Table of Contents

Struct DepthStencilStateDescription

Namespace
Stride.Graphics
Assembly
Stride.Graphics.dll

A description of a Depth-Stencil State, which defines how depth and stencil testing are performed during rasterization.

[DataContract]
public struct DepthStencilStateDescription : IEquatable<DepthStencilStateDescription>
Implements
Inherited Members
Extension Methods

Remarks

This structure controls whether depth and stencil tests are enabled, how they are configured, and how they affect pixel visibility.
It allows fine-grained control over depth comparisons, stencil operations, and write masks, enabling advanced rendering techniques such as shadow volumes, outlines, and complex masking.

Constructors

DepthStencilStateDescription()

Initializes a new instance of the DepthStencilStateDescription structure with default values.

public DepthStencilStateDescription()

Remarks

The default values are:
  <ul><li>Enables depth testing and depth writing.</li><li>Uses the depth comparison function <xref href="Stride.Graphics.CompareFunction.LessEqual" data-throw-if-not-resolved="false"></xref>.</li><li>Disables stencil testing.</li><li>Sets the stencil bitmasks to <xref href="System.Byte.MaxValue" data-throw-if-not-resolved="false"></xref> (all birs set to 1).</li><li>
      The stencil operations and comparison functions for both front-facing and back-facing pixels are set to
      <xref href="Stride.Graphics.CompareFunction.Always" data-throw-if-not-resolved="false"></xref> (they always succeed) and <xref href="Stride.Graphics.StencilOperation.Keep" data-throw-if-not-resolved="false"></xref>
      (the value in the stencil buffer is not modified).</li></ul>
</remarks>

DepthStencilStateDescription(bool, bool)

Initializes a new instance of the DepthStencilStateDescription structure with default values.

public DepthStencilStateDescription(bool depthEnable, bool depthWriteEnable)

Parameters

depthEnable bool

A value indicating whether to enable Depth testing.

depthWriteEnable bool

A value indicating whether to enable writing to the Depth-Stencil Buffer.

Remarks

The default values are:
  <ul><li>Enables depth testing and depth writing.</li><li>Uses the depth comparison function <xref href="Stride.Graphics.CompareFunction.LessEqual" data-throw-if-not-resolved="false"></xref>.</li><li>Disables stencil testing.</li><li>Sets the stencil bitmasks to <xref href="System.Byte.MaxValue" data-throw-if-not-resolved="false"></xref> (all birs set to 1).</li><li>
      The stencil operations and comparison functions for both front-facing and back-facing pixels are set to
      <xref href="Stride.Graphics.CompareFunction.Always" data-throw-if-not-resolved="false"></xref> (they always succeed) and <xref href="Stride.Graphics.StencilOperation.Keep" data-throw-if-not-resolved="false"></xref>
      (the value in the stencil buffer is not modified).</li></ul>
</remarks>

Fields

BackFace

Describes stencil operations and comparison function for back-facing polygons.

public DepthStencilStencilOpDescription BackFace

Field Value

DepthStencilStencilOpDescription

Remarks

Typically used in conjunction with FrontFace to implement two-sided stencil operations, such as shadow volume rendering or complex masking.

Default

A Depth-Stencil State description with default values.

public static readonly DepthStencilStateDescription Default

Field Value

DepthStencilStateDescription

Remarks

The default values are:

  • Enables depth testing and depth writing.
  • Uses the depth comparison function LessEqual.
  • Disables stencil testing.
  • Sets the stencil bitmasks to MaxValue (all birs set to 1).
  • The stencil operations and comparison functions for both front-facing and back-facing pixels are set to Always (they always succeed) and Keep (the value in the stencil buffer is not modified).

DefaultDepthBufferEnable

The default value for DepthBufferEnable.

public const bool DefaultDepthBufferEnable = true

Field Value

bool

DefaultDepthBufferFunction

The default value for DepthBufferFunction.

public const CompareFunction DefaultDepthBufferFunction = LessEqual

