GraphicsAdapter.CheckDepthStencilMatch Method

Tests whether a depth stencil format is compatible with a render target format in a particular display mode.

Namespace: Microsoft.Xna.Framework.Graphics
Assembly: Microsoft.Xna.Framework (in microsoft.xna.framework.dll)

public bool CheckDepthStencilMatch (
         DeviceType deviceType,
         SurfaceFormat adapterFormat,
         SurfaceFormat renderTargetFormat,
         DepthFormat depthStencilFormat
)

Parameters

deviceType
The device type.
adapterFormat
The format of the display mode into which the adapter will be placed.
renderTargetFormat
The format of the render-target surface to be tested.
depthStencilFormat
The format of the depth stencil surface to be tested.

Return Value

true if the format is compatible; false otherwise.

Exception typeCondition
DeviceNotSupportedException(Xbox 360) Hardware is the only device type supported on this platform.
InvalidOperationExceptionAn error has occurred.

CheckDepthStencilMatch enables applications to work with hardware that requires that certain depth formats work only with certain render target formats.

public static DepthStencilBuffer CreateDepthStencil(RenderTarget2D target)
{
    return new DepthStencilBuffer(target.GraphicsDevice, target.Width,
        target.Height, target.GraphicsDevice.DepthStencilBuffer.Format,
        target.MultiSampleType, target.MultiSampleQuality);
}
public static DepthStencilBuffer CreateDepthStencil(RenderTarget2D target, DepthFormat depth)
{
    if (GraphicsAdapter.DefaultAdapter.CheckDepthStencilMatch(DeviceType.Hardware,
       GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Format, target.Format,
        depth))
    {
        return new DepthStencilBuffer(target.GraphicsDevice, target.Width,
            target.Height, depth, target.MultiSampleType, target.MultiSampleQuality);
    }
    else
        return CreateDepthStencil(target);
}

Xbox 360, Windows XP SP2, Windows Vista

Community Additions

ADD
Show: