This commit is contained in:
wheremyfoodat 2023-07-28 02:24:26 +03:00
parent adb78bf838
commit 73321856c8
4 changed files with 53 additions and 29 deletions

View file

@ -34,11 +34,13 @@ struct GLStateManager {
bool redMask, greenMask, blueMask, alphaMask;
bool depthMask;
GLuint stencilMask;
GLuint boundVAO;
GLuint boundVBO;
GLuint currentProgram;
GLenum depthFunc;
GLenum logicOp;
void reset();
void resetBlend();
@ -121,6 +123,13 @@ struct GLStateManager {
}
}
void setLogicOp(GLenum op) {
if (logicOp != op) {
logicOp = op;
OpenGL::setLogicOp(op);
}
}
void enableClipPlane(GLuint index) {
if (index >= clipPlaneCount) [[unlikely]] {
Helpers::panic("Enabled invalid clipping plane %d\n", index);
@ -143,6 +152,13 @@ struct GLStateManager {
}
}
void setStencilMask(GLuint mask) {
if (stencilMask != mask) {
stencilMask = mask;
OpenGL::setStencilMask(mask);
}
}
void bindVAO(GLuint handle) {
if (boundVAO != handle) {
boundVAO = handle;

View file

@ -533,6 +533,9 @@ namespace OpenGL {
static void setColourMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a) { glColorMask(r, g, b, a); }
static void setDepthMask(GLboolean mask) { glDepthMask(mask); }
// TODO: Add a proper enum for this
static void setLogicOp(GLenum op) { glLogicOp(op); }
enum Primitives {
Triangle = GL_TRIANGLES,
Triangles = Triangle,

View file

@ -3,9 +3,11 @@
void GLStateManager::resetBlend() {
blendEnabled = false;
logicOpEnabled = false;
logicOp = GL_COPY;
OpenGL::disableBlend();
OpenGL::disableLogicOp();
OpenGL::setLogicOp(GL_COPY);
}
void GLStateManager::resetClipping() {
@ -39,7 +41,10 @@ void GLStateManager::resetScissor() {
void GLStateManager::resetStencil() {
stencilEnabled = false;
stencilMask = 0xff;
OpenGL::disableStencil();
OpenGL::setStencilMask(0xff);
}
void GLStateManager::resetVAO() {

View file

@ -184,7 +184,7 @@ void RendererGL::setupBlending() {
if (!blendingEnabled) { // Logic ops are enabled
const u32 logicOp = getBits<0, 4>(regs[PICA::InternalRegs::LogicOp]);
glLogicOp(logicOps[logicOp]);
gl.setLogicOp(logicOps[logicOp]);
// If logic ops are enabled we don't need to disable blending because they override it
gl.enableLogicOp();
@ -243,7 +243,7 @@ void RendererGL::setupStencilTest(bool stencilEnable) {
const u32 stencilBufferMask = stencilWrite ? getBits<8, 8>(stencilConfig) : 0;
glStencilFunc(stencilFuncs[stencilFunc], reference, stencilRefMask);
glStencilMask(stencilBufferMask);
gl.setStencilMask(stencilBufferMask);
static constexpr std::array<GLenum, 8> stencilOps = {
GL_KEEP,
@ -489,7 +489,7 @@ void RendererGL::clearBuffer(u32 startAddress, u32 endAddress, u32 value, u32 co
if (format == DepthFmt::Depth24Stencil8) {
const u8 stencil = (value >> 24);
OpenGL::setStencilMask(0xff);
gl.setStencilMask(0xff);
OpenGL::setClearStencil(stencil);
OpenGL::clearDepthAndStencil();
} else {