I am employing a nested rendertarget strategy as a way to manage clipping and group transformation in a 2D environment. I’ve found that the nesting works only 2 levels deep. I’ve unrolled my drawing loop below. I see the contents of RenderBuffer_1 and RenderBuffer_2 just fine, but RenderBuffer3 doesn’t show up at all. Any ideas what is wrong?
_spriteBatch.Begin();
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(RenderBuffer_1);
_spriteBatch.Begin();
// Draw Something on RenderBuffer_1
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(RenderBuffer_2);
_spriteBatch.Begin();
// Draw Something on RenderBuffer_2
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(RenderBuffer_3);
_spriteBatch.Begin();
// Draw Something on RenderBuffer_3
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(RenderBuffer_2);
_spriteBatch.Begin();
// _spriteBatch.Draw RenderBuffer_3 -> RenderBuffer_2
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(RenderBuffer_1);
_spriteBatch.Begin();
// _spriteBatch.Draw RenderBuffer_2 -> RenderBuffer_1
_spriteBatch.End();
GraphicsDevice.SetRenderTarget(null);
_spriteBatch.Begin();
// _spriteBatch.Draw RenderBuffer_1 -> mainbuffer
_spriteBatch.End();
And here is how I construct my render targets:
return new RenderTarget2D(
graphicsDevice,
width,
height,
false,
SurfaceFormat.Color,
DepthFormat.None,
1,
RenderTargetUsage.PreserveContents);