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
adapter
GraphicsAdapterThe graphics adapter.
graphicsProfile
GraphicsProfileThe graphics profile.
presentationParameters
PresentationParametersThe presentation options.
Exceptions
- ArgumentNullException
presentationParameters
is 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
adapter
GraphicsAdapterThe graphics adapter.
graphicsProfile
GraphicsProfileThe graphics profile.
preferHalfPixelOffset
boolIndicates if DX9 style pixel addressing or current standard pixel addressing should be used. This value is passed to UseHalfPixelOffset
presentationParameters
PresentationParametersThe presentation options.
Exceptions
- ArgumentNullException
presentationParameters
is 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
color
Color
Clear(ClearOptions, Color, float, int)
public void Clear(ClearOptions options, Color color, float depth, int stencil)
Parameters
options
ClearOptionscolor
Colordepth
floatstencil
int
Clear(ClearOptions, Vector4, float, int)
public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)
Parameters
options
ClearOptionscolor
Vector4depth
floatstencil
int
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
disposing
bool
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
primitiveType
PrimitiveTypeThe type of primitives in the index buffer.
baseVertex
intUsed to offset the vertex range indexed from the vertex buffer.
startIndex
intThe index within the index buffer to start drawing from.
primitiveCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives in the index buffer.
baseVertex
intUsed to offset the vertex range indexed from the vertex buffer.
minVertexIndex
intThis is unused and remains here only for XNA API compatibility.
numVertices
intThis is unused and remains here only for XNA API compatibility.
startIndex
intThe index within the index buffer to start drawing from.
primitiveCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives in the index buffer.
baseVertex
intUsed to offset the vertex range indexed from the vertex buffer.
startIndex
intThe index within the index buffer to start drawing from.
primitiveCount
intThe number of primitives in a single instance.
instanceCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives in the index buffer.
baseVertex
intUsed to offset the vertex range indexed from the vertex buffer.
startIndex
intThe index within the index buffer to start drawing from.
primitiveCount
intThe number of primitives in a single instance.
baseInstance
intUsed to offset the instance range indexed from the instance buffer.
instanceCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives in the index buffer.
baseVertex
intUsed to offset the vertex range indexed from the vertex buffer.
minVertexIndex
intThis is unused and remains here only for XNA API compatibility.
numVertices
intThis is unused and remains here only for XNA API compatibility.
startIndex
intThe index within the index buffer to start drawing from.
primitiveCount
intThe number of primitives in a single instance.
instanceCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives to draw.
vertexStart
intIndex of the vertex to start at.
primitiveCount
intThe 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex to draw.
numVertices
intThe number of vertices to draw.
indexData
short[]The index data.
indexOffset
intThe index in the array of indices of the first index to use
primitiveCount
intThe number of primitives to draw.
Type Parameters
T
The 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex to draw.
numVertices
intThe number of vertices to draw.
indexData
short[]The index data.
indexOffset
intThe index in the array of indices of the first index to use
primitiveCount
intThe number of primitives to draw.
vertexDeclaration
VertexDeclarationThe layout of the vertices.
Type Parameters
T
The 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex to draw.
numVertices
intThe number of vertices to draw.
indexData
int[]The index data.
indexOffset
intThe index in the array of indices of the first index to use
primitiveCount
intThe number of primitives to draw.
Type Parameters
T
The 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex to draw.
numVertices
intThe number of vertices to draw.
indexData
int[]The index data.
indexOffset
intThe index in the array of indices of the first index to use
primitiveCount
intThe number of primitives to draw.
vertexDeclaration
VertexDeclarationThe layout of the vertices.
Type Parameters
T
The 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex that should be rendered.
primitiveCount
intThe number of primitives to draw.
Type Parameters
T
The 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
primitiveType
PrimitiveTypeThe type of primitives to draw with the vertices.
vertexData
T[]An array of vertices to draw.
vertexOffset
intThe index in the array of the first vertex that should be rendered.
primitiveCount
intThe number of primitives to draw.
vertexDeclaration
VertexDeclarationThe layout of the vertices.
Type Parameters
T
The 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
data
T[]
Type Parameters
T
A 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
outTargets
RenderTargetBinding[]
Present()
public void Present()
Reset()
public void Reset()
Reset(PresentationParameters)
public void Reset(PresentationParameters presentationParameters)
Parameters
presentationParameters
PresentationParameters
SetRenderTarget(RenderTarget2D)
public void SetRenderTarget(RenderTarget2D renderTarget)
Parameters
renderTarget
RenderTarget2D
SetRenderTarget(RenderTargetCube, CubeMapFace)
public void SetRenderTarget(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
Parameters
renderTarget
RenderTargetCubecubeMapFace
CubeMapFace
SetRenderTargets(params RenderTargetBinding[])
public void SetRenderTargets(params RenderTargetBinding[] renderTargets)
Parameters
renderTargets
RenderTargetBinding[]
SetVertexBuffer(VertexBuffer)
public void SetVertexBuffer(VertexBuffer vertexBuffer)
Parameters
vertexBuffer
VertexBuffer
SetVertexBuffer(VertexBuffer, int)
public void SetVertexBuffer(VertexBuffer vertexBuffer, int vertexOffset)
Parameters
vertexBuffer
VertexBuffervertexOffset
int
SetVertexBuffers(params VertexBufferBinding[])
public void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)
Parameters
vertexBuffers
VertexBufferBinding[]
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