Table of Contents

Class GraphicsDevice

Namespace
Pie
Assembly
Pie.dll

A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

public abstract class GraphicsDevice : IDisposable
Inheritance
GraphicsDevice
Implements
Inherited Members

Properties

Adapter

The GraphicsAdapter this device is running on.

public abstract GraphicsAdapter Adapter { get; }

Property Value

GraphicsAdapter
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

Api

Get the GraphicsApi this device is using.

public abstract GraphicsApi Api { get; }

Property Value

GraphicsApi
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

Scissor

Get or set the scissor rectangle of this device.

public abstract Rectangle Scissor { get; set; }

Property Value

Rectangle
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

Swapchain

Get the Swapchain of this device.

public abstract Swapchain Swapchain { get; }

Property Value

Swapchain
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

Viewport

Get or set the viewport of this device.

public abstract Rectangle Viewport { get; set; }

Property Value

Rectangle
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

Methods

ClearColorBuffer(Color)

Clears the set Framebuffer's color texture with the given color and flags. If no framebuffer is set, this clears the back buffer.

public abstract void ClearColorBuffer(Color color)

Parameters

color Color

The color to clear with.

ClearColorBuffer(Vector4)

Clears the set Framebuffer's color texture with the given normalized color and flags. If no framebuffer is set, this clears the back buffer.

public abstract void ClearColorBuffer(Vector4 color)

Parameters

color Vector4

The color to clear with. This value should be normalized between 0-1.

ClearColorBuffer(float, float, float, float)

Clears the set Framebuffer's color texture with the given normalized color and flags. If no framebuffer is set, this clears the back buffer.

public abstract void ClearColorBuffer(float r, float g, float b, float a)

Parameters

r float

The red channel, normalized between 0-1.

g float

The green channel, normalized between 0-1.

b float

The blue channel, normalized between 0-1.

a float

The alpha channel, normalized between 0-1.

ClearDepthStencilBuffer(ClearFlags, float, byte)

Clears the set Framebuffer's depth stencil texture with the given flags. If no framebuffer is set, this clears the back buffer.

public abstract void ClearDepthStencilBuffer(ClearFlags flags, float depth, byte stencil)

Parameters

flags ClearFlags

Which part(s) of the depth-stencil buffer to clear.

depth float

The depth value to clear with.

stencil byte

The stencil value to clear with.

CreateBlendState(BlendStateDescription)

Create a new blend state from the blend state description.

public abstract BlendState CreateBlendState(BlendStateDescription description)

Parameters

description BlendStateDescription

The blend state description to create from.

Returns

BlendState

The created blend state.

CreateBuffer(BufferType, uint, bool)

Create an empty graphics buffer with the given size.

public abstract GraphicsBuffer CreateBuffer(BufferType bufferType, uint sizeInBytes, bool dynamic = false)

Parameters

bufferType BufferType

The type of buffer that should be created.

sizeInBytes uint

The size, in bytes, that this buffer should be.

dynamic bool

Whether or not this buffer is dynamic.

Returns

GraphicsBuffer

The created graphics buffer.

CreateBuffer(BufferType, uint, nint, bool)

Create a graphics buffer with the given type and data.

public abstract GraphicsBuffer CreateBuffer(BufferType bufferType, uint sizeInBytes, nint data, bool dynamic = false)

Parameters

bufferType BufferType

The type of buffer that should be created.

sizeInBytes uint

The size, in bytes, that this buffer should be.

data nint

The data pointer.

dynamic bool

Whether or not this buffer is dynamic.

Returns

GraphicsBuffer

The created graphics buffer.

CreateBuffer(BufferType, uint, void*, bool)

Create a graphics buffer with the given type and data.

public abstract GraphicsBuffer CreateBuffer(BufferType bufferType, uint sizeInBytes, void* data, bool dynamic = false)

Parameters

bufferType BufferType

The type of buffer that should be created.

sizeInBytes uint

The size, in bytes, that this buffer should be.

data void*

The data pointer.

dynamic bool

