Jump to content
  • Advertisement
Sign in to follow this  
Ripiz

[C++ DX9] DepthStencil error

This topic is 2716 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

I try to render into 1024x1024 texture, but it throws "Direct3D9: (ERROR) :DepthStencil Buffer must be at least as big as the RenderTarget." error when backbuffer resolution is smaller than my render target. I tried disabling Z Buffer but it still throws error. Is there any way to fix it?

[font="consolas"] device->SetRenderState(D3DRS_ZENABLE, 0);[/font] device->SetRenderState(D3DRS_ZWRITEENABLE, 0);
device->SetRenderTarget(0, textureMapSurface);
device->BeginScene();
[color="blue"]uint cPasses;
shader->Begin(&cPasses, 0);
shader->BeginPass(0);
device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, quad, [color="blue"]sizeof(VertexScreen));
shader->EndPass();
shader->End();
device->EndScene();
device->SetRenderState(D3DRS_ZENABLE, 1);
[font="consolas"] device->SetRenderState(D3DRS_ZWRITEENABLE, 1);[/font]

Share this post


Link to post
Share on other sites
Advertisement
The Z buffer is attached/detached independently of the RenderTarget with SetDepthStencilSurface. Your error is because your default depth/stencil surface is still set when you render into your render target. If you don't need depth buffer call SetDepthStencilSurface(0) after you bind your render target.

Share this post


Link to post
Share on other sites
You just wrote what is the answer!

When you create direct3d device by filling present params structure you need to specify if you want it to create depth stencil surface (automaticly):

PresentParams.EnableAutoDepthStencil = TRUE;

if you set this to TRUE it will create it with size specified by:

PresentParams.BackBufferWidth = W;
PresentParams.BackBufferHeight = H;

and then later you use render target witch is probably (or at least its width or height is) larger then your ds surface size!
To solve this:
1. create yet another ds surface with proper size (best option)
2. decrease size of your render target
3. increase size of your window

Share this post


Link to post
Share on other sites
I found karwosts way easier, I used G[color=#1C2837][size=2]etDepthStencilSurface to get pointer to current buffer, then [color=#1C2837][size=2]SetDepthStencilSurface(0), render what I need, and set it back. It works fine now.
[color="#1C2837"]

[color="#1C2837"]Thank you both.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!