Table of Contents

Class GraphicsDevice

Namespace
Microsoft.Xna.Framework.Graphics
Assembly
MonoGame.Framework.dll
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 GraphicsAdapter

The graphics adapter.

graphicsProfile GraphicsProfile

The graphics profile.

presentationParameters PresentationParameters

The 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 GraphicsAdapter

The graphics adapter.

graphicsProfile GraphicsProfile

The graphics profile.

preferHalfPixelOffset bool

Indicates if DX9 style pixel addressing or current standard pixel addressing should be used. This value is passed to UseHalfPixelOffset

presentationParameters PresentationParameters

The presentation options.

Exceptions

ArgumentNullException

presentationParameters is null.

Properties

Adapter

public GraphicsAdapter Adapter { get; }

Property Value

GraphicsAdapter

BlendFactor

The color used as blend factor when alpha blending.

public Color BlendFactor { get; set; }

Property Value

Color

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

BlendState

DepthStencilState

public DepthStencilState DepthStencilState { get; set; }

Property Value

DepthStencilState

DiscardColor

Get or set the color a RenderTarget2D is cleared to when it is set.

public static Color DiscardColor { get; set; }

Property Value

Color

DisplayMode

public DisplayMode DisplayMode { get; }

Property Value

DisplayMode

GraphicsDebug

Access debugging APIs for the graphics subsystem.

public GraphicsDebug GraphicsDebug { get; set; }

Property Value

GraphicsDebug

GraphicsDeviceStatus

public GraphicsDeviceStatus GraphicsDeviceStatus { get; }

Property Value

GraphicsDeviceStatus

GraphicsProfile

public GraphicsProfile GraphicsProfile { get; }

Property Value

GraphicsProfile

Indices

public IndexBuffer Indices { get; set; }

Property Value

IndexBuffer

IsContentLost

public bool IsContentLost { get; }

Property Value

bool

IsDisposed

public bool IsDisposed { get; }

Property Value

bool

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

GraphicsMetrics

PresentationParameters

public PresentationParameters PresentationParameters { get; }

Property Value

PresentationParameters

RasterizerState

public RasterizerState RasterizerState { get; set; }

Property Value

RasterizerState

RenderTargetCount

public int RenderTargetCount { get; }

Property Value

int

ResourcesLost

public bool ResourcesLost { get; set; }

Property Value

bool

SamplerStates

public SamplerStateCollection SamplerStates { get; }

Property Value

SamplerStateCollection

ScissorRectangle

public Rectangle ScissorRectangle { get; set; }

Property Value

Rectangle

Textures

public TextureCollection Textures { get; }

Property Value

TextureCollection

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

bool

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

SamplerStateCollection

VertexTextures

public TextureCollection VertexTextures { get; }

Property Value

TextureCollection

Viewport

public Viewport Viewport { get; set; }

Property Value

Viewport

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 ClearOptions
color Color
depth float
stencil int

Clear(ClearOptions, Vector4, float, int)

public void Clear(ClearOptions options, Vector4 color, float depth, int stencil)

Parameters

options ClearOptions
color Vector4
depth float
stencil 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 PrimitiveType

The type of primitives in the index buffer.

baseVertex int

Used to offset the vertex range indexed from the vertex buffer.

startIndex int

The index within the index buffer to start drawing from.

primitiveCount int

The 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 PrimitiveType

The type of primitives in the index buffer.

baseVertex int

Used to offset the vertex range indexed from the vertex buffer.

minVertexIndex int

This is unused and remains here only for XNA API compatibility.

numVertices int

This is unused and remains here only for XNA API compatibility.

startIndex int

The index within the index buffer to start drawing from.

primitiveCount int

The 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 PrimitiveType

The type of primitives in the index buffer.

baseVertex int

Used to offset the vertex range indexed from the vertex buffer.

startIndex int

The index within the index buffer to start drawing from.

primitiveCount int

The number of primitives in a single instance.

instanceCount int

The 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 PrimitiveType

The type of primitives in the index buffer.

baseVertex int

Used to offset the vertex range indexed from the vertex buffer.

startIndex int

The index within the index buffer to start drawing from.

primitiveCount int

The number of primitives in a single instance.

baseInstance int

Used to offset the instance range indexed from the instance buffer.

instanceCount int

The 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 PrimitiveType

The type of primitives in the index buffer.

baseVertex int

Used to offset the vertex range indexed from the vertex buffer.

minVertexIndex int

This is unused and remains here only for XNA API compatibility.

numVertices int

This is unused and remains here only for XNA API compatibility.

startIndex int

The index within the index buffer to start drawing from.

primitiveCount int

The number of primitives in a single instance.

instanceCount int

The 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 PrimitiveType

The type of primitives to draw.

vertexStart int

Index of the vertex to start at.

primitiveCount int

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex to draw.

numVertices int

The number of vertices to draw.

indexData short[]

The index data.

indexOffset int

The index in the array of indices of the first index to use

primitiveCount int

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex to draw.

numVertices int

The number of vertices to draw.

indexData short[]

The index data.

indexOffset int

The index in the array of indices of the first index to use

primitiveCount int

The number of primitives to draw.

vertexDeclaration VertexDeclaration

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex to draw.

numVertices int

The number of vertices to draw.

indexData int[]

The index data.

indexOffset int

The index in the array of indices of the first index to use

primitiveCount int

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex to draw.

numVertices int

The number of vertices to draw.

indexData int[]

The index data.

indexOffset int

The index in the array of indices of the first index to use

primitiveCount int

The number of primitives to draw.

vertexDeclaration VertexDeclaration

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex that should be rendered.

primitiveCount int

The 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 PrimitiveType

The type of primitives to draw with the vertices.

vertexData T[]

An array of vertices to draw.

vertexOffset int

The index in the array of the first vertex that should be rendered.

primitiveCount int

The number of primitives to draw.

vertexDeclaration VertexDeclaration

The 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

rect Rectangle?
data T[]
startIndex int
elementCount int

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

data T[]
startIndex int
elementCount int

Type Parameters

T

GetRenderTargets()

public RenderTargetBinding[] GetRenderTargets()

Returns

RenderTargetBinding[]

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 RenderTargetCube
cubeMapFace 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 VertexBuffer
vertexOffset int

SetVertexBuffers(params VertexBufferBinding[])

public void SetVertexBuffers(params VertexBufferBinding[] vertexBuffers)

Parameters

vertexBuffers VertexBufferBinding[]

Events

DeviceLost

public event EventHandler<EventArgs> DeviceLost

Event Type

EventHandler<EventArgs>

DeviceReset

public event EventHandler<EventArgs> DeviceReset

Event Type

EventHandler<EventArgs>

DeviceResetting

public event EventHandler<EventArgs> DeviceResetting

Event Type

EventHandler<EventArgs>

Disposing

public event EventHandler<EventArgs> Disposing

Event Type

EventHandler<EventArgs>

ResourceCreated

public event EventHandler<ResourceCreatedEventArgs> ResourceCreated

Event Type

EventHandler<ResourceCreatedEventArgs>

ResourceDestroyed

public event EventHandler<ResourceDestroyedEventArgs> ResourceDestroyed

Event Type

EventHandler<ResourceDestroyedEventArgs>