refactor: Refactor OpenGL backend to use OpenGLEnums
Use centralized OpenGLEnums.h for enum conversion: - Remove local ToGL* functions from OpenGLCommandList - Replace with ToOpenGL() and ToOpenGLClearBuffer() from OpenGLEnums - Simplify OpenGLTexture, OpenGLBuffer, OpenGLSampler, etc.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLPipelineState.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLShader.h"
|
||||
#include "XCEngine/RHI/OpenGL/OpenGLEnums.h"
|
||||
#include <glad/glad.h>
|
||||
|
||||
namespace XCEngine {
|
||||
@@ -86,20 +87,20 @@ void OpenGLPipelineState::ApplyDepthStencil() {
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
}
|
||||
glDepthMask(m_glDepthStencilState.depthWriteEnable ? GL_TRUE : GL_FALSE);
|
||||
glDepthFunc(static_cast<GLenum>(m_glDepthStencilState.depthFunc));
|
||||
glDepthFunc(ToOpenGL(m_glDepthStencilState.depthFunc));
|
||||
|
||||
if (m_glDepthStencilState.stencilEnable) {
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glStencilMask(m_glDepthStencilState.stencilWriteMask);
|
||||
glStencilFunc(
|
||||
static_cast<GLenum>(m_glDepthStencilState.stencilFunc),
|
||||
ToOpenGL(m_glDepthStencilState.stencilFunc),
|
||||
m_glDepthStencilState.stencilRef,
|
||||
m_glDepthStencilState.stencilReadMask
|
||||
);
|
||||
glStencilOp(
|
||||
static_cast<GLenum>(m_glDepthStencilState.stencilFailOp),
|
||||
static_cast<GLenum>(m_glDepthStencilState.stencilDepthFailOp),
|
||||
static_cast<GLenum>(m_glDepthStencilState.stencilDepthPassOp)
|
||||
ToOpenGL(m_glDepthStencilState.stencilFailOp),
|
||||
ToOpenGL(m_glDepthStencilState.stencilDepthFailOp),
|
||||
ToOpenGL(m_glDepthStencilState.stencilDepthPassOp)
|
||||
);
|
||||
} else {
|
||||
glDisable(GL_STENCIL_TEST);
|
||||
@@ -110,14 +111,14 @@ void OpenGLPipelineState::ApplyBlend() {
|
||||
if (m_glBlendState.blendEnable) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFuncSeparate(
|
||||
static_cast<GLenum>(m_glBlendState.srcBlend),
|
||||
static_cast<GLenum>(m_glBlendState.dstBlend),
|
||||
static_cast<GLenum>(m_glBlendState.srcBlendAlpha),
|
||||
static_cast<GLenum>(m_glBlendState.dstBlendAlpha)
|
||||
ToOpenGL(m_glBlendState.srcBlend),
|
||||
ToOpenGL(m_glBlendState.dstBlend),
|
||||
ToOpenGL(m_glBlendState.srcBlendAlpha),
|
||||
ToOpenGL(m_glBlendState.dstBlendAlpha)
|
||||
);
|
||||
glBlendEquationSeparate(
|
||||
static_cast<GLenum>(m_glBlendState.blendOp),
|
||||
static_cast<GLenum>(m_glBlendState.blendOpAlpha)
|
||||
ToOpenGL(m_glBlendState.blendOp),
|
||||
ToOpenGL(m_glBlendState.blendOpAlpha)
|
||||
);
|
||||
glColorMask(
|
||||
(m_glBlendState.colorWriteMask & 1) != 0,
|
||||
@@ -133,13 +134,13 @@ void OpenGLPipelineState::ApplyBlend() {
|
||||
void OpenGLPipelineState::ApplyRasterizer() {
|
||||
if (m_glRasterizerState.cullFaceEnable) {
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(static_cast<GLenum>(m_glRasterizerState.cullFace));
|
||||
glFrontFace(static_cast<GLenum>(m_glRasterizerState.frontFace));
|
||||
glCullFace(ToOpenGL(m_glRasterizerState.cullFace));
|
||||
glFrontFace(ToOpenGL(m_glRasterizerState.frontFace));
|
||||
} else {
|
||||
glDisable(GL_CULL_FACE);
|
||||
}
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, static_cast<GLenum>(m_glRasterizerState.polygonMode));
|
||||
glPolygonMode(GL_FRONT_AND_BACK, ToOpenGL(m_glRasterizerState.polygonMode));
|
||||
|
||||
if (m_glRasterizerState.multisampleEnable) {
|
||||
glEnable(GL_MULTISAMPLE);
|
||||
@@ -197,11 +198,7 @@ void OpenGLPipelineState::SetClearColor(float r, float g, float b, float a) {
|
||||
}
|
||||
|
||||
void OpenGLPipelineState::Clear(unsigned int buffers) {
|
||||
unsigned int glBuffers = 0;
|
||||
if (buffers & 1) glBuffers |= GL_COLOR_BUFFER_BIT;
|
||||
if (buffers & 2) glBuffers |= GL_DEPTH_BUFFER_BIT;
|
||||
if (buffers & 4) glBuffers |= GL_STENCIL_BUFFER_BIT;
|
||||
glClear(glBuffers);
|
||||
glClear(ToOpenGLClearBuffer(buffers));
|
||||
}
|
||||
|
||||
void OpenGLPipelineState::AttachShader(unsigned int program) {
|
||||
@@ -229,4 +226,4 @@ const OpenGLRasterizerState& OpenGLPipelineState::GetOpenGLRasterizerState() con
|
||||
}
|
||||
|
||||
} // namespace RHI
|
||||
} // namespace XCEngine
|
||||
} // namespace XCEngine
|
||||
|
||||
Reference in New Issue
Block a user