在 Win32 API 中,CD3D11_DEPTH_STENCIL_DESC 是由 DirectX Tool Kit 提供的辅助结构,用于简化 Direct3D 11 中 D3D11_DEPTH_STENCIL_DESC 结构的使用。这个结构位于 D3d11.h 头文件中。

以下是 CD3D11_DEPTH_STENCIL_DESC 的定义:
struct CD3D11_DEPTH_STENCIL_DESC : public D3D11_DEPTH_STENCIL_DESC
{
    CD3D11_DEPTH_STENCIL_DESC() noexcept {}
    explicit CD3D11_DEPTH_STENCIL_DESC(
        BOOL depthEnable,
        D3D11_DEPTH_WRITE_MASK depthWriteMask,
        D3D11_COMPARISON_FUNC depthFunc,
        BOOL stencilEnable,
        UINT8 stencilReadMask,
        UINT8 stencilWriteMask,
        const D3D11_DEPTH_STENCILOP_DESC& frontFace,
        const D3D11_DEPTH_STENCILOP_DESC& backFace
        ) noexcept
    {
        DepthEnable = depthEnable;
        DepthWriteMask = depthWriteMask;
        DepthFunc = depthFunc;
        StencilEnable = stencilEnable;
        StencilReadMask = stencilReadMask;
        StencilWriteMask = stencilWriteMask;
        FrontFace = frontFace;
        BackFace = backFace;
    }
    explicit CD3D11_DEPTH_STENCIL_DESC(
        const D3D11_DEPTH_STENCIL_DESC& o
        ) noexcept : D3D11_DEPTH_STENCIL_DESC(o) {}
};

CD3D11_DEPTH_STENCIL_DESC 通过构造函数提供了一些便捷的初始化方法,使得创建深度模板状态描述更加直观和简便。这个结构通常用于描述深度测试和模板测试的设置。

以下是一个使用 CD3D11_DEPTH_STENCIL_DESC 的示例:
CD3D11_DEPTH_STENCIL_DESC depthStencilDesc(
    TRUE,                               // DepthEnable
    D3D11_DEPTH_WRITE_MASK_ALL,        // DepthWriteMask
    D3D11_COMPARISON_LESS,             // DepthFunc
    TRUE,                               // StencilEnable
    0xFF,                               // StencilReadMask
    0xFF,                               // StencilWriteMask
    D3D11_DEPTH_STENCILOP_DESC(
        D3D11_STENCIL_OP_KEEP,          // StencilFailOp
        D3D11_STENCIL_OP_KEEP,          // StencilDepthFailOp
        D3D11_STENCIL_OP_REPLACE,       // StencilPassOp
        D3D11_COMPARISON_ALWAYS         // StencilFunc
    ),
    D3D11_DEPTH_STENCILOP_DESC(
        D3D11_STENCIL_OP_KEEP,          // StencilFailOp
        D3D11_STENCIL_OP_KEEP,          // StencilDepthFailOp
        D3D11_STENCIL_OP_REPLACE,       // StencilPassOp
        D3D11_COMPARISON_ALWAYS         // StencilFunc
    )
);

这个示例创建了一个 CD3D11_DEPTH_STENCIL_DESC 结构,表示一个启用深度测试和模板测试的深度模板状态。这个结构可以用于创建深度模板状态对象,例如使用 ID3D11Device::CreateDepthStencilState 函数。


转载请注明出处:http://www.zyzy.cn/article/detail/25637/Win32 API/D3d11.h/CD3D11_DEPTH_STENCIL_DESC