Class RenderTarget2D
Represents a 2D texture resource that will be written to at the end of a render pass.
public class RenderTarget2D : Texture2D, IDisposable
- Inheritance
-
RenderTarget2D
- Implements
- Inherited Members
Remarks
After a render pass the render target contains the color information of a rendered image.
Render targets represent a linear area of display memory and usually resides in the display memory of the display card. Because of this, objects must be recreated when the device is reset.
Constructors
RenderTarget2D(GraphicsDevice, int, int)
Creates a new RenderTarget2D instance with the specified parameters.
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height)
Parameters
graphicsDevice
GraphicsDeviceThe graphics device to associate with this render target resource.
width
intWidth, in pixels, of the render target.
height
intHeight, in pixels, of the render target.
Exceptions
- ArgumentNullException
The
graphicsDevice
parameter is null.- ArgumentOutOfRangeException
The
width
and/orheight
parameters less than or equal to zero.
RenderTarget2D(GraphicsDevice, int, int, bool, SurfaceFormat, DepthFormat)
Creates a new RenderTarget2D instance with the specified parameters.
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat)
Parameters
graphicsDevice
GraphicsDeviceThe graphics device to associate with this render target resource.
width
intWidth, in pixels, of the render target.
height
intHeight, in pixels, of the render target.
mipMap
booltrue if mipmapping is enabled; otherwise, false.
preferredFormat
SurfaceFormatThe preferred surface format of the render target.
preferredDepthFormat
DepthFormatThe preferred depth format of the render target.
Exceptions
- ArgumentNullException
The
graphicsDevice
parameter is null.- ArgumentOutOfRangeException
The
width
and/orheight
parameters less than or equal to zero.
RenderTarget2D(GraphicsDevice, int, int, bool, SurfaceFormat, DepthFormat, int, RenderTargetUsage)
Creates a new RenderTarget2D instance with the specified parameters.
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
Parameters
graphicsDevice
GraphicsDeviceThe graphics device to associate with this render target resource.
width
intWidth, in pixels, of the render target.
height
intHeight, in pixels, of the render target.
mipMap
booltrue if mipmapping is enabled; otherwise, false.
preferredFormat
SurfaceFormatThe preferred surface format of the render target.
preferredDepthFormat
DepthFormatThe preferred depth format of the render target.
preferredMultiSampleCount
intThe preferred number of samples per pixel when multisampling.
usage
RenderTargetUsageThe behavior to use when binding the render target to the graphics device.
Exceptions
- ArgumentNullException
The
graphicsDevice
parameter is null.- ArgumentOutOfRangeException
The
width
and/orheight
parameters less than or equal to zero.
RenderTarget2D(GraphicsDevice, int, int, bool, SurfaceFormat, DepthFormat, int, RenderTargetUsage, SurfaceType)
Allows child class to specify the surface type, eg: a swap chain.
protected RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat format, DepthFormat depthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, Texture2D.SurfaceType surfaceType)
Parameters
graphicsDevice
GraphicsDevicewidth
intheight
intmipMap
boolformat
SurfaceFormatdepthFormat
DepthFormatpreferredMultiSampleCount
intusage
RenderTargetUsagesurfaceType
Texture2D.SurfaceType
RenderTarget2D(GraphicsDevice, int, int, bool, SurfaceFormat, DepthFormat, int, RenderTargetUsage, bool)
Creates a new RenderTarget2D instance with the specified parameters.
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared)
Parameters
graphicsDevice
GraphicsDeviceThe graphics device to associate with this render target resource.
width
intWidth, in pixels, of the render target.
height
intHeight, in pixels, of the render target.
mipMap
booltrue if mipmapping is enabled; otherwise, false.
preferredFormat
SurfaceFormatThe preferred surface format of the render target.
preferredDepthFormat
DepthFormatThe preferred depth format of the render target.
preferredMultiSampleCount
intThe preferred number of samples per pixel when multisampling.
usage
RenderTargetUsageThe behavior to use when binding the render target to the graphics device.
shared
boolWhether this render target resource should be a shared resource accessible on another device. This property is only valid for DirectX targets.
Exceptions
- ArgumentNullException
The
graphicsDevice
parameter is null.- ArgumentOutOfRangeException
The
width
and/orheight
parameters less than or equal to zero.
RenderTarget2D(GraphicsDevice, int, int, bool, SurfaceFormat, DepthFormat, int, RenderTargetUsage, bool, int)
Creates a new RenderTarget2D instance with the specified parameters.
public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage, bool shared, int arraySize)
Parameters
graphicsDevice
GraphicsDeviceThe graphics device to associate with this render target resource.
width
intWidth, in pixels, of the render target.
height
intHeight, in pixels, of the render target.
mipMap
booltrue if mipmapping is enabled; otherwise, false.
preferredFormat
SurfaceFormatThe preferred surface format of the render target.
preferredDepthFormat
DepthFormatThe preferred depth format of the render target.
preferredMultiSampleCount
intThe preferred number of samples per pixel when multisampling.
usage
RenderTargetUsageThe behavior to use when binding the render target to the graphics device.
shared
boolWhether this render target resource should be a shared resource accessible on another device. This property is only valid for DirectX targets.
arraySize
intThe size of the texture array.
Exceptions
- ArgumentNullException
The
graphicsDevice
parameter is null.- ArgumentOutOfRangeException
The
width
and/orheight
parameters less than or equal to zero.- ArgumentException
arraySize
is greater than 0 and the graphics device does not support texture arrays.
Properties
DepthStencilFormat
Gets the depth format used by this RenderTarget2D
public DepthFormat DepthStencilFormat { get; }
Property Value
IsContentLost
Gets a value that indicates whether the contents of this RenderTarget2D has been lost due to a lost device event.
[Obsolete("This is provided for XNA compatibility only and will always return false")]
public bool IsContentLost { get; }
Property Value
Remarks
This property will always return false. It is included for XNA compatibility.
MultiSampleCount
Gets the number of samples taken per pixel
public int MultiSampleCount { get; }
Property Value
RenderTargetUsage
Gets or Sets the usage type used by this RenderTarget2D
public RenderTargetUsage RenderTargetUsage { get; }
Property Value
Methods
Dispose(bool)
protected override void Dispose(bool disposing)
Parameters
disposing
bool
GraphicsDeviceResetting()
Called before the device is reset. Allows graphics resources to invalidate their state so they can be recreated after the device reset. Warning: This may be called after a call to Dispose() up until the resource is garbage collected.
protected override void GraphicsDeviceResetting()
QuerySelectedFormat(GraphicsDevice, SurfaceFormat)
protected static SurfaceFormat QuerySelectedFormat(GraphicsDevice graphicsDevice, SurfaceFormat preferredFormat)
Parameters
graphicsDevice
GraphicsDevicepreferredFormat
SurfaceFormat
Returns
Events
ContentLost
Occurs when a graphics device lost event is triggered.
[Obsolete("This is provided for XNA compatibility is never called by MonoGame")]
public event EventHandler<EventArgs> ContentLost
Event Type
Remarks
This event is never called. It is included for XNA compatibility.