Gorgon
Show / Hide Table of Contents

Class Gorgon2DShaderStateBuilder<T>

A fluent interface used to create shader states for use with a Gorgon2DBatchState.

Inheritance
object
Gorgon2DShaderStateBuilder<T>
Implements
IGorgonFluentBuilderAllocator<Gorgon2DShaderStateBuilder<T>, Gorgon2DShaderState<T>, IGorgonAllocator<Gorgon2DShaderState<T>>>
IGorgonFluentBuilder<Gorgon2DShaderStateBuilder<T>, Gorgon2DShaderState<T>>
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.Renderers
Assembly: Gorgon.Renderers.Gorgon2D.dll
Syntax
public class Gorgon2DShaderStateBuilder<T> : IGorgonFluentBuilderAllocator<Gorgon2DShaderStateBuilder<T>, Gorgon2DShaderState<T>, IGorgonAllocator<Gorgon2DShaderState<T>>>, IGorgonFluentBuilder<Gorgon2DShaderStateBuilder<T>, Gorgon2DShaderState<T>> where T : GorgonShader
Type Parameters
Name Description
T

The type of shader.

Remarks

This builder creates shader states for state information wrapped around shaders based on GorgonShader. States built by this type are used for passing shader programs and related states to the Gorgon2DBatchState when setting up a batch render via Begin(Gorgon2DBatchState, GorgonCameraCommon).

If a custom pixel or vertex shader is assigned to the state, then developers should note which resource slots, and constant buffer slots are used by the 2D renderer itself. Gorgon will allow overriding of these slots, but in those cases, some information may no longer available and things may not work as expected. The following slots are use by the 2D renderer:

Shader TypeResource typeSlot #Purpose
PixelTexture/Sampler0Primary sprite texture/sampler.
PixelTexture1Additional texture for effects.
PixelConstants0Data for alpha testing.
Pixel and VertexConstants12Timing data.
Pixel and VertexConstants13Miscellaneous data (e.g. target width and height)
VertexConstants0View/Projection matrix for the CurrentCamera (or the default camera if null).
VertexConstants1Data for a polygon sprite.
Following this list, a developer can use any texture slot from 2 and up, and any constant buffer slots between 2 (or 1 for pixel shaders) and 11 for their own data.

Methods

| Edit this page View Source

Build()

Function to return the object.

Declaration
public Gorgon2DShaderState<T> Build()
Returns
Type Description
Gorgon2DShaderState<T>

The object created or updated by this builder.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

Build(IGorgonAllocator<Gorgon2DShaderState<T>>)

Function to return the object.

Declaration
public Gorgon2DShaderState<T> Build(IGorgonAllocator<Gorgon2DShaderState<T>> allocator)
Parameters
Type Name Description
IGorgonAllocator<Gorgon2DShaderState<T>> allocator

The allocator used to create an instance of the object

Returns
Type Description
Gorgon2DShaderState<T>

The object created or updated by this builder.

Remarks

Using an allocator can provide different strategies when building objects. If omitted, the object will be created using the standard new keyword.

A custom allocator can be beneficial because it allows us to use a pool for allocating the objects, and thus allows for recycling of objects. This keeps the garbage collector happy by keeping objects around for as long as we need them, instead of creating objects that can potentially end up in the large object heap or in Gen 2.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

Clear()

Function to clear the builder to a default state.

Declaration
public Gorgon2DShaderStateBuilder<T> Clear()
Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

ConstantBuffer(GorgonConstantBufferView, int)

Function to set a constant buffer for a specific shader stage.

Declaration
public Gorgon2DShaderStateBuilder<T> ConstantBuffer(GorgonConstantBufferView constantBuffer, int slot = 0)
Parameters
Type Name Description
GorgonConstantBufferView constantBuffer

The constant buffer to assign.

int slot

The slot for the constant buffer.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

Exceptions
Type Condition
ArgumentNullException

Thrown when the slot is less than 0, or greater than/equal to MaximumConstantBufferCount.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

ConstantBuffers(IReadOnlyList<GorgonConstantBufferView>, int)

Function to set the constant buffers for a specific shader stage.

