I'm rendering my entire scene to a 2d texture but the depth info isn't being used.
When I render normally to the backbuffer the depth information is used.
Here's what I'm doing:
// Cache the current depth buffer
DepthStencilBuffer old = GraphicsDevice.DepthStencilBuffer;
// render to the "backbuffer"
GraphicsDevice.SetRenderTarget(0, backBuffer);
// kill everything
graphics.GraphicsDevice.Clear(
Color.CornflowerBlue);
// Set our custom depth buffer
GraphicsDevice.DepthStencilBuffer = backDepthStencilBuffer;
// draw everything
base.Draw(gameTime);
// Set render target back to the real back buffer
GraphicsDevice.SetRenderTarget(0,
null);
// Reset the depth buffer
GraphicsDevice.DepthStencilBuffer = old;
// and render the "back buffer" to the back buffer
Rectangle rect = new Rectangle(0,0,
GraphicsDevice.PresentationParameters.BackBufferWidth,
GraphicsDevice.PresentationParameters.BackBufferHeight);
backBufferSpriteBatch.Begin(
SpriteBlendMode.None);
backBufferSpriteBatch.Draw(backBuffer.GetTexture(), rect,
Color.White);
backBufferSpriteBatch.End();
I first tried it without creating a whole new depth buffer and it didn't work and then created a depth buffer and it still doesn't work :(
Halp! ;o
EDIT:
Here's the loading code:
// load the backbuffer
backBuffer =
new RenderTarget2D(
GraphicsDevice,
// the rendering device
GraphicsDevice.PresentationParameters.BackBufferWidth,
// screen width
GraphicsDevice.PresentationParameters.BackBufferHeight,
// screen height
1,
// 1 mipmap level
GraphicsDevice.DisplayMode.Format,
// bgr32
0,
// no multisample (AA)
0
// no multisample (AA)
);
// load the depth for the back buffer
backDepthStencilBuffer =
new DepthStencilBuffer(
GraphicsDevice,
// rendering device
GraphicsDevice.PresentationParameters.BackBufferWidth,
// screen width
GraphicsDevice.PresentationParameters.BackBufferHeight,
// screen height
GraphicsDevice.DepthStencilBuffer.Format,
// format of actual bb
0,
// no multisample (AA)
0
// no multisample (AA)
);
// load the spritepatch used to display the backbuffer
backBufferSpriteBatch =
new SpriteBatch(GraphicsDevice);