Device.SetRenderTarget(Int32,Surface) Method (Microsoft.DirectX.Direct3D)

Sets a new color buffer for a device.


Visual BasicPublic Sub SetRenderTarget( _
    ByVal renderTargetIndex As Integer, _
    ByVal renderTarget As Surface _
C#public void SetRenderTarget(
    int renderTargetIndex,
    Surface renderTarget
void SetRenderTarget(
    int renderTargetIndex,
JScriptpublic function SetRenderTarget(
    renderTargetIndex : int,
    renderTarget : Surface


renderTargetIndex System.Int32
Index of the render target. See Remarks.
renderTarget Microsoft.DirectX.Direct3D.Surface
New color buffer. If set to null, the color buffer for the corresponding param_Int32_renderTargetIndex is disabled. Devices must always be associated with a color buffer.

The new render-target surface must have at least RenderTarget specified.


The device can support multiple render targets. The number of render targets supported by a device is contained in Caps.NumberSimultaneousRts.

Some hardware tests the compatibility of the depth stencil buffer with the color buffer. If this is done, it is done only in a debug build.

The following restrictions apply when using this method.

  • The multisample type must be the same for the render target and the depth stencil surface.
  • The formats must be compatible for the render target and the depth stencil surface. For more information, see Manager.CheckDepthStencilMatch.
  • The size of the depth stencil surface must be greater than or equal to the size of the render target.

These restrictions are validated only when using the debug runtime when any of the DeviceDraw methods are called.

Cube textures differ from other surfaces in that they are collections of surfaces. To call Device.SetRenderTarget with a cube texture, select an individual face using CubeTexture.GetCubeMapSurface and pass the resulting surface to Device.SetRenderTarget.

InvalidCallException The method call is invalid. Either param_Surface_renderTarget = null and param_Int32_renderTargetIndex = 0, or param_Surface_renderTarget != null and the render target is invalid.