Skip to content

GraphicsDevice class reference

Alan Stagner edited this page Jun 9, 2020 · 1 revision

Methods

void FlushChanges() - Immediately flush any changes made to the graphics device (back buffer format, MSAA, present interval, etc). If this is not called, any changes made will take effect on the next frame, so you normally won't need to worry about calling this.


void BeginFrame() - Begin rendering a new frame. This is automatically called by Game as part of the main loop, so you shouldn't have to call this yourself.


void Present() - Swap buffers, present to the screen, and wait for present interval. This is automatically called by Game as part of the main loop, so you shouldn't have to call this yourself


void Clear(ClearOptions clearOptions, Color color, float depth = 0f, int stencil = 0) - Clear the current render target (optionally clearing any or all of color, depth, and stencil buffers with the given values)


void Blit(Texture2D source, ColorRenderBuffer dest) - Blit the given texture into the given target. Note that this will change the current render target to dest.


void SetViewport(Viewport viewport) - Set the current viewport.


void SetScissorRect(Rect scissorRect) - Set the scissor rectangle.


void SetBlendState(BlendState blendState) - Set the blend state for the following graphics commands


void SetDepthStencilState(DepthStencilState depthStencilState) - Set the depth+stencil state for the following graphics commands


void ApplyRasterizerState(RasterizerState rasterizerState) - Set the rasterizer state for the following graphics commands


void ApplyVertexBufferBinding(VertexBuffer buffer, bool bindingsUpdated = true, int baseVertex = 0) - Bind a vertex buffer for following draw calls to use


void DrawIndexedPrimitives(PrimitiveType type, VertexBuffer buffer, int primitiveCount, IndexBuffer indexBuffer)
void DrawIndexedPrimitives(PrimitiveType type, VertexBufferSpan buffer, int primitiveCount, IndexBuffer indexBuffer)
void DrawIndexedPrimitives(PrimitiveType type, VertexBuffer buffer, int baseVertex, int numVertices, int startIndex, int primitiveCount, IndexBuffer indexBuffer)

Bind a vertex buffer and then draw from it using an index buffer


void DrawIndexedPrimitives(PrimitiveType type, int baseVertex, int numVertices, int startIndex, int primitiveCount, IndexBuffer indexBuffer) - Draw from the previously bound vertex buffer using an index buffer


void DrawInstancedPrimitives(PrimitiveType type, int baseVertex, int numVertices, int startIndex, int primitiveCount, int instanceCount, IndexBuffer indexBuffer) - Draws a number of instances of the previously bound vertex buffer using an index buffer


void DrawPrimitives(PrimitiveType type, int vertexStart, int primitiveCount) - Draws a number of sequential primitives from the previously bound vertex buffer.


void SetRenderTarget(ColorRenderBuffer renderBuffer)
void SetRenderTarget(ColorRenderBuffer renderBuffer, DepthStencilRenderBuffer depthBuffer)
void SetRenderTargets(ColorRenderBuffer[] renderBuffer, DepthStencilBuffer depthBuffer)

Set the current render target(s). Provide null to set to back buffer.


void PushCurrentRenderTarget() - Save the current render target onto a stack. Use this when you want to temporarily change the render target and then set it back afterwards


void PopCurrentRenderTarget() - Revert back to the last render target. Use this after the previous call to restore.


void ResolveTarget(ColorRenderBuffer renderTarget) - Use this after you've rendered to render buffer to resolve multisampling and/or mipmaps.

Properties

SurfaceFormat BackbufferFormat { get; set; } - Gets or sets the color format of the backbuffer


DepthFormat DepthStencilFormat { get; set; } - Gets or sets the depth+stencil format of the backbuffer


int TargetWidth { get; } - Gets the width of the current render target (either the back buffer or a render buffer)


int TargetHeight { get; } - Gets the height of the current render target (either the back buffer or a render buffer)


int BackbufferWidth { get; set; } - Gets or sets the width of the backbuffer


int BackbufferHeight { get; set; } - Gets or sets the height of the backbuffer


DisplayOrientation Orientation { get; set; } - Gets or sets the orientation. You do not need to set this yourself, it is automatically updated from the GameWindow orientation.


bool IsFullscreen { get; set; } - Gets or sets whether the graphics device is in fullscreen. Normally you should be using GameWindow.IsFullscreen instead.


int MultiSampleCount { get; set; } - Gets or sets the multisample count. The default is 1 which disables multi-sampling, other valid values are 2, 4, or 8


PresentInterval PresentInverval { get; set; } - Gets or sets the present interval (Default tries to wait for vsync unless the game is running too slow, One waits for vsync, Two waits for every other vsync, and Immediate disables vsync)