Files
XCEngine/engine/include/XCEngine/RHI/OpenGL/OpenGLPipelineState.h

101 lines
2.0 KiB
C++

#pragma once
#include <GLFW/glfw3.h>
namespace XCEngine {
namespace RHI {
enum class ComparisonFunc {
Never,
Less,
Equal,
LessEqual,
Greater,
NotEqual,
GreaterEqual,
Always
};
enum class BlendFactor {
Zero,
One,
SrcColor,
OneMinusSrcColor,
DstColor,
OneMinusDstColor,
SrcAlpha,
OneMinusSrcAlpha,
DstAlpha,
OneMinusDstAlpha,
ConstantColor,
OneMinusConstantColor,
ConstantAlpha,
OneMinusConstantAlpha
};
enum class CullFace {
Front,
Back,
FrontAndBack
};
enum class FrontFace {
Clockwise,
CounterClockwise
};
struct DepthStencilState {
bool depthTestEnable = true;
bool depthWriteEnable = true;
ComparisonFunc depthFunc = ComparisonFunc::Less;
};
struct BlendState {
bool blendEnable = false;
BlendFactor srcBlend = BlendFactor::SrcAlpha;
BlendFactor dstBlend = BlendFactor::OneMinusSrcAlpha;
BlendFactor srcBlendAlpha = BlendFactor::One;
BlendFactor dstBlendAlpha = BlendFactor::Zero;
};
struct RasterizerState {
bool cullFaceEnable = true;
CullFace cullFace = CullFace::Back;
FrontFace frontFace = FrontFace::CounterClockwise;
bool polygonModeFill = true;
};
struct ViewportState {
int x = 0;
int y = 0;
int width = 0;
int height = 0;
float minDepth = 0.0f;
float maxDepth = 1.0f;
};
class OpenGLPipelineState {
public:
OpenGLPipelineState();
~OpenGLPipelineState();
void SetDepthStencilState(const DepthStencilState& state);
void SetBlendState(const BlendState& state);
void SetRasterizerState(const RasterizerState& state);
void SetViewport(const ViewportState& state);
void Apply();
void SetClearColor(float r, float g, float b, float a);
void Clear(unsigned int buffers);
private:
DepthStencilState m_depthStencilState;
BlendState m_blendState;
RasterizerState m_rasterizerState;
ViewportState m_viewportState;
float m_clearColor[4];
};
} // namespace RHI
} // namespace XCEngine