• 13
• 15
• 19
• 27
• 9

# "DepthStencil Buffer must be at least as big as the RenderTarget"

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

## Recommended Posts

Hello, When trying to clear a render target, I am getting this error: DepthStencil Buffer must be at least as big as the RenderTarget. Here's how I am doing it:
hr = g_device->CreateTexture(512, 512, 0, D3DUSAGE_RENDERTARGET|D3DUSAGE_AUTOGENMIPMAP, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &Texture, 0);
IDirect3DSurface9 *Sfc, *Sfc2;
Texture->GetSurfaceLevel(0, &Sfc);				// sfc is top level surface of 'Texture' , the temp target
g_device->GetRenderTarget(0, &Sfc2);			// store the main backbuffer render target
g_device->SetRenderTarget(0, Sfc);				// switch to temporary target

g_device->Clear(0, 0, D3DCLEAR_TARGET, 0xFFFF00FF, 1.0f, 0);

g_device->SetRenderTarget(0, Sfc2);				// switch back
Sfc->Release();

Sirob, you noticed this one? Thanks in advance! Simon

##### Share on other sites
When rendering to a texture you need to also create a depth buffer of an appropriate size.

pDev->CreateDepthStencilSurface(...)
pDev->SetDepthStencilSurface(...)

Although the error implies the sizes don't have to match, as long as the depth buffer is atleast as large as the render target, this isn't the case. Atleast it doesn't work on the XBox. It may work on PC. In any event, to avoid problems with various drivers, or if the problem exists in general on the PC as well, it's easiest to just make the sizes be equal.

##### Share on other sites
Hi again Simon!

Wow, funny. Your error seems like by all means it should be happening in my application as well (the one I E-mailed you). This is so weird, since it doesn't happen in my app at all.

My best guess would be that if you don't need a Z-buffer, disable it before the clear call, which I'm hoping would supress this error. Hopefully :).

At any rate - the clear call is only for the Target frame, and not the Z/Stencil buffer, so you shouldn't have a problem just disabling the Z-buffer for the whole process.

If things get critical and disabling Z-buffering doesn't work, I suppose a SetDepthStencil() with a NULL pointer would solve the issue.

Hope this helps :).