/*-------------------------------------------------------------------------*/
/* 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)
GetRenderTargetData and SetTexture() problem
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
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement