Add **stencil buffer** support to GPUPipelineState

This commit is contained in:
Wojtek Figat
2023-06-19 13:46:37 +02:00
parent a6353c0bb9
commit f952a392de
5 changed files with 188 additions and 134 deletions

View File

@@ -90,96 +90,79 @@ GPUResourceType GPUPipelineState::GetResourceType() const
return GPUResourceType::PipelineState;
}
// @formatter:off
GPUPipelineState::Description GPUPipelineState::Description::Default =
{
// Enable/disable depth write
true,
// Enable/disable depth test
true,
// DepthClipEnable
true,
// DepthFunc
ComparisonFunc::Less,
// Vertex shader
nullptr,
// Hull shader
nullptr,
// Domain shader
nullptr,
// Geometry shader
nullptr,
// Pixel shader
nullptr,
// Primitives topology
PrimitiveTopologyType::Triangle,
// True if use wireframe rendering
false,
// Primitives culling mode
CullMode::Normal,
// Colors blending mode
BlendingMode::Opaque,
true, // DepthEnable
true, // DepthWriteEnable
true, // DepthClipEnable
ComparisonFunc::Less, // DepthFunc
false, // StencilEnable
0xff, // StencilReadMask
0xff, // StencilWriteMask
ComparisonFunc::Always, // StencilFunc
StencilOperation::Keep, // StencilFailOp
StencilOperation::Keep, // StencilDepthFailOp
StencilOperation::Keep, // StencilPassOp
nullptr, // VS
nullptr, // HS
nullptr, // DS
nullptr, // GS
nullptr, // PS
PrimitiveTopologyType::Triangle, // PrimitiveTopology
false, // Wireframe
CullMode::Normal, // CullMode
BlendingMode::Opaque, // BlendMode
};
GPUPipelineState::Description GPUPipelineState::Description::DefaultNoDepth =
{
// Enable/disable depth write
false,
// Enable/disable depth test
false,
// DepthClipEnable
false,
// DepthFunc
ComparisonFunc::Less,
// Vertex shader
nullptr,
// Hull shader
nullptr,
// Domain shader
nullptr,
// Geometry shader
nullptr,
// Pixel shader
nullptr,
// Primitives topology
PrimitiveTopologyType::Triangle,
// True if use wireframe rendering
false,
// Primitives culling mode
CullMode::Normal,
// Colors blending mode
BlendingMode::Opaque,
false, // DepthEnable
false, // DepthWriteEnable
false, // DepthClipEnable
ComparisonFunc::Less, // DepthFunc
false, // StencilEnable
0xff, // StencilReadMask
0xff, // StencilWriteMask
ComparisonFunc::Always, // StencilFunc
StencilOperation::Keep, // StencilFailOp
StencilOperation::Keep, // StencilDepthFailOp
StencilOperation::Keep, // StencilPassOp
nullptr, // VS
nullptr, // HS
nullptr, // DS
nullptr, // GS
nullptr, // PS
PrimitiveTopologyType::Triangle, // PrimitiveTopology
false, // Wireframe
CullMode::Normal, // CullMode
BlendingMode::Opaque, // BlendMode
};
GPUPipelineState::Description GPUPipelineState::Description::DefaultFullscreenTriangle =
{
// Enable/disable depth write
false,
// Enable/disable depth test
false,
// DepthClipEnable
false,
// DepthFunc
ComparisonFunc::Less,
// Vertex shader
nullptr,
// Set to default quad VS via GPUDevice
// Hull shader
nullptr,
// Domain shader
nullptr,
// Geometry shader
nullptr,
// Pixel shader
nullptr,
// Primitives topology
PrimitiveTopologyType::Triangle,
// True if use wireframe rendering
false,
// Primitives culling mode
CullMode::TwoSided,
// Colors blending mode
BlendingMode::Opaque,
false, // DepthEnable
false, // DepthWriteEnable
false, // DepthClipEnable
ComparisonFunc::Less, // DepthFunc
false, // StencilEnable
0xff, // StencilReadMask
0xff, // StencilWriteMask
ComparisonFunc::Always, // StencilFunc
StencilOperation::Keep, // StencilFailOp
StencilOperation::Keep, // StencilDepthFailOp
StencilOperation::Keep, // StencilPassOp
nullptr, // VS (Set to default quad VS via GPUDevice)
nullptr, // HS
nullptr, // DS
nullptr, // GS
nullptr, // PS
PrimitiveTopologyType::Triangle, // PrimitiveTopology
false, // Wireframe
CullMode::TwoSided, // CullMode
BlendingMode::Opaque, // BlendMode
};
// @formatter:on
GPUResource::GPUResource()
: ScriptingObject(SpawnParams(Guid::New(), TypeInitializer))

View File

@@ -7,6 +7,31 @@
#include "Enums.h"
#include "GPUResource.h"
/// <summary>
/// Stencil operation modes.
/// </summary>
API_ENUM() enum class StencilOperation : byte
{
// Keep the existing stencil data.
Keep,
// Set the stencil data to 0.
Zero,
// Set the stencil data to the reference value (set via GPUContext::SetStencilRef).
Replace,
// Increment the stencil value by 1, and clamp the result.
IncrementSaturated,
// Decrement the stencil value by 1, and clamp the result.
DecrementSaturated,
// Invert the stencil data.
Invert,
// Increment the stencil value by 1, and wrap the result if necessary.
Increment,
// Decrement the stencil value by 1, and wrap the result if necessary.
Decrement,
API_ENUM(Attributes="HideInEditor") MAX
};
/// <summary>
/// Describes full graphics pipeline state within single object.
/// </summary>
@@ -44,6 +69,41 @@ public:
/// </summary>
API_FIELD() ComparisonFunc DepthFunc;
/// <summary>
/// Enable/disable stencil buffer usage
/// </summary>
API_FIELD() bool StencilEnable;
/// <summary>
/// The read mask applied to the reference value and each stencil buffer entry to determine the significant bits for the stencil test.
/// </summary>
API_FIELD() uint8 StencilReadMask;
/// <summary>
/// The write mask applied to values written into the stencil buffer.
/// </summary>
API_FIELD() uint8 StencilWriteMask;
/// <summary>
/// The comparison function for the stencil test.
/// </summary>
API_FIELD() ComparisonFunc StencilFunc;
/// <summary>
/// The stencil operation to perform when stencil testing fails.
/// </summary>
API_FIELD() StencilOperation StencilFailOp;
/// <summary>
/// The stencil operation to perform when stencil testing passes and depth testing fails.
/// </summary>
API_FIELD() StencilOperation StencilDepthFailOp;
/// <summary>
/// The stencil operation to perform when stencil testing and depth testing both pass.
/// </summary>
API_FIELD() StencilOperation StencilPassOp;
/// <summary>
/// Vertex shader program
/// </summary>