Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

jollyjeffers

Getting a D3D9 texture from a D3D9 surface

This topic is 5417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, Something here thats driving me up the wall, because I'm SURE that I've done the same thing under D3D8 - just now in D3D9 things have changed just a little bit and my technique no longer seems to work!! I'm trying to copy part of a surface (LPDIRECT3DSURFACE9) to an entire texture (LPDIRECT3DTEXTURE9). I've attempted using both StretchRect and UpdateSurface - neither of which succeed. I'm pretty sure that its just not matching the requirements (its pretty strict on what surfaces can be copied).. here's roughly what I've got:
pDev->CreateTexture( part->iWidth, part->iHeight, 1, 0, fmtDisp, D3DPOOL_MANAGED, &(part->pTex), NULL );

LPDIRECT3DSURFACE9 pTmpSurf;
part->pTex->GetSurfaceLevel( 0, &pTmpSurf );

RECT r;
//calculate 'r' here, to be a portion of pSurf the SAME size

//as pTmpSurf.

pDev->UpdateSurface( pSurf, &r, pTmpSurf, NULL );

SAFE_RELEASE( pTmpSurf );
the above code has been stripped off error-checking, but each call is error checked / return value analysed... the only error reported is "UpdateSurface()".. any ideas how I can do this? Jack **EDIT: Both texture and surface have the same format (no alpha channel, either 16bit or 32bit). The source surface is in _DEFAULT and the texture is in _MANAGED, but I've tried changing those to no effect. [edited by - Jollyjeffers on January 13, 2004 11:48:32 PM]

Share this post


Link to post
Share on other sites
Advertisement
The source surface must have been created with D3DPOOL_SYSTEMMEM.
The destination surface must have been created with D3DPOOL_DEFAULT.

(from the Summer Update docs)

I like pie.

Share this post


Link to post
Share on other sites
I'm pretty sure that UpdateSurface() won't work unless the source surface is in D3DPOOL_SYSTEMMEM and the destination surface is in D3DPOOL_DEFAULT. Plus the obvious restrictions (same size, no multisampling etc).

[edited by - TheBigJ on January 13, 2004 12:08:29 AM]

Share this post


Link to post
Share on other sites
StretchRect has its own set of limitations. For one, both surfaces have to be in D3DPOOL_DEFAULT which is why it probably failed in your case. The docs for StretchRect contain a table and details on the requirements for source and destination surfaces.


Share this post


Link to post
Share on other sites
quote:
The source surface must have been created with D3DPOOL_SYSTEMMEM.
The destination surface must have been created with D3DPOOL_DEFAULT.


that did the trick

thinking of the table in the docs... I was sure that I''d checked my stuff against that and it would work. Guess I changed one at a time, and not both at the same time serves me right for programming at 4am

thanks all,
Jack

Share this post


Link to post
Share on other sites
As an alternative, what I''ve seen work really well is using the Texture interface, get the surface level of a texture, and then you do a surface->surface copy. It''s much more flexible about Pool types.

Share this post


Link to post
Share on other sites
Woah... Wait a minute! That would highly simplify what I''m working with right now. GetSurfaceLevel allows you to modify a SURFACE based on a texture? I''ve been sitting here messing with rectangle locking and the like to transfer surfaces to textures and so on. It''s been a nightmare.

Share this post


Link to post
Share on other sites
quote:
Original post by ShadowP13
Woah... Wait a minute! That would highly simplify what I'm working with right now. GetSurfaceLevel allows you to modify a SURFACE based on a texture? I've been sitting here messing with rectangle locking and the like to transfer surfaces to textures and so on. It's been a nightmare.


Yeah, that's what I was talking about, sorry I wasn't being more explicit.

Aside from the simplicity of it, I'm guessing that it's also more efficiently implemented in D3DX than if you were to lock it and do it yourself.

[edited by - mbrown211 on January 14, 2004 3:25:04 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by jollyjeffers
quote:
do a surface->surface copy


hmm, what do you mean by this exactly? is there another surface-copy beyond StretchRect / UpdateSurface ?

Jack


Yeah, in D3DX you can do a LoadSurfaceFromSurface
that takes in pallettes and rects (both optional) and does surface to surface copying...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!