Enhance OpenGLPipelineState with comprehensive state management
- Add BlendOp enum for blend operations - Add PolygonMode enum for polygon rendering mode - Add StencilOp enum for stencil operations - Add ScissorState and LogicalOperation structs - Add DepthStencilState: stencil enable, read/write mask, stencil ref, stencil func, stencil ops - Add BlendState: blend equation, color write mask, blend factor - Add RasterizerState: polygon mode, polygon offset, depth clip, scissor test, multisample - Add ViewportState: float coordinates with min/max depth - Add Apply methods for individual state groups - Add AttachShader/DetachShader for program management - Add getter methods for state structs
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace RHI {
|
||||
@@ -30,7 +32,19 @@ enum class BlendFactor {
|
||||
ConstantColor,
|
||||
OneMinusConstantColor,
|
||||
ConstantAlpha,
|
||||
OneMinusConstantAlpha
|
||||
OneMinusConstantAlpha,
|
||||
Src1Color,
|
||||
InvSrc1Color,
|
||||
Src1Alpha,
|
||||
InvSrc1Alpha
|
||||
};
|
||||
|
||||
enum class BlendOp {
|
||||
Add,
|
||||
Subtract,
|
||||
ReverseSubtract,
|
||||
Min,
|
||||
Max
|
||||
};
|
||||
|
||||
enum class CullFace {
|
||||
@@ -44,10 +58,35 @@ enum class FrontFace {
|
||||
CounterClockwise
|
||||
};
|
||||
|
||||
enum class PolygonMode {
|
||||
Point,
|
||||
Line,
|
||||
Fill
|
||||
};
|
||||
|
||||
enum class StencilOp {
|
||||
Keep,
|
||||
Zero,
|
||||
Replace,
|
||||
Incr,
|
||||
IncrWrap,
|
||||
Decr,
|
||||
DecrWrap,
|
||||
Invert
|
||||
};
|
||||
|
||||
struct DepthStencilState {
|
||||
bool depthTestEnable = true;
|
||||
bool depthWriteEnable = true;
|
||||
ComparisonFunc depthFunc = ComparisonFunc::Less;
|
||||
bool stencilEnable = false;
|
||||
uint8_t stencilReadMask = 0xFF;
|
||||
uint8_t stencilWriteMask = 0xFF;
|
||||
int stencilRef = 0;
|
||||
ComparisonFunc stencilFunc = ComparisonFunc::Always;
|
||||
StencilOp stencilFailOp = StencilOp::Keep;
|
||||
StencilOp stencilDepthFailOp = StencilOp::Keep;
|
||||
StencilOp stencilDepthPassOp = StencilOp::Keep;
|
||||
};
|
||||
|
||||
struct BlendState {
|
||||
@@ -56,22 +95,45 @@ struct BlendState {
|
||||
BlendFactor dstBlend = BlendFactor::OneMinusSrcAlpha;
|
||||
BlendFactor srcBlendAlpha = BlendFactor::One;
|
||||
BlendFactor dstBlendAlpha = BlendFactor::Zero;
|
||||
BlendOp blendOp = BlendOp::Add;
|
||||
BlendOp blendOpAlpha = BlendOp::Add;
|
||||
uint8_t colorWriteMask = 0xF;
|
||||
float blendFactor[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
};
|
||||
|
||||
struct RasterizerState {
|
||||
bool cullFaceEnable = true;
|
||||
CullFace cullFace = CullFace::Back;
|
||||
FrontFace frontFace = FrontFace::CounterClockwise;
|
||||
bool polygonModeFill = true;
|
||||
PolygonMode polygonMode = PolygonMode::Fill;
|
||||
float polygonOffsetFactor = 0.0f;
|
||||
float polygonOffsetUnits = 0.0f;
|
||||
bool depthClipEnable = true;
|
||||
bool scissorTestEnable = false;
|
||||
bool multisampleEnable = false;
|
||||
bool sampleAlphaToCoverageEnable = false;
|
||||
};
|
||||
|
||||
struct ViewportState {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
float minDepth = 0.0f;
|
||||
float maxDepth = 1.0f;
|
||||
};
|
||||
|
||||
struct ScissorState {
|
||||
bool enable = false;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
float minDepth = 0.0f;
|
||||
float maxDepth = 1.0f;
|
||||
};
|
||||
|
||||
struct LogicalOperation {
|
||||
bool enable = false;
|
||||
uint32_t operation = 0;
|
||||
};
|
||||
|
||||
class OpenGLPipelineState {
|
||||
@@ -83,17 +145,37 @@ public:
|
||||
void SetBlendState(const BlendState& state);
|
||||
void SetRasterizerState(const RasterizerState& state);
|
||||
void SetViewport(const ViewportState& state);
|
||||
void SetScissor(const ScissorState& state);
|
||||
void SetLogicalOperation(const LogicalOperation& state);
|
||||
|
||||
void Apply();
|
||||
void ApplyDepthStencil();
|
||||
void ApplyBlend();
|
||||
void ApplyRasterizer();
|
||||
void ApplyViewport();
|
||||
void ApplyScissor();
|
||||
|
||||
void SetClearColor(float r, float g, float b, float a);
|
||||
void Clear(unsigned int buffers);
|
||||
|
||||
void AttachShader(unsigned int program);
|
||||
void DetachShader();
|
||||
|
||||
const DepthStencilState& GetDepthStencilState() const { return m_depthStencilState; }
|
||||
const BlendState& GetBlendState() const { return m_blendState; }
|
||||
const RasterizerState& GetRasterizerState() const { return m_rasterizerState; }
|
||||
const ViewportState& GetViewportState() const { return m_viewportState; }
|
||||
|
||||
private:
|
||||
DepthStencilState m_depthStencilState;
|
||||
BlendState m_blendState;
|
||||
RasterizerState m_rasterizerState;
|
||||
ViewportState m_viewportState;
|
||||
ScissorState m_scissorState;
|
||||
LogicalOperation m_logicalOperation;
|
||||
float m_clearColor[4];
|
||||
unsigned int m_program;
|
||||
bool m_programAttached;
|
||||
};
|
||||
|
||||
} // namespace RHI
|
||||
|
||||
Reference in New Issue
Block a user