Export (0) Print
Expand All

What Is a Render Target?

A render target is a buffer where the video card draws pixels for a scene that is being rendered by an Effect Class.

The default render target is called the back buffer - this is the part of video memory that contains the next frame to be drawn. You can create other render targets with the RenderTarget2D class - in effect, reserving new regions of video memory for drawing. Most games render a lot of content to other render targets besides the back buffer ("offscreen"), then assemble the different graphical elements in stages, combining them to create the final product in the back buffer.

A render target has a width and height. The width and height of the back buffer are the final resolution of your game (although on Xbox 360 that final result is scaled to match the user's screen). An offscreen render target does not need to have the same width and height as the back buffer. Small parts of the final image can be rendered in small render targets, then copied to another render target later. A render target also has a surface format, which describes how many bits are allocated to each pixel and how they are divided between red, green, blue, and alpha. For example, SurfaceFormat.Bgr32 allocates 32 bits per pixel: 8 bits for each color and 8 bits for the alpha channel. As an option, render targets can perform antialiasing on all the images that are rendered into them.

To use a render target, create a RenderTarget2D object with the width, height, and other options you prefer. Then call GraphicsDevice.SetRenderTarget to make your render target the current render target. From this point on, any Draw calls you make will draw into your render target. When you are finished with the render target, call GraphicsDevice.SetRenderTarget to a new render target (or null for the back buffer). Then at any time you can call RenderTarget2D.GetTexture to get the contents of the render target for further processing.

Render targets work in conjunction with the depth-stencil buffer. If you set a new render target, it will use the existing depth-stencil buffer. If the new render target has different multisampling settings than the depth-stencil buffer, or a larger width and height, you will need a new depth-stencil buffer to match. You must also use a depth format in your depth-stencil buffer that is compatible with the surface format of your render target.

You can sometimes render to more than one render target at the same time. The number of simultaneous render targets your graphics device supports is given by the MaxSimultaneousRenderTargets property. There are numerous caveats for using multiple render targets. For more information, see Render Targets.

Community Additions

ADD
Show:
© 2014 Microsoft