Class GraphicsDevice
public class GraphicsDevice : IDisposable
- Inheritance
-
GraphicsDevice
- Implements
- Inherited Members
Constructors
GraphicsDevice(GraphicsAdapter, GraphicsProfile, PresentationParameters)
Initializes a new instance of the GraphicsDevice class.
public GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, PresentationParameters presentationParameters)
Parameters
adapterGraphicsAdapterThe graphics adapter.
graphicsProfileGraphicsProfileThe graphics profile.
presentationParametersPresentationParametersThe presentation options.
Exceptions
- ArgumentNullException
presentationParametersis null.
GraphicsDevice(GraphicsAdapter, GraphicsProfile, bool, PresentationParameters)
Initializes a new instance of the GraphicsDevice class.
public GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile graphicsProfile, bool preferHalfPixelOffset, PresentationParameters presentationParameters)
Parameters
adapterGraphicsAdapterThe graphics adapter.
graphicsProfileGraphicsProfileThe graphics profile.
preferHalfPixelOffsetboolIndicates if DX9 style pixel addressing or current standard pixel addressing should be used. This value is passed to UseHalfPixelOffset
presentationParametersPresentationParametersThe presentation options.
Exceptions
- ArgumentNullException
presentationParametersis null.
Properties
Adapter
public GraphicsAdapter Adapter { get; }
Property Value
BlendFactor
The color used as blend factor when alpha blending.
public Color BlendFactor { get; set; }
Property Value
Remarks
When only changing BlendFactor, use this rather than BlendFactor to only update BlendFactor so the whole BlendState does not have to be updated.
BlendState
public BlendState BlendState { get; set; }
Property Value
DepthStencilState
public DepthStencilState DepthStencilState { get; set; }
Property Value
DiscardColor
Get or set the color a RenderTarget2D is cleared to when it is set.
public static Color DiscardColor { get; set; }
Property Value
DisplayMode
public DisplayMode DisplayMode { get; }
Property Value
GraphicsDebug
Access debugging APIs for the graphics subsystem.
public GraphicsDebug GraphicsDebug { get; set; }
Property Value
GraphicsDeviceStatus
public GraphicsDeviceStatus GraphicsDeviceStatus { get; }
Property Value
GraphicsProfile
public GraphicsProfile GraphicsProfile { get; }
Property Value
Indices
public IndexBuffer Indices { get; set; }
Property Value
IsContentLost
public bool IsContentLost { get; }
Property Value
IsDisposed
public bool IsDisposed { get; }
Property Value
Metrics
The rendering information for debugging and profiling. The metrics are reset every frame after draw within Present().
public GraphicsMetrics Metrics { get; set; }
Property Value
PresentationParameters
public PresentationParameters PresentationParameters { get; }
Property Value
RasterizerState
public RasterizerState RasterizerState { get; set; }
Property Value
RenderTargetCount
public int RenderTargetCount { get; }
Property Value
ResourcesLost
public bool ResourcesLost { get; set; }
Property Value
SamplerStates
public SamplerStateCollection SamplerStates { get; }
Property Value
ScissorRectangle
public Rectangle ScissorRectangle { get; set; }
Property Value
Textures
public TextureCollection Textures { get; }
Property Value
UseHalfPixelOffset
Indicates if DX9 style pixel addressing or current standard
pixel addressing should be used. This flag is set to
false by default. If UseHalfPixelOffset is
true you have to add half-pixel offset to a Projection matrix.
See also PreferHalfPixelOffset.
public bool UseHalfPixelOffset { get; }
Property Value
Remarks
XNA uses DirectX9 for its graphics. DirectX9 interprets UV
coordinates differently from other graphics API's. This is
typically referred to as the half-pixel offset. MonoGame
replicates XNA behavior if this flag is set to true.
VertexSamplerStates
public SamplerStateCollection VertexSamplerStates { get; }
Property Value
VertexTextures
public TextureCollection VertexTextures { get; }
Property Value
Viewport
public Viewport Viewport { get; set; }
Property Value
Methods
Clear(Color)
public void Clear(Color color)
Parameters
colorColor
Clear(ClearOptions, Color, float, int)
public void Clear(ClearOptions options, Color color, float depth, int stencil)
Parameters
optionsClearOptionscolorColordepthfloatstencilint
Clear(ClearOptions, Vector4, float, int)
public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
Parameters
optionsClearOptionscolorVector4depthfloatstencilint
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
protected virtual void Dispose(bool disposing)
Parameters
disposingbool
DrawIndexedPrimitives(PrimitiveType, int, int, int)
Draw geometry by indexing into the vertex buffer.
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives in the index buffer.
baseVertexintUsed to offset the vertex range indexed from the vertex buffer.
startIndexintThe index within the index buffer to start drawing from.
primitiveCountintThe number of primitives to render from the index buffer.
DrawIndexedPrimitives(PrimitiveType, int, int, int, int, int)
Draw geometry by indexing into the vertex buffer.
[Obsolete("Use DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount) instead. In future versions this method can be removed.")]
public void DrawIndexedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives in the index buffer.
baseVertexintUsed to offset the vertex range indexed from the vertex buffer.
minVertexIndexintThis is unused and remains here only for XNA API compatibility.
numVerticesintThis is unused and remains here only for XNA API compatibility.
startIndexintThe index within the index buffer to start drawing from.
primitiveCountintThe number of primitives to render from the index buffer.
Remarks
Note that minVertexIndex and numVertices are unused in MonoGame and will be ignored.
DrawInstancedPrimitives(PrimitiveType, int, int, int, int)
Draw instanced geometry from the bound vertex buffers and index buffer.
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount, int instanceCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives in the index buffer.
baseVertexintUsed to offset the vertex range indexed from the vertex buffer.
startIndexintThe index within the index buffer to start drawing from.
primitiveCountintThe number of primitives in a single instance.
instanceCountintThe number of instances to render.
Remarks
Draw geometry with data from multiple bound vertex streams at different frequencies.
DrawInstancedPrimitives(PrimitiveType, int, int, int, int, int)
Draw instanced geometry from the bound vertex buffers and index buffer.
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount, int baseInstance, int instanceCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives in the index buffer.
baseVertexintUsed to offset the vertex range indexed from the vertex buffer.
startIndexintThe index within the index buffer to start drawing from.
primitiveCountintThe number of primitives in a single instance.
baseInstanceintUsed to offset the instance range indexed from the instance buffer.
instanceCountintThe number of instances to render.
Remarks
Draw geometry with data from multiple bound vertex streams at different frequencies.
DrawInstancedPrimitives(PrimitiveType, int, int, int, int, int, int)
Draw instanced geometry from the bound vertex buffers and index buffer.
[Obsolete("Use DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount, int instanceCount) instead. In future versions this method can be removed.")]
public void DrawInstancedPrimitives(PrimitiveType primitiveType, int baseVertex, int minVertexIndex, int numVertices, int startIndex, int primitiveCount, int instanceCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives in the index buffer.
baseVertexintUsed to offset the vertex range indexed from the vertex buffer.
minVertexIndexintThis is unused and remains here only for XNA API compatibility.
numVerticesintThis is unused and remains here only for XNA API compatibility.
startIndexintThe index within the index buffer to start drawing from.
primitiveCountintThe number of primitives in a single instance.
instanceCountintThe number of instances to render.
Remarks
Note that minVertexIndex and numVertices are unused in MonoGame and will be ignored.
DrawPrimitives(PrimitiveType, int, int)
Draw primitives of the specified type from the currently bound vertexbuffers without indexing.
public void DrawPrimitives(PrimitiveType primitiveType, int vertexStart, int primitiveCount)
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw.
vertexStartintIndex of the vertex to start at.
primitiveCountintThe number of primitives to draw.
DrawUserIndexedPrimitives<T>(PrimitiveType, T[], int, int, short[], int, int)
Draw primitives of the specified type by indexing into the given array of vertices with 16-bit indices.
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex to draw.
numVerticesintThe number of vertices to draw.
indexDatashort[]The index data.
indexOffsetintThe index in the array of indices of the first index to use
primitiveCountintThe number of primitives to draw.
Type Parameters
TThe type of the vertices.
Remarks
The VertexDeclaration will be found by getting VertexDeclaration
from an instance of T and cached for subsequent calls.
DrawUserIndexedPrimitives<T>(PrimitiveType, T[], int, int, short[], int, int, VertexDeclaration)
Draw primitives of the specified type by indexing into the given array of vertices with 16-bit indices.
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, short[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex to draw.
numVerticesintThe number of vertices to draw.
indexDatashort[]The index data.
indexOffsetintThe index in the array of indices of the first index to use
primitiveCountintThe number of primitives to draw.
vertexDeclarationVertexDeclarationThe layout of the vertices.
Type Parameters
TThe type of the vertices.
Remarks
All indices in the vertex buffer are interpreted relative to the specified vertexOffset.
For example a value of zero in the array of indices points to the vertex at index vertexOffset
in the array of vertices.
DrawUserIndexedPrimitives<T>(PrimitiveType, T[], int, int, int[], int, int)
Draw primitives of the specified type by indexing into the given array of vertices with 32-bit indices.
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount) where T : struct, IVertexType
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex to draw.
numVerticesintThe number of vertices to draw.
indexDataint[]The index data.
indexOffsetintThe index in the array of indices of the first index to use
primitiveCountintThe number of primitives to draw.
Type Parameters
TThe type of the vertices.
Remarks
The VertexDeclaration will be found by getting VertexDeclaration
from an instance of T and cached for subsequent calls.
DrawUserIndexedPrimitives<T>(PrimitiveType, T[], int, int, int[], int, int, VertexDeclaration)
Draw primitives of the specified type by indexing into the given array of vertices with 32-bit indices.
public void DrawUserIndexedPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int numVertices, int[] indexData, int indexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex to draw.
numVerticesintThe number of vertices to draw.
indexDataint[]The index data.
indexOffsetintThe index in the array of indices of the first index to use
primitiveCountintThe number of primitives to draw.
vertexDeclarationVertexDeclarationThe layout of the vertices.
Type Parameters
TThe type of the vertices.
Remarks
All indices in the vertex buffer are interpreted relative to the specified vertexOffset.
For example value of zero in the array of indices points to the vertex at index vertexOffset
in the array of vertices.
DrawUserPrimitives<T>(PrimitiveType, T[], int, int)
Draw primitives of the specified type from the data in an array of vertices without indexing.
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount) where T : struct, IVertexType
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex that should be rendered.
primitiveCountintThe number of primitives to draw.
Type Parameters
TThe type of the vertices.
Remarks
The VertexDeclaration will be found by getting VertexDeclaration
from an instance of T and cached for subsequent calls.
DrawUserPrimitives<T>(PrimitiveType, T[], int, int, VertexDeclaration)
Draw primitives of the specified type from the data in the given array of vertices without indexing.
public void DrawUserPrimitives<T>(PrimitiveType primitiveType, T[] vertexData, int vertexOffset, int primitiveCount, VertexDeclaration vertexDeclaration) where T : struct
Parameters
primitiveTypePrimitiveTypeThe type of primitives to draw with the vertices.
vertexDataT[]An array of vertices to draw.
vertexOffsetintThe index in the array of the first vertex that should be rendered.
primitiveCountintThe number of primitives to draw.
vertexDeclarationVertexDeclarationThe layout of the vertices.
Type Parameters
TThe type of the vertices.
~GraphicsDevice()
protected ~GraphicsDevice()
GetBackBufferData<T>(Rectangle?, T[], int, int)
public void GetBackBufferData<T>(Rectangle? rect, T[] data, int startIndex, int elementCount) where T : struct
Parameters
Type Parameters
T
GetBackBufferData<T>(T[])
Gets the Pixel data of what is currently drawn on screen. The format is whatever the current format of the backbuffer is.
public void GetBackBufferData<T>(T[] data) where T : struct
Parameters
dataT[]
Type Parameters
TA byte[] of size (ViewPort.Width * ViewPort.Height * 4)
GetBackBufferData<T>(T[], int, int)
public void GetBackBufferData<T>(T[] data, int startIndex, int elementCount) where T : struct
Parameters
Type Parameters
T
GetRenderTargets()
public RenderTargetBinding[] GetRenderTargets()
Returns
GetRenderTargets(RenderTargetBinding[])
public void GetRenderTargets(RenderTargetBinding[] outTargets)
Parameters
outTargetsRenderTargetBinding[]
Present()
public void Present()
Reset()
public void Reset()
Reset(PresentationParameters)
public void Reset(PresentationParameters presentationParameters)
Parameters
presentationParametersPresentationParameters
SetRenderTarget(RenderTarget2D)
public void SetRenderTarget(RenderTarget2D renderTarget)
Parameters
renderTargetRenderTarget2D
SetRenderTarget(RenderTargetCube, CubeMapFace)
public void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
Parameters
renderTargetRenderTargetCubecubeMapFaceCubeMapFace
SetRenderTargets(params RenderTargetBinding[])
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
Parameters
renderTargetsRenderTargetBinding[]
SetVertexBuffer(VertexBuffer)
public void SetVertexBuffer(VertexBuffer vertexBuffer)
Parameters
vertexBufferVertexBuffer
SetVertexBuffer(VertexBuffer, int)
public void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset)
Parameters
vertexBufferVertexBuffervertexOffsetint
SetVertexBuffers(params VertexBufferBinding[])
public void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)
Parameters
vertexBuffersVertexBufferBinding[]
Events
DeviceLost
public event EventHandler<EventArgs> DeviceLost
Event Type
DeviceReset
public event EventHandler<EventArgs> DeviceReset
Event Type
DeviceResetting
public event EventHandler<EventArgs> DeviceResetting
Event Type
Disposing
public event EventHandler<EventArgs> Disposing
Event Type
ResourceCreated
public event EventHandler<ResourceCreatedEventArgs> ResourceCreated
Event Type
ResourceDestroyed
public event EventHandler<ResourceDestroyedEventArgs> ResourceDestroyed