XNA 4.0 Breaking Changes – RenderTargets
One of the things that has changed with XNA Version 4.0 is RenderTargets. The constructor parameters have changed, as has their interaction with the DepthStencilBuffer class.
While previously we had to specify a DepthStencilBuffer instance of the same width, height, and multisampling settings as a render target we were trying to set to the graphics device, the render target now takes care of this for us.
In addition, the functions to set render targets to the graphics device have changed. We no longer specify indices for our render targets. Instead, we either set one render target using the “GraphicsDevice.SetRenderTarget(RenderTarget2D renderTarget)” function, or set multiple render targets using the “GraphicsDevice.SetRenderTargets(params RenderTargetBinding[] renderTargets)” function.
For example, the following draw code from XNA 3.1:
graphicsDevice.SetRenderTarget(0, renderTarg); DepthStencilBuffer oldDepth = graphicsDevice.DepthStencilBuffer; graphicsDevice.DepthStencilBuffer = depthBuffer; // Draw graphicsDevice.SetRenderTarget(0, null); graphicsDevice..DepthStencilBuffer = oldDepth;
Would become in XNA 4.0:
graphicsDevice.SetRenderTarget(shadowTarg);
foreach (CModel model in Models)
model.Draw(shadowCamera);
graphicsDevice.SetRenderTarget(null);
Other changes have been made to the RenderTarget as well–the “GetTexture()” function is gone now, for example (as the entire thing now inherits from Texture2D). I’ll update as I figure more out.

This writing is so nice. I try to do this.