Whether or not this buffer is dynamic.

Returns

GraphicsBuffer

The created graphics buffer.

CreateBuffer<T>(BufferType, T, bool)

Create a graphics buffer with the given type and data.

public abstract GraphicsBuffer CreateBuffer<T>(BufferType bufferType, T data, bool dynamic = false) where T : unmanaged

Parameters

bufferType BufferType

The type of buffer that should be created.

data T

The data itself.

dynamic bool

Whether or not this buffer is dynamic.

Returns

GraphicsBuffer

The created graphics buffer.

Type Parameters

T

Any unmanaged type.

CreateBuffer<T>(BufferType, T[], bool)

Create a graphics buffer with the given type and data.

public abstract GraphicsBuffer CreateBuffer<T>(BufferType bufferType, T[] data, bool dynamic = false) where T : unmanaged

Parameters

bufferType BufferType

The type of buffer that should be created.

data T[]

The data itself.

dynamic bool

Whether or not this buffer is dynamic.

Returns

GraphicsBuffer

The created graphics buffer.

Type Parameters

T

Any unmanaged type.

CreateD3D11(nint, Size, GraphicsDeviceOptions)

Create a Direct3D 11 graphics device.

public static GraphicsDevice CreateD3D11(nint hwnd, Size winSize, GraphicsDeviceOptions options = default)

Parameters

hwnd nint

The HWND pointer.

winSize Size

The size of the window on startup.

options GraphicsDeviceOptions

The options for this graphics device, if any.

Returns

GraphicsDevice

The created graphics device.

CreateDepthStencilState(DepthStencilStateDescription)

Create a new depth state from the depth state description.

public abstract DepthStencilState CreateDepthStencilState(DepthStencilStateDescription description)

Parameters

description DepthStencilStateDescription

The depth state description to create from.

Returns

DepthStencilState

The created depth state.

CreateFramebuffer(params FramebufferAttachment[])

Create a framebuffer, also known as a render target, that can be rendered to.

public abstract Framebuffer CreateFramebuffer(params FramebufferAttachment[] attachments)

Parameters

attachments FramebufferAttachment[]

The framebuffer attachments to attach.

Returns

Framebuffer

The created framebuffer.

CreateInputLayout(params InputLayoutDescription[])

Create an input layout which can be used with a vertex buffer.

public abstract InputLayout CreateInputLayout(params InputLayoutDescription[] inputLayoutDescriptions)

Parameters

inputLayoutDescriptions InputLayoutDescription[]

The descriptions for this layout.

Returns

InputLayout

The created input layout.

CreateNull(Size, GraphicsDeviceOptions)

Create a null graphics device.

public static GraphicsDevice CreateNull(Size winSize, GraphicsDeviceOptions options = default)

Parameters

winSize Size

