CD3D11_BLEND_DESC 是 D3D11_BLEND_DESC 结构的一个封装,用于更方便地设置混合状态。以下是该结构的定义:
struct CD3D11_BLEND_DESC : public D3D11_BLEND_DESC
{
CD3D11_BLEND_DESC() noexcept {}
explicit CD3D11_BLEND_DESC(const D3D11_BLEND_DESC& o) noexcept : D3D11_BLEND_DESC(o) {}
explicit CD3D11_BLEND_DESC(CD3D11_DEFAULT) noexcept { CD3D11_BLEND_DESC temp{}; *this = temp; }
explicit CD3D11_BLEND_DESC(
BOOL alphaToCoverageEnable,
BOOL independentBlendEnable = FALSE
) noexcept
{
AlphaToCoverageEnable = alphaToCoverageEnable;
IndependentBlendEnable = independentBlendEnable;
for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
RenderTarget[i] = D3D11_RENDER_TARGET_BLEND_DESC(CD3D11_DEFAULT());
}
explicit CD3D11_BLEND_DESC(
const D3D11_RENDER_TARGET_BLEND_DESC& renderTarget0,
BOOL independentBlendEnable = FALSE
) noexcept
{
AlphaToCoverageEnable = FALSE;
IndependentBlendEnable = independentBlendEnable;
for (UINT i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
{
if (i == 0)
RenderTarget[i] = renderTarget0;
else
RenderTarget[i] = D3D11_RENDER_TARGET_BLEND_DESC(CD3D11_DEFAULT());
}
}
};
这个结构通过成员函数和构造函数提供了一些便捷的初始化方法,使得设置混合状态更加直观和简便。例如,你可以使用 CD3D11_BLEND_DESC 的构造函数来设置 alpha-to-coverage 开启或关闭,独立混合开启或关闭,以及每个渲染目标的混合设置。
这里是一个使用 CD3D11_BLEND_DESC 的示例:
CD3D11_BLEND_DESC blendDesc(D3D11_DEFAULT);
blendDesc.RenderTarget[0].BlendEnable = TRUE;
blendDesc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA;
blendDesc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
blendDesc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
blendDesc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
这个示例使用 CD3D11_BLEND_DESC 设置了一种常见的混合状态,即将源颜色乘以 alpha,然后与目标颜色相加。
转载请注明出处:http://www.pingtaimeng.com/article/detail/25633/Win32 API/D3d11.h/CD3D11_BLEND_DESC