Sign in to follow this  
programmer_tom

GetRenderTargetData and SetTexture() problem

Recommended Posts

programmer_tom    214
hey all frustrating problem i can't figure out... just want to grab the back buffer to a memory texture, and use that memory texture to texture a quad that is rendered to a render target texture. i know for a fact that the memory texture's surface has the back buffer color info right, but when i use the memory texture to render the quad, it's blank. is there some step i'm forgetting between grabbing the surface info from the back buffer and texturing a quad? here's the code

   /*-------------------------------------------------------------------------*/
   /* Copy the back buffer to the surface of the memory texture.              */
   /*-------------------------------------------------------------------------*/

   LPDIRECT3DSURFACE9 pBackBuffer;
   m_pd3dDevice->GetBackBuffer ( 0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer );
   
   LPDIRECT3DSURFACE9 pSurfaceMemory;
   m_pTextureMemory->GetSurfaceLevel ( 0, &pSurfaceMemory );
   
   m_pd3dDevice->GetRenderTargetData ( pBackBuffer, pSurfaceMemory );
   

   /*-------------------------------------------------------------------------*/
   /* Render from our memory texture to our render target texture.            */
   /*-------------------------------------------------------------------------*/
  
   LPDIRECT3DSURFACE9 pSurfaceRenderTarget;
   m_pTextureRenderTarget->GetSurfaceLevel ( 0, pSurfaceRenderTarget );     
   m_pd3dDevice->SetRenderTarget ( 0, pSurfaceRenderTarget );
   
   (device states etc)
   m_pd3dDevice->SetTexture ( 0, m_pTextureMemory );
   (draw)


Share this post


Link to post
Share on other sites
MJP    19754
You can't just use textures created in D3DPOOL_SYSTEMMEM like normal textures, they're only accessible to the device through specific functions. If you want to copy data from SYSTEMMEM to DEFAULT, you'll have to use IDirect3DDevice9::UpdateSurface or IDirect3DDevice9::UpdateTexture.

However, I can't really see why you're doing all of this copying to system memory in the first place. It's bound to be horrifically slow, given that you're reading back the entire backbuffer over the AGP bus. You should probably using something like IDirect3DDevice9::StretchRect to directly copy memory from the backbuffer to your render target (check the docs and device caps to make sure this is a valid op). Also if you're going to be rendering a bunch of data that you need to read back again, the backbuffer probably isn't a good place to render it to. A render target texture will give you much more flexibility, since you can just apply it as a texture and do whatever you want with it.

Share this post


Link to post
Share on other sites
programmer_tom    214
You can't just use textures created in D3DPOOL_SYSTEMMEM like normal textures

ya i had forgotten that :(

i didn't know that blt from StretchRect() was legal using the back buffer...made things much simpler.

thanks a lot.
-programmer_tom

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this