mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-07 22:55:40 +12:00
Add UBO/BlendEquation/BlendFunc to GL state manager
This commit is contained in:
parent
219a560cbe
commit
a4ec770587
3 changed files with 67 additions and 7 deletions
|
@ -40,9 +40,13 @@ struct GLStateManager {
|
||||||
GLuint boundVAO;
|
GLuint boundVAO;
|
||||||
GLuint boundVBO;
|
GLuint boundVBO;
|
||||||
GLuint currentProgram;
|
GLuint currentProgram;
|
||||||
|
GLuint boundUBO;
|
||||||
|
|
||||||
GLenum depthFunc;
|
GLenum depthFunc;
|
||||||
GLenum logicOp;
|
GLenum logicOp;
|
||||||
|
GLenum blendEquationRGB, blendEquationAlpha;
|
||||||
|
GLenum blendFuncSourceRGB, blendFuncSourceAlpha;
|
||||||
|
GLenum blendFuncDestRGB, blendFuncDestAlpha;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void resetBlend();
|
void resetBlend();
|
||||||
|
@ -51,7 +55,7 @@ struct GLStateManager {
|
||||||
void resetColourMask();
|
void resetColourMask();
|
||||||
void resetDepth();
|
void resetDepth();
|
||||||
void resetVAO();
|
void resetVAO();
|
||||||
void resetVBO();
|
void resetBuffers();
|
||||||
void resetProgram();
|
void resetProgram();
|
||||||
void resetScissor();
|
void resetScissor();
|
||||||
void resetStencil();
|
void resetStencil();
|
||||||
|
@ -183,6 +187,13 @@ struct GLStateManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bindUBO(GLuint handle) {
|
||||||
|
if (boundUBO != handle) {
|
||||||
|
boundUBO = handle;
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, boundUBO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void bindVAO(const OpenGL::VertexArray& vao) { bindVAO(vao.handle()); }
|
void bindVAO(const OpenGL::VertexArray& vao) { bindVAO(vao.handle()); }
|
||||||
void bindVBO(const OpenGL::VertexBuffer& vbo) { bindVBO(vbo.handle()); }
|
void bindVBO(const OpenGL::VertexBuffer& vbo) { bindVBO(vbo.handle()); }
|
||||||
void useProgram(const OpenGL::Program& program) { useProgram(program.handle()); }
|
void useProgram(const OpenGL::Program& program) { useProgram(program.handle()); }
|
||||||
|
@ -224,6 +235,41 @@ struct GLStateManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setDepthFunc(OpenGL::DepthFunc func) { setDepthFunc(static_cast<GLenum>(func)); }
|
void setDepthFunc(OpenGL::DepthFunc func) { setDepthFunc(static_cast<GLenum>(func)); }
|
||||||
|
|
||||||
|
// Counterpart to glBlendEquationSeparate
|
||||||
|
void setBlendEquation(GLenum modeRGB, GLenum modeAlpha) {
|
||||||
|
if (blendEquationRGB != modeRGB || blendEquationAlpha != modeAlpha) {
|
||||||
|
blendEquationRGB = modeRGB;
|
||||||
|
blendEquationAlpha = modeAlpha;
|
||||||
|
|
||||||
|
glBlendEquationSeparate(modeRGB, modeAlpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Counterpart to glBlendFuncSeparate
|
||||||
|
void setBlendFunc(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) {
|
||||||
|
if (blendFuncSourceRGB != sourceRGB || blendFuncDestRGB != destRGB || blendFuncSourceAlpha != sourceAlpha ||
|
||||||
|
blendFuncDestAlpha != destAlpha) {
|
||||||
|
|
||||||
|
blendFuncSourceRGB = sourceRGB;
|
||||||
|
blendFuncDestRGB = destRGB;
|
||||||
|
blendFuncSourceAlpha = sourceAlpha;
|
||||||
|
blendFuncDestAlpha = destAlpha;
|
||||||
|
|
||||||
|
glBlendFuncSeparate(sourceRGB, destRGB,sourceAlpha, destAlpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Counterpart to regular glBlendEquation
|
||||||
|
void setBlendEquation(GLenum mode) { setBlendEquation(mode, mode); }
|
||||||
|
|
||||||
|
void setBlendEquation(OpenGL::BlendEquation modeRGB, OpenGL::BlendEquation modeAlpha) {
|
||||||
|
setBlendEquation(static_cast<GLenum>(modeRGB), static_cast<GLenum>(modeAlpha));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBlendEquation(OpenGL::BlendEquation mode) {
|
||||||
|
setBlendEquation(static_cast<GLenum>(mode));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert(std::is_trivially_constructible<GLStateManager>(), "OpenGL State Manager class is not trivially constructible!");
|
static_assert(std::is_trivially_constructible<GLStateManager>(), "OpenGL State Manager class is not trivially constructible!");
|
||||||
|
|
|
@ -5,9 +5,20 @@ void GLStateManager::resetBlend() {
|
||||||
logicOpEnabled = false;
|
logicOpEnabled = false;
|
||||||
logicOp = GL_COPY;
|
logicOp = GL_COPY;
|
||||||
|
|
||||||
|
blendEquationRGB = GL_FUNC_ADD;
|
||||||
|
blendEquationAlpha = GL_FUNC_ADD;
|
||||||
|
|
||||||
|
blendFuncSourceRGB = GL_SRC_COLOR;
|
||||||
|
blendFuncDestRGB = GL_DST_COLOR;
|
||||||
|
blendFuncSourceAlpha = GL_SRC_ALPHA;
|
||||||
|
blendFuncDestAlpha = GL_DST_ALPHA;
|
||||||
|
|
||||||
OpenGL::disableBlend();
|
OpenGL::disableBlend();
|
||||||
OpenGL::disableLogicOp();
|
OpenGL::disableLogicOp();
|
||||||
OpenGL::setLogicOp(GL_COPY);
|
OpenGL::setLogicOp(GL_COPY);
|
||||||
|
|
||||||
|
glBlendEquationSeparate(blendEquationRGB, blendEquationAlpha);
|
||||||
|
glBlendFuncSeparate(blendFuncSourceRGB, blendFuncDestRGB, blendFuncSourceAlpha, blendFuncDestAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLStateManager::resetClearing() {
|
void GLStateManager::resetClearing() {
|
||||||
|
@ -61,9 +72,12 @@ void GLStateManager::resetVAO() {
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLStateManager::resetVBO() {
|
void GLStateManager::resetBuffers() {
|
||||||
boundVBO = 0;
|
boundVBO = 0;
|
||||||
|
boundUBO = 0;
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLStateManager::resetProgram() {
|
void GLStateManager::resetProgram() {
|
||||||
|
@ -79,7 +93,7 @@ void GLStateManager::reset() {
|
||||||
resetDepth();
|
resetDepth();
|
||||||
|
|
||||||
resetVAO();
|
resetVAO();
|
||||||
resetVBO();
|
resetBuffers();
|
||||||
resetProgram();
|
resetProgram();
|
||||||
resetScissor();
|
resetScissor();
|
||||||
resetStencil();
|
resetStencil();
|
||||||
|
|
|
@ -229,8 +229,8 @@ void RendererGL::setupBlending() {
|
||||||
OpenGL::setBlendColor(float(r) / 255.f, float(g) / 255.f, float(b) / 255.f, float(a) / 255.f);
|
OpenGL::setBlendColor(float(r) / 255.f, float(g) / 255.f, float(b) / 255.f, float(a) / 255.f);
|
||||||
|
|
||||||
// Translate equations and funcs to their GL equivalents and set them
|
// Translate equations and funcs to their GL equivalents and set them
|
||||||
glBlendEquationSeparate(blendingEquations[rgbEquation], blendingEquations[alphaEquation]);
|
gl.setBlendEquation(blendingEquations[rgbEquation], blendingEquations[alphaEquation]);
|
||||||
glBlendFuncSeparate(blendingFuncs[rgbSourceFunc], blendingFuncs[rgbDestFunc], blendingFuncs[alphaSourceFunc], blendingFuncs[alphaDestFunc]);
|
gl.setBlendFunc(blendingFuncs[rgbSourceFunc], blendingFuncs[rgbDestFunc], blendingFuncs[alphaSourceFunc], blendingFuncs[alphaDestFunc]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,7 +821,7 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
|
|
||||||
// Allocate memory for the program UBO
|
// Allocate memory for the program UBO
|
||||||
glGenBuffers(1, &programEntry.uboBinding);
|
glGenBuffers(1, &programEntry.uboBinding);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, programEntry.uboBinding);
|
gl.bindUBO(programEntry.uboBinding);
|
||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(PICA::FragmentUniforms), nullptr, GL_DYNAMIC_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(PICA::FragmentUniforms), nullptr, GL_DYNAMIC_DRAW);
|
||||||
|
|
||||||
// Set up the binding for our UBO. Sadly we can't specify it in the shader like normal people,
|
// Set up the binding for our UBO. Sadly we can't specify it in the shader like normal people,
|
||||||
|
@ -869,7 +869,7 @@ OpenGL::Program& RendererGL::getSpecializedShader() {
|
||||||
vec[3] = float((color >> 24) & 0xFF) / 255.0f;
|
vec[3] = float((color >> 24) & 0xFF) / 255.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, programEntry.uboBinding);
|
gl.bindUBO(programEntry.uboBinding);
|
||||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(PICA::FragmentUniforms), &uniforms);
|
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(PICA::FragmentUniforms), &uniforms);
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
|
|
Loading…
Add table
Reference in a new issue