Table of Contents

Class DepthStencilState

Namespace
Microsoft.Xna.Framework.Graphics
Assembly
MonoGame.Framework.dll

Contains depth-stencil state for the device.

public class DepthStencilState : GraphicsResource, IDisposable
Inheritance
DepthStencilState
Implements
Inherited Members

Constructors

DepthStencilState()

Creates a new instance of the DepthStencilState class with default values.

public DepthStencilState()

Fields

Default

A built-in state object with default settings for using a depth stencil buffer.

public static readonly DepthStencilState Default

Field Value

DepthStencilState

Remarks

This built-in state object has the following settings:

DepthBufferEnable = true,
DepthBufferWriteEnable = true

DepthRead

A built-int state object with settings for enabling a read-only depth stencil buffer.

public static readonly DepthStencilState DepthRead

Field Value

DepthStencilState

Remarks

This built-in state object has the following settings:

DepthBufferEnable = true,
DepthBufferWriteEnable = false

None

A built in state object with settings for not using a depth stencil buffer.

public static readonly DepthStencilState None

Field Value

DepthStencilState

Remarks

This built-int state object has the following settings:

DepthBufferEnable = false,
DepthBufferWriteEnable = false

Properties

CounterClockwiseStencilDepthBufferFail

Gets or Sets the stencil operation to perform if the stencil test passes and the depth-buffer test fails for a counterclockwise triangle. The default value is StencilOperation.Keep.

public StencilOperation CounterClockwiseStencilDepthBufferFail { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

CounterClockwiseStencilFail

Gets or Sets the stencil operation to perform if the stencil test fails for the counterclockwise triangle. The default value is StencilOperation.Keep.

public StencilOperation CounterClockwiseStencilFail { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

CounterClockwiseStencilFunction

Gets or Sets the comparison function to use for counterclockwise stencil tests. The default value is CompareFunction.Always

public CompareFunction CounterClockwiseStencilFunction { get; set; }

Property Value

CompareFunction

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

CounterClockwiseStencilPass

Gets or Sets the stencil operation to perform if the stencil and depth-tests pass for a counterclockwise triangle. The default value is StencilOperation.Keep.

public StencilOperation CounterClockwiseStencilPass { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

DepthBufferEnable

Gets or Sets a value that indicates if depth buffering is enabled. The default value is true.

public bool DepthBufferEnable { get; set; }

Property Value

bool

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

DepthBufferFunction

Gets or Sets the comparison function for the depth-buffer test. The default value is CompareFunction.LessEqual.

public CompareFunction DepthBufferFunction { get; set; }

Property Value

CompareFunction

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

DepthBufferWriteEnable

Gets or Sets a value that indicates if writing to the depth buffer is enabled. The default value is true.

public bool DepthBufferWriteEnable { get; set; }

Property Value

bool

Remarks

This property enables an application to prevent the system from updating the depth buffer with new values.

if false, depth comparisons are still made according to the render state DepthBufferFunction, assuming that depth buffering is taking place, but depth values are not written to the buffer.

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

ReferenceStencil

Gets or Sets a reference value to use for the stencil test. The default is 0.

public int ReferenceStencil { get; set; }

Property Value

int

Remarks

The reference value is compared, by the comparison function specified by the StencilFunction property, to the stencil buffer entry of a pixel. This can be illustrated by a simple equation:

ReferenceStencil StencilFunction (stencil buffer entry)

This comparison applies only to the bits in the reference value and stencil buffer entry that are set in the stencil mask by this property. If the comparison is true, the stencil test passes and the pass operation (specified by the StencilPass property) is performed.

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilDepthBufferFail

Gets or Sets the stencil operation to perform if the stencil test passes and the depth-test fails. The default is StencilOperation.Keep.

public StencilOperation StencilDepthBufferFail { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilEnable

Gets or Sets a value that indicates whether stenciling is enabled. The default is false.

public bool StencilEnable { get; set; }

Property Value

bool

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilFail

Gets or Sets the stencil operation to perform if the stencil test fails. The default is StencilOperation.Keep.

public StencilOperation StencilFail { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilFunction

Gets or Sets the comparison function for the stencil test. The default is CompareFunction.Always.

public CompareFunction StencilFunction { get; set; }

Property Value

CompareFunction

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilMask

Gets or Sets the mask applied to the reference value and each stencil buffer entry to determine the significant bits for the stencil test. The default mask is Int32.MaxValue.

public int StencilMask { get; set; }

Property Value

int

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilPass

Gets or Sets the stencil operation to perform if the stencil test passes. The default value is StencilOperation.Keep.

public StencilOperation StencilPass { get; set; }

Property Value

StencilOperation

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

StencilWriteMask

Gets or Sets the write mask applied to values written into the stencil buffer. The default mask is Int32.MaxValue.

public int StencilWriteMask { get; set; }

Property Value

int

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

TwoSidedStencilMode

Gets or Sets a value that indicates whether two-sided stenciling is enabled. The default value is false.

public bool TwoSidedStencilMode { get; set; }

Property Value

bool

Exceptions

InvalidOperationException

When setting this value for one of the default DepthStencilState instances; Default, DepthRead, or None.

-or-

When setting this value after this DepthStencilState has already been bound to the graphics device.

Methods

Dispose(bool)

The method that derived classes should override to implement disposing of managed and native resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

True if managed objects should be disposed.

Remarks

Native resources should always be released regardless of the value of the disposing parameter.