feat(RHI): add rendering state abstraction to RHICommandList
- Add DepthStencilState and BlendState structs to RHICommandList - Add SetPrimitiveTopology, SetDepthStencilState, SetStencilRef, SetBlendState, SetBlendFactor virtual methods - Implement new methods in OpenGL backend with full state control - Implement stub methods in D3D12 backend (states controlled via PSO)
This commit is contained in:
@@ -158,11 +158,16 @@ public:
|
||||
void PopDebugGroup();
|
||||
|
||||
void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) override;
|
||||
void SetPrimitiveTopology(PrimitiveTopology topology) override;
|
||||
void SetViewport(const Viewport& viewport) override;
|
||||
void SetViewports(uint32_t count, const Viewport* viewports) override;
|
||||
void SetScissorRect(const Rect& rect) override;
|
||||
void SetScissorRects(uint32_t count, const Rect* rects) override;
|
||||
void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) override;
|
||||
void SetDepthStencilState(const DepthStencilState& state) override;
|
||||
void SetStencilRef(uint8_t ref) override;
|
||||
void SetBlendState(const BlendState& state) override;
|
||||
void SetBlendFactor(const float factor[4]) override;
|
||||
void ClearRenderTarget(void* renderTarget, const float color[4]) override;
|
||||
void ClearDepthStencil(void* depthStencil, float depth, uint8_t stencil) override;
|
||||
void Draw(uint32_t vertexCount, uint32_t instanceCount, uint32_t startVertex, uint32_t startInstance) override;
|
||||
|
||||
@@ -6,6 +6,40 @@
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
|
||||
struct DepthStencilState {
|
||||
bool depthEnable = true;
|
||||
bool depthWriteMask = true;
|
||||
ComparisonFunc depthFunc = ComparisonFunc::Less;
|
||||
bool stencilEnable = false;
|
||||
uint8_t stencilReadMask = 0xFF;
|
||||
uint8_t stencilWriteMask = 0xFF;
|
||||
struct StencilOpDesc {
|
||||
StencilOp stencilFailOp = StencilOp::Keep;
|
||||
StencilOp stencilDepthFailOp = StencilOp::Keep;
|
||||
StencilOp stencilPassOp = StencilOp::Keep;
|
||||
ComparisonFunc stencilFunc = ComparisonFunc::Always;
|
||||
};
|
||||
StencilOpDesc frontFace;
|
||||
StencilOpDesc backFace;
|
||||
};
|
||||
|
||||
struct BlendState {
|
||||
bool alphaToCoverageEnable = false;
|
||||
bool independentBlendEnable = false;
|
||||
struct RenderTarget {
|
||||
bool blendEnable = false;
|
||||
BlendFactor srcBlend = BlendFactor::One;
|
||||
BlendFactor dstBlend = BlendFactor::Zero;
|
||||
BlendOp blendOp = BlendOp::Add;
|
||||
BlendFactor srcBlendAlpha = BlendFactor::One;
|
||||
BlendFactor dstBlendAlpha = BlendFactor::Zero;
|
||||
BlendOp blendOpAlpha = BlendOp::Add;
|
||||
uint8_t renderTargetWriteMask = 0xF;
|
||||
};
|
||||
RenderTarget renderTargets[8];
|
||||
float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
|
||||
};
|
||||
|
||||
class RHICommandList {
|
||||
public:
|
||||
virtual ~RHICommandList() = default;
|
||||
@@ -18,12 +52,18 @@ public:
|
||||
virtual void TransitionBarrier(void* resource, ResourceStates stateBefore, ResourceStates stateAfter) = 0;
|
||||
|
||||
virtual void SetPipelineState(void* pso) = 0;
|
||||
virtual void SetPrimitiveTopology(PrimitiveTopology topology) = 0;
|
||||
virtual void SetViewport(const Viewport& viewport) = 0;
|
||||
virtual void SetViewports(uint32_t count, const Viewport* viewports) = 0;
|
||||
virtual void SetScissorRect(const Rect& rect) = 0;
|
||||
virtual void SetScissorRects(uint32_t count, const Rect* rects) = 0;
|
||||
virtual void SetRenderTargets(uint32_t count, void** renderTargets, void* depthStencil = nullptr) = 0;
|
||||
|
||||
virtual void SetDepthStencilState(const DepthStencilState& state) = 0;
|
||||
virtual void SetStencilRef(uint8_t ref) = 0;
|
||||
virtual void SetBlendState(const BlendState& state) = 0;
|
||||
virtual void SetBlendFactor(const float factor[4]) = 0;
|
||||
|
||||
virtual void SetVertexBuffer(uint32_t slot, void* buffer, uint64_t offset, uint32_t stride) = 0;
|
||||
virtual void SetVertexBuffers(uint32_t startSlot, uint32_t count, const uint64_t* buffers, const uint64_t* offsets, const uint32_t* strides) = 0;
|
||||
virtual void SetIndexBuffer(void* buffer, uint64_t offset, Format format) = 0;
|
||||
|
||||
Reference in New Issue
Block a user