The initial window size. (Use 0x0 if you're not using a window).

options GraphicsDeviceOptions

The options for this graphics device, if any.

Returns

GraphicsDevice

The created graphics device.

CreateOpenGL(PieGlContext, Size, bool, GraphicsDeviceOptions)

Create an OpenGL 3.3 graphics device.

public static GraphicsDevice CreateOpenGL(PieGlContext context, Size winSize, bool isEs, GraphicsDeviceOptions options = default)

Parameters

context PieGlContext

The GL context.

winSize Size

The size of the window on startup.

isEs bool

If enabled, the device will behave like it has been created with an OpenGL ES 3.0 context.

options GraphicsDeviceOptions

The options for this graphics device, if any.

Returns

GraphicsDevice

The created graphics device.

CreateRasterizerState(RasterizerStateDescription)

Create a new rasterizer state from the given description.

public abstract RasterizerState CreateRasterizerState(RasterizerStateDescription description)

Parameters

description RasterizerStateDescription

The rasterizer state description.

Returns

RasterizerState

The created rasterizer state.

CreateSamplerState(SamplerStateDescription)

Create a new sampler state from the sampler state description.

public abstract SamplerState CreateSamplerState(SamplerStateDescription description)

Parameters

description SamplerStateDescription

The sampler state description to create from.

Returns

SamplerState

The created sampler state.

CreateShader(ShaderAttachment[], SpecializationConstant[])

Create a shader with the given shader attachments.

public abstract Shader CreateShader(ShaderAttachment[] attachments, SpecializationConstant[] constants = null)

Parameters

attachments ShaderAttachment[]

The attachments for this shader.

constants SpecializationConstant[]

Any specialization constants to use in this shader.

Returns

Shader

The created shader.

CreateTexture(TextureDescription)

Create an empty texture with the given description.

public abstract Texture CreateTexture(TextureDescription description)

Parameters

description TextureDescription

The description of the texture.

Returns

Texture

The created texture.

CreateTexture(TextureDescription, nint)

Create a texture with the given description and data.

public abstract Texture CreateTexture(TextureDescription description, nint data)

Parameters

description TextureDescription

The description of the texture.

data nint

The pointer to the data.

Returns

Texture

The created texture.

CreateTexture(TextureDescription, void*)

Create a texture with the given description and data.

public abstract Texture CreateTexture(TextureDescription description, void* data)

Parameters

description TextureDescription

The description of the texture.

data void*

The pointer to the data.

Returns

Texture

The created texture.

CreateTexture<T>(TextureDescription, T[])

Create a texture with the given description and data.

public abstract Texture CreateTexture<T>(TextureDescription description, T[] data) where T : unmanaged

Parameters

description TextureDescription

The description of the texture.

data T[]

The initial data of the texture.

Returns

Texture

The created texture.

Type Parameters

T

The data type, typically byte or float. This type should match the Format in the description.

CreateTexture<T>(TextureDescription, T[][])

Create a texture with the given description and array data.

public abstract Texture CreateTexture<T>(TextureDescription description, T[][] data) where T : unmanaged

Parameters

description TextureDescription

The description of the texture.

data T[][]

The initial array data of the texture.

Returns

Texture

The created texture.

Type Parameters

T

The data type, typically byte or float. This type should match the Format in the description.

Remarks

As this takes in array data, this method should only be used with array textures and cubemaps.

Dispatch(uint, uint, uint)

Dispatch the current compute shader.

public abstract void Dispatch(uint groupCountX, uint groupCountY, uint groupCountZ)

Parameters

groupCountX uint

The number of thread groups in X.

groupCountY uint

The number of thread groups in Y.

groupCountZ uint

The number of thread groups in Z.

Dispose()

Dispose of this graphics device.

public abstract void Dispose()

Draw(uint)

Draw to the screen with the given number of vertices.

public abstract void Draw(uint vertexCount)

Parameters

vertexCount uint

The number of vertices.

Draw(uint, int)

Draw to the screen with the given number of vertices, at the given start vertex.

public abstract void Draw(uint vertexCount, int startVertex)

Parameters

vertexCount uint

The number of vertices.

startVertex int

The starting vertex of the vertices to draw.

DrawIndexed(uint)

Draw to the screen with the given indices count.

public abstract void DrawIndexed(uint indexCount)

Parameters

indexCount uint

The number of indices.

DrawIndexed(uint, int)

Draw to the screen with the given indices count, at the given start index.

public abstract void DrawIndexed(uint indexCount, int startIndex)

Parameters

indexCount uint

The number of indices.

startIndex int

The starting index of the indices to draw.

DrawIndexed(uint, int, int)

Draw to the screen with the given indices count, at the given start index, at the given base vertex.

public abstract void DrawIndexed(uint indexCount, int startIndex, int baseVertex)

Parameters

indexCount uint

The number of indices.

startIndex int

The starting index of the indices to draw.

baseVertex int

The base vertex of the indices to draw.

DrawIndexedInstanced(uint, uint)

Draw with instancing, with the given indices count and number of instances.

public abstract void DrawIndexedInstanced(uint indexCount, uint instanceCount)

Parameters

indexCount uint

The number of indices.

instanceCount uint

The number of instances.

Flush()

Force the device to execute all queued commands in the command buffer.

public abstract void Flush()

GenerateMipmaps(Texture)

Generate mipmaps for the given texture.

public abstract void GenerateMipmaps(Texture texture)

Parameters

texture Texture

GetBestApiForPlatform()

Determine the best graphics API to use for the current platform.

public static GraphicsApi GetBestApiForPlatform()

Returns

GraphicsApi

MapResource(MappableResource, MapMode)

Map the given resource to CPU accessible memory.

public abstract MappedSubresource MapResource(MappableResource resource, MapMode mode)

Parameters

resource MappableResource

The resource to map.

mode MapMode

The CPU access mode of this resource.

Returns

MappedSubresource

The mapped resource's data.

Present(int)

Present to the screen.

public abstract void Present(int swapInterval)

Parameters

swapInterval int
A Pie Graphics Device provides all the rendering functions for a given physical graphics device.

ResizeSwapchain(Size)

Resize the swapchain.

public abstract void ResizeSwapchain(Size newSize)

Parameters

newSize Size

The new size of the swapchain.

SetBlendState(BlendState)

Set the blend state that will be used on next draw.

public abstract void SetBlendState(BlendState state)

Parameters

state BlendState

The blend state to use.

SetDepthStencilState(DepthStencilState, int)

Set the depth-stencil state that will be used on next draw.

public abstract void SetDepthStencilState(DepthStencilState state, int stencilRef = 0)

Parameters

state DepthStencilState

The depth-stencil state to use.

stencilRef int

The reference value to perform against when performing a stencil test.

SetFramebuffer(Framebuffer)

Set the framebuffer that will be used on next draw. Set as null to use the default back buffer.

public abstract void SetFramebuffer(Framebuffer framebuffer)

Parameters

framebuffer Framebuffer

The framebuffer to use.

SetIndexBuffer(GraphicsBuffer, IndexType)

Set the index buffer that will be used on next draw.

public abstract void SetIndexBuffer(GraphicsBuffer buffer, IndexType type)

Parameters

buffer GraphicsBuffer

The buffer to use.

type IndexType

The type of indices.

SetInputLayout(InputLayout)

Sets the input layout what will be used on next draw.

public abstract void SetInputLayout(InputLayout layout)

Parameters

layout InputLayout

The input layout to use.

SetPrimitiveType(PrimitiveType)

Set the primitive type that will be used on next draw.

public abstract void SetPrimitiveType(PrimitiveType type)

Parameters

type PrimitiveType

The primitive type to draw with.

SetRasterizerState(RasterizerState)

Set the rasterizer state that will be used on next draw.

public abstract void SetRasterizerState(RasterizerState state)

Parameters

state RasterizerState

The rasterizer state to use.

SetShader(Shader)

Set the shader that will be used on next draw.

public abstract void SetShader(Shader shader)

Parameters

shader Shader

The shader to use.

SetTexture(uint, Texture, SamplerState)

Set the texture that will be used on next draw.

public abstract void SetTexture(uint bindingSlot, Texture texture, SamplerState samplerState)

Parameters

bindingSlot uint

The binding slot that this texture will be used in.

texture Texture

The texture to use.

samplerState SamplerState

The sampler state to use for this texture.

SetUniformBuffer(uint, GraphicsBuffer)

Set the uniform buffer that will be used on next draw.

public abstract void SetUniformBuffer(uint bindingSlot, GraphicsBuffer buffer)

Parameters

bindingSlot uint
buffer GraphicsBuffer

The buffer to use.

SetVertexBuffer(uint, GraphicsBuffer, uint)

Set the vertex buffer that will be used on next draw.

public abstract void SetVertexBuffer(uint slot, GraphicsBuffer buffer, uint stride)

Parameters

slot uint

The input slot.

buffer GraphicsBuffer

The buffer to use.

stride uint

The stride, in bytes, for the input layout.

UnmapResource(MappableResource)

Unmapped the given mapped resource.

public abstract void UnmapResource(MappableResource resource)

Parameters

resource MappableResource

The resource to unmap.

UpdateBuffer(GraphicsBuffer, uint, uint, nint)

Update the given buffer with the given data at the given offset in bytes.

public abstract void UpdateBuffer(GraphicsBuffer buffer, uint offsetInBytes, uint sizeInBytes, nint data)

Parameters

buffer GraphicsBuffer

The buffer to update.

offsetInBytes uint

The offset in bytes, if any, where the data will be updated.

sizeInBytes uint

The size in bytes of the data.

data nint

The data pointer.

UpdateBuffer(GraphicsBuffer, uint, uint, void*)

Update the given buffer with the given data at the given offset in bytes.

public abstract void UpdateBuffer(GraphicsBuffer buffer, uint offsetInBytes, uint sizeInBytes, void* data)

Parameters

buffer GraphicsBuffer

The buffer to update.

offsetInBytes uint

The offset in bytes, if any, where the data will be updated.

sizeInBytes uint

The size in bytes of the data.

data void*

The data pointer.

UpdateBuffer<T>(GraphicsBuffer, uint, T)

Update the given buffer with the given data at the given offset in bytes.

public abstract void UpdateBuffer<T>(GraphicsBuffer buffer, uint offsetInBytes, T data) where T : unmanaged

Parameters

buffer GraphicsBuffer

The buffer to update.

offsetInBytes uint

The offset in bytes, if any, where the data will be updated.

data T

The data itself.

Type Parameters

T

Any unmanaged type.

UpdateBuffer<T>(GraphicsBuffer, uint, T[])

Update the given buffer with the given data at the given offset in bytes.

public abstract void UpdateBuffer<T>(GraphicsBuffer buffer, uint offsetInBytes, T[] data) where T : unmanaged

Parameters

buffer GraphicsBuffer

The buffer to update.

offsetInBytes uint

The offset in bytes, if any, where the data will be updated.

data T[]

The data itself.

Type Parameters

T

Any unmanaged type.

UpdateTexture(Texture, int, int, int, int, int, int, int, int, nint)

Update a region of this texture with the given data.

public abstract void UpdateTexture(Texture texture, int mipLevel, int arrayIndex, int x, int y, int z, int width, int height, int depth, nint data)

Parameters

texture Texture

The texture to update.

mipLevel int

The mip level to update.

arrayIndex int

The array index to update.

x int

The x-offset in pixels of the data.

y int

The y-offset in pixels of the data.

z int

The z-offset in pixels of the data.

width int

The width in pixels of the data.

height int

The height in pixels of the data.

depth int

The depth in pixels of the texture.

data nint

The data pointer.

UpdateTexture(Texture, int, int, int, int, int, int, int, int, void*)

Update a region of this texture with the given data.

public abstract void UpdateTexture(Texture texture, int mipLevel, int arrayIndex, int x, int y, int z, int width, int height, int depth, void* data)

Parameters

texture Texture

The texture to update.

mipLevel int

The mip level to update.

arrayIndex int

The array index to update.

x int

The x-offset in pixels of the data.

y int

The y-offset in pixels of the data.

z int

The z-offset in pixels of the data.

width int

The width in pixels of the data.

height int

The height in pixels of the data.

depth int

The depth in pixels of the texture.

data void*

The data pointer.

UpdateTexture<T>(Texture, int, int, int, int, int, int, int, int, T[])

Update a region of this texture with the given data.

public abstract void UpdateTexture<T>(Texture texture, int mipLevel, int arrayIndex, int x, int y, int z, int width, int height, int depth, T[] data) where T : unmanaged

Parameters

texture Texture

The texture to update.

mipLevel int

The mip level to update.

arrayIndex int

The array index to update.

x int

The x-offset in pixels of the data.

y int

The y-offset in pixels of the data.

z int

The z-offset in pixels of the data.

width int

The width in pixels of the data.

height int

The height in pixels of the data.

depth int

The depth in pixels of the texture.

data T[]

The data itself.

Type Parameters

T

The data type, typically byte or float. This type should match the Format in the texture's TextureDescription.