Field Value

CompareFunction

DefaultDepthBufferWriteEnable

The default value for DepthBufferWriteEnable.

public const bool DefaultDepthBufferWriteEnable = true

Field Value

bool

DefaultDepthStencilOp

The default value for both FrontFace and BackFace.

public static readonly DepthStencilStencilOpDescription DefaultDepthStencilOp

Field Value

DepthStencilStencilOpDescription

DefaultStencilEnable

The default value for StencilEnable.

public const bool DefaultStencilEnable = false

Field Value

bool

DefaultStencilMask

The default value for StencilMask.

public const byte DefaultStencilMask = 255

Field Value

byte

DefaultStencilWriteMask

The default value for StencilWriteMask.

public const byte DefaultStencilWriteMask = 255

Field Value

byte

DepthBufferEnable

Enables or disables depth testing during rasterization.

public bool DepthBufferEnable

Field Value

bool

Remarks

When enabled, the depth test compares each pixel's depth value against the existing value in the Depth-Stencil Buffer, using the function specified by DepthBufferFunction.
If disabled, all pixels pass the depth test.

DepthBufferFunction

Specifies the comparison function used in the depth test.

public CompareFunction DepthBufferFunction

Field Value

CompareFunction

Remarks

This function determines whether a pixel should be drawn based on its depth value. For example, CompareFunction.LessEqual allows a pixel to pass if its depth is less than or equal to the current Depth-Stencil Buffer value.

DepthBufferWriteEnable

Enables or disables writing to the depth buffer.

public bool DepthBufferWriteEnable

Field Value

bool

Remarks

Disabling depth writes can be useful for rendering transparent objects or overlays that should not affect depth testing of subsequent geometry.

FrontFace

Describes stencil operations and comparison function for front-facing polygons.

public DepthStencilStencilOpDescription FrontFace

Field Value

DepthStencilStencilOpDescription

Remarks

This includes the operations to perform when the stencil test fails, when the depth test fails, and when both pass. It also defines the comparison function used for the stencil test.

StencilEnable

Enables or disables stencil testing.

public bool StencilEnable

Field Value

bool

Remarks

When enabled, the stencil test is performed for each pixel using the configured stencil operations and masks. This allows for advanced rendering techniques such as masking, outlining, and shadow volumes.

StencilMask

Bitmask applied to both the reference value and stencil buffer entry during stencil testing. Default is MaxValue.

public byte StencilMask

Field Value

byte

Remarks

This mask controls which bits are considered significant in the stencil comparison. For example, a mask of 0x0F limits the test to the lower 4 bits of the stencil value.

StencilWriteMask

Bitmask applied to values written into the stencil buffer. Default is MaxValue.

public byte StencilWriteMask

Field Value

byte

Remarks

This mask determines which bits can be modified during stencil write operations. It allows selective updating of stencil buffer bits.

Methods

Clone()

Creates a new instance of DepthStencilStateDescription with the same values as this instance.

public readonly DepthStencilStateDescription Clone()

Returns

DepthStencilStateDescription

A new Depth-Stencil State description that is a copy of this instance.

Equals(DepthStencilStateDescription)

Indicates whether the current object is equal to another object of the same type.

public readonly bool Equals(DepthStencilStateDescription other)

Parameters

other DepthStencilStateDescription

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Indicates whether this instance and a specified object are equal.

public override readonly bool Equals(object obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override readonly int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

Operators

operator ==(DepthStencilStateDescription, DepthStencilStateDescription)

public static bool operator ==(DepthStencilStateDescription left, DepthStencilStateDescription right)

Parameters

left DepthStencilStateDescription
right DepthStencilStateDescription

Returns

bool

operator !=(DepthStencilStateDescription, DepthStencilStateDescription)

public static bool operator !=(DepthStencilStateDescription left, DepthStencilStateDescription right)

Parameters

left DepthStencilStateDescription
right DepthStencilStateDescription

Returns

bool

See Also