Declaration
public Gorgon2DShaderStateBuilder<T> ConstantBuffers(IReadOnlyList<GorgonConstantBufferView> constantBuffers, int startSlot = 0)
Parameters
Type Name Description
IReadOnlyList<GorgonConstantBufferView> constantBuffers

The constant buffers to copy.

int startSlot

[Optional] The starting slot to use when copying the list.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

Exceptions
Type Condition
ArgumentNullException

Thrown when the startSlot is less than 0, or greater than/equal to MaximumConstantBufferCount.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

ResetTo(Gorgon2DShaderState<T>)

Function to reset the builder to the specified object state.

Declaration
public Gorgon2DShaderStateBuilder<T> ResetTo(Gorgon2DShaderState<T> builderObject = null)
Parameters
Type Name Description
Gorgon2DShaderState<T> builderObject

[Optional] The specified object state to copy.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

SamplerState(GorgonSamplerState, int)

Function to assign a sampler to a shader on the pipeline.

Declaration
public Gorgon2DShaderStateBuilder<T> SamplerState(GorgonSamplerState sampler, int index = 0)
Parameters
Type Name Description
GorgonSamplerState sampler

The sampler to assign.

int index

[Optional] The index of the sampler.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the index parameter is less than 0, or greater than/equal to MaximumSamplerStateCount.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

SamplerState(GorgonSamplerStateBuilder, int)

Function to assign a sampler to a shader on the pipeline.

Declaration
public Gorgon2DShaderStateBuilder<T> SamplerState(GorgonSamplerStateBuilder sampler, int index = 0)
Parameters
Type Name Description
GorgonSamplerStateBuilder sampler

The sampler to assign.

int index

[Optional] The index of the sampler.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the index parameter is less than 0, or greater than/equal to MaximumSamplerStateCount.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

SamplerStates(IReadOnlyList<GorgonSamplerState>, int)

Function to assign a list of samplers to a shader on the pipeline.

Declaration
public Gorgon2DShaderStateBuilder<T> SamplerStates(IReadOnlyList<GorgonSamplerState> samplers, int index = 0)
Parameters
Type Name Description
IReadOnlyList<GorgonSamplerState> samplers

The samplers to assign.

int index

[Optional] The starting index to use when copying.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent interface for this builder.

Exceptions
Type Condition
ArgumentOutOfRangeException

Thrown if the index parameter is less than 0, or greater than/equal to MaximumSamplerStateCount.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

Shader(T)

Function to assign the current shader.

Declaration
public Gorgon2DShaderStateBuilder<T> Shader(T shader)
Parameters
Type Name Description
T shader

The shader to assign.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

Remarks

This method is used to share an existing GorgonShader amongst many 2D shader instances. Shared shader objects are not owned by the resulting Gorgon2DShaderState<T>, and must have their lifetimes managed by the user.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

ShaderResource(GorgonShaderResourceView, int)

Function to assign a single shader resource view to the draw call.

Declaration
public Gorgon2DShaderStateBuilder<T> ShaderResource(GorgonShaderResourceView resourceView, int slot = 0)
Parameters
Type Name Description
GorgonShaderResourceView resourceView

The shader resource view to assign.

int slot

[Optional] The slot used to asign the view.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface.

Exceptions
Type Condition
ArgumentNullException

Thrown when the slot is less than 0, or greater than/equal to 16.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
| Edit this page View Source

ShaderResources(IReadOnlyList<GorgonShaderResourceView>, int)

Function to assign the list of shader resource views to the shader.

Declaration
public Gorgon2DShaderStateBuilder<T> ShaderResources(IReadOnlyList<GorgonShaderResourceView> resourceViews, int startSlot = 0)
Parameters
Type Name Description
IReadOnlyList<GorgonShaderResourceView> resourceViews

The shader resource views to copy.

int startSlot

[Optional] The starting slot to use when copying the list.

Returns
Type Description
Gorgon2DShaderStateBuilder<T>

The fluent builder interface .

Exceptions
Type Condition
ArgumentNullException

Thrown when the startSlot is less than 0, or greater than/equal to 16.

See Also
GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader

Implements

IGorgonFluentBuilderAllocator<TB, TBo, TBa>
IGorgonFluentBuilder<TB, TBo>

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)

See Also

GorgonPipelineState
GorgonDrawCall
Gorgon2DBatchState
GorgonShader
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author