XNA 3.1 to 4.0 Conversion – Rendertarget
XNA 3.1 code causes following error when compiled with XNA 4.0:
Error 5 ’Microsoft.Xna.Framework.Graphics.RenderTarget2D’ does not contain a constructor that takes 5 arguments.
XNA 3.1 code: renderTarget =new RenderTarget2D(device, width, height, 1, device.DisplayMode.Format);
XNA 3.1 had 4 overload versions:
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format)
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, RenderTargetUsage useage)
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, int multiSampleQuality)
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, int numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, int multiSampleQuality, RenderTargetUsage useage)
In XNA 4.0 this has reduced to:
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height)
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, bool mipMap, SurfaceFormat prefferedFormat, DepthFormat prefferedDepthFormat)
RenderTarget2D.RenderTarget2D(Graphics Device graphicsDevice, int width, int height, bool mipMap, SurfaceFormat prefferedFormat, DepthFormat prefferedDepthFormat, int prefferedMultiSampleCount, RenderTargetUsage useage)
The changes to RenderTarget were required as there were too many opportunites to generate errors (eg if you changed the rendertarget but not the depthbufffer) . See Shawn Hargreaves Blog and Shawn Hargreaves Blog for full explanation.




