2026-03-16 18:25:58 +08:00
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h"
|
2026-03-25 01:05:03 +08:00
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLShader.h"
|
2026-03-25 19:01:36 +08:00
|
|
|
#include "XCEngine/RHI/OpenGL/OpenGLEnums.h"
|
2026-03-16 18:25:58 +08:00
|
|
|
#include <glad/glad.h>
|
|
|
|
|
|
|
|
|
|
namespace XCEngine {
|
|
|
|
|
namespace RHI {
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
OpenGLPipelineState::OpenGLPipelineState()
|
|
|
|
|
: m_program(0), m_programAttached(false) {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
OpenGLPipelineState::~OpenGLPipelineState() {
|
2026-03-16 18:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetInputLayout(const InputLayoutDesc& layout) {
|
|
|
|
|
m_inputLayoutDesc = layout;
|
2026-03-16 18:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetRasterizerState(const RasterizerDesc& state) {
|
|
|
|
|
m_rasterizerDesc = state;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetBlendState(const BlendDesc& state) {
|
|
|
|
|
m_blendDesc = state;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetDepthStencilState(const DepthStencilStateDesc& state) {
|
|
|
|
|
m_depthStencilDesc = state;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetTopology(uint32_t topologyType) {
|
|
|
|
|
m_topologyType = topologyType;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetRenderTargetFormats(uint32_t count, const uint32_t* formats, uint32_t depthFormat) {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetSampleCount(uint32_t count) {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-25 01:05:03 +08:00
|
|
|
void OpenGLPipelineState::SetComputeShader(RHIShader* shader) {
|
|
|
|
|
m_computeShader = shader;
|
|
|
|
|
if (shader) {
|
|
|
|
|
OpenGLShader* glShader = static_cast<OpenGLShader*>(shader);
|
|
|
|
|
m_computeProgram = glShader->GetID();
|
|
|
|
|
} else {
|
|
|
|
|
m_computeProgram = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
PipelineStateHash OpenGLPipelineState::GetHash() const {
|
|
|
|
|
PipelineStateHash hash = {};
|
|
|
|
|
return hash;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::Shutdown() {
|
|
|
|
|
m_program = 0;
|
2026-03-25 01:05:03 +08:00
|
|
|
m_computeProgram = 0;
|
|
|
|
|
m_computeShader = nullptr;
|
2026-03-24 18:33:16 +08:00
|
|
|
m_programAttached = false;
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::Bind() {
|
2026-03-25 01:05:03 +08:00
|
|
|
if (HasComputeShader()) {
|
|
|
|
|
glUseProgram(m_computeProgram);
|
|
|
|
|
} else if (m_programAttached) {
|
2026-03-24 18:33:16 +08:00
|
|
|
glUseProgram(m_program);
|
|
|
|
|
}
|
|
|
|
|
Apply();
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::Unbind() {
|
|
|
|
|
glUseProgram(0);
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 18:25:58 +08:00
|
|
|
void OpenGLPipelineState::Apply() {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
ApplyDepthStencil();
|
|
|
|
|
ApplyBlend();
|
|
|
|
|
ApplyRasterizer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::ApplyDepthStencil() {
|
2026-03-24 18:33:16 +08:00
|
|
|
if (m_glDepthStencilState.depthTestEnable) {
|
2026-03-16 18:25:58 +08:00
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
|
}
|
2026-03-24 18:33:16 +08:00
|
|
|
glDepthMask(m_glDepthStencilState.depthWriteEnable ? GL_TRUE : GL_FALSE);
|
2026-03-25 19:01:36 +08:00
|
|
|
glDepthFunc(ToOpenGL(m_glDepthStencilState.depthFunc));
|
2026-03-16 18:25:58 +08:00
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
if (m_glDepthStencilState.stencilEnable) {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
glEnable(GL_STENCIL_TEST);
|
2026-03-24 18:33:16 +08:00
|
|
|
glStencilMask(m_glDepthStencilState.stencilWriteMask);
|
|
|
|
|
glStencilFunc(
|
2026-03-25 19:01:36 +08:00
|
|
|
ToOpenGL(m_glDepthStencilState.stencilFunc),
|
2026-03-24 18:33:16 +08:00
|
|
|
m_glDepthStencilState.stencilRef,
|
|
|
|
|
m_glDepthStencilState.stencilReadMask
|
|
|
|
|
);
|
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
2026-03-17 02:15:48 +08:00
|
|
|
glStencilOp(
|
2026-03-25 19:01:36 +08:00
|
|
|
ToOpenGL(m_glDepthStencilState.stencilFailOp),
|
|
|
|
|
ToOpenGL(m_glDepthStencilState.stencilDepthFailOp),
|
|
|
|
|
ToOpenGL(m_glDepthStencilState.stencilDepthPassOp)
|
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
2026-03-17 02:15:48 +08:00
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::ApplyBlend() {
|
2026-03-24 18:33:16 +08:00
|
|
|
if (m_glBlendState.blendEnable) {
|
2026-03-16 18:25:58 +08:00
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
glBlendFuncSeparate(
|
2026-03-25 19:01:36 +08:00
|
|
|
ToOpenGL(m_glBlendState.srcBlend),
|
|
|
|
|
ToOpenGL(m_glBlendState.dstBlend),
|
|
|
|
|
ToOpenGL(m_glBlendState.srcBlendAlpha),
|
|
|
|
|
ToOpenGL(m_glBlendState.dstBlendAlpha)
|
2026-03-16 18:25:58 +08:00
|
|
|
);
|
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
2026-03-17 02:15:48 +08:00
|
|
|
glBlendEquationSeparate(
|
2026-03-25 19:01:36 +08:00
|
|
|
ToOpenGL(m_glBlendState.blendOp),
|
|
|
|
|
ToOpenGL(m_glBlendState.blendOpAlpha)
|
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
2026-03-17 02:15:48 +08:00
|
|
|
);
|
|
|
|
|
glColorMask(
|
2026-03-24 18:33:16 +08:00
|
|
|
(m_glBlendState.colorWriteMask & 1) != 0,
|
|
|
|
|
(m_glBlendState.colorWriteMask & 2) != 0,
|
|
|
|
|
(m_glBlendState.colorWriteMask & 4) != 0,
|
|
|
|
|
(m_glBlendState.colorWriteMask & 8) != 0
|
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
2026-03-17 02:15:48 +08:00
|
|
|
);
|
2026-03-16 18:25:58 +08:00
|
|
|
} else {
|
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
|
}
|
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
2026-03-17 02:15:48 +08:00
|
|
|
}
|
2026-03-16 18:25:58 +08:00
|
|
|
|
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
2026-03-17 02:15:48 +08:00
|
|
|
void OpenGLPipelineState::ApplyRasterizer() {
|
2026-03-24 18:33:16 +08:00
|
|
|
if (m_glRasterizerState.cullFaceEnable) {
|
2026-03-16 18:25:58 +08:00
|
|
|
glEnable(GL_CULL_FACE);
|
2026-03-25 19:01:36 +08:00
|
|
|
glCullFace(ToOpenGL(m_glRasterizerState.cullFace));
|
|
|
|
|
glFrontFace(ToOpenGL(m_glRasterizerState.frontFace));
|
2026-03-16 18:25:58 +08:00
|
|
|
} else {
|
|
|
|
|
glDisable(GL_CULL_FACE);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-25 19:01:36 +08:00
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, ToOpenGL(m_glRasterizerState.polygonMode));
|
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
2026-03-17 02:15:48 +08:00
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
if (m_glRasterizerState.multisampleEnable) {
|
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
2026-03-17 02:15:48 +08:00
|
|
|
glEnable(GL_MULTISAMPLE);
|
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_MULTISAMPLE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::ApplyViewport() {
|
|
|
|
|
glViewport((GLint)m_viewportState.x, (GLint)m_viewportState.y,
|
|
|
|
|
(GLsizei)m_viewportState.width, (GLsizei)m_viewportState.height);
|
2026-03-16 18:25:58 +08:00
|
|
|
glDepthRange(m_viewportState.minDepth, m_viewportState.maxDepth);
|
|
|
|
|
}
|
|
|
|
|
|
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
2026-03-17 02:15:48 +08:00
|
|
|
void OpenGLPipelineState::ApplyScissor() {
|
|
|
|
|
if (m_scissorState.enable) {
|
|
|
|
|
glEnable(GL_SCISSOR_TEST);
|
|
|
|
|
glScissor(m_scissorState.x, m_scissorState.y, m_scissorState.width, m_scissorState.height);
|
|
|
|
|
} else {
|
|
|
|
|
glDisable(GL_SCISSOR_TEST);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
void OpenGLPipelineState::SetProgram(unsigned int program) {
|
|
|
|
|
m_program = program;
|
|
|
|
|
m_programAttached = (program != 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::SetDepthStencilState(const OpenGLDepthStencilState& state) {
|
|
|
|
|
m_glDepthStencilState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::SetBlendState(const OpenGLBlendState& state) {
|
|
|
|
|
m_glBlendState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::SetRasterizerState(const OpenGLRasterizerState& state) {
|
|
|
|
|
m_glRasterizerState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::SetViewport(const ViewportState& state) {
|
|
|
|
|
m_viewportState = state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::SetScissor(const ScissorState& state) {
|
|
|
|
|
m_scissorState = state;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-16 18:25:58 +08:00
|
|
|
void OpenGLPipelineState::SetClearColor(float r, float g, float b, float a) {
|
|
|
|
|
m_clearColor[0] = r;
|
|
|
|
|
m_clearColor[1] = g;
|
|
|
|
|
m_clearColor[2] = b;
|
|
|
|
|
m_clearColor[3] = a;
|
|
|
|
|
glClearColor(r, g, b, a);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::Clear(unsigned int buffers) {
|
2026-03-25 19:01:36 +08:00
|
|
|
glClear(ToOpenGLClearBuffer(buffers));
|
2026-03-16 18:25:58 +08:00
|
|
|
}
|
|
|
|
|
|
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
2026-03-17 02:15:48 +08:00
|
|
|
void OpenGLPipelineState::AttachShader(unsigned int program) {
|
|
|
|
|
m_program = program;
|
|
|
|
|
m_programAttached = true;
|
|
|
|
|
glUseProgram(program);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OpenGLPipelineState::DetachShader() {
|
|
|
|
|
m_program = 0;
|
|
|
|
|
m_programAttached = false;
|
|
|
|
|
glUseProgram(0);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
const OpenGLDepthStencilState& OpenGLPipelineState::GetOpenGLDepthStencilState() const {
|
|
|
|
|
return m_glDepthStencilState;
|
2026-03-17 18:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
const OpenGLBlendState& OpenGLPipelineState::GetOpenGLBlendState() const {
|
|
|
|
|
return m_glBlendState;
|
2026-03-17 18:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 18:33:16 +08:00
|
|
|
const OpenGLRasterizerState& OpenGLPipelineState::GetOpenGLRasterizerState() const {
|
|
|
|
|
return m_glRasterizerState;
|
2026-03-17 18:09:34 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-16 18:25:58 +08:00
|
|
|
} // namespace RHI
|
2026-03-25 19:01:36 +08:00
|
|
|
} // namespace XCEngine
|