Sign in to follow this  
deffer

z-buffer lost(?) AFTER render to texture

Recommended Posts

deffer    754
Hi. I wanted to render a terrain part to a texture, 'cause splatting every frame is really killing me. Texture came just fine. I am doing this: // prepare texture to render to. CDXTexture pTex; hr = g_pDevice->CreateTexture( nTexSize, nTexSize, 0, 3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTex, NULL); CDXSurface pSurf; hr = pTex->GetSurfaceLevel( 0, &pSurf ); // save the original surface. CDXSurface pOrigSurf; hr = g_pDevice->GetRenderTarget(0, &pOrigSurf); // set the new surface. hr = g_pDevice->SetRenderTarget(0, pSurf); Here I should render something to the texture, and if I do, it works just fine. Let's say I'm not rendering anything, nor setting any other options. I'm restoring the previous seting that way: // restore settings. hr = g_pDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); hr = g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); hr = g_pDevice->SetRenderTarget(0, pOrigSurf); pOrigSurf->Release(); hr = g_pDevice->SetRenderState( D3DRS_ZENABLE, TRUE ); hr = g_pDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); Then releasing the texture and so. Absolutely no errors are generated during thios process. Then I'm turning to render my world as usuall. The problem is, it seems that my z-buffer isn't working any more. It's pretty obvious to realize. It's loking exactly like all the z-tests are passed. That is why I try to turn it on before and after changing the surface back to original, but it's not helping. It's turn on, but not working. ANY help appreciated. /def

Share this post


Link to post
Share on other sites
clip    126
just a guess, when you setrendertartget to your texture,did you CheckDepthStencilMatch ? if the format doesn't match, maybe the depthbuffer already got lost at that time, are you sure the depthtest still working when you rendering the terrian?
after you set the rendertarget back to the orginal buffer, are you expecting the depthbuffer contain the value of the terrain?

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