[GL] More state stuff

This commit is contained in:
wheremyfoodat 2023-07-28 01:35:49 +03:00
parent 64fa970468
commit adb78bf838
4 changed files with 67 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#pragma once
#include <type_traits>
#include "helpers.hpp"
#include "opengl.hpp"
// GL state manager object for use in the OpenGL GPU renderer and potentially other things in the future (such as a potential ImGui GUI)
@ -18,10 +19,16 @@
// backend-agnostic as possible
struct GLStateManager {
// We only support 6 clipping planes in our state manager because that's the minimum for GL_MAX_CLIP_PLANES
// And nobody needs more than 6 clip planes anyways
static constexpr GLint clipPlaneCount = 6;
bool blendEnabled;
bool logicOpEnabled;
bool depthEnabled;
bool scissorEnabled;
bool stencilEnabled;
u32 enabledClipPlanes; // Bitfield of enabled clip planes
// Colour/depth masks
bool redMask, greenMask, blueMask, alphaMask;
@ -35,6 +42,7 @@ struct GLStateManager {
void reset();
void resetBlend();
void resetClipping();
void resetColourMask();
void resetDepth();
void resetVAO();
@ -99,6 +107,42 @@ struct GLStateManager {
}
}
void enableLogicOp() {
if (!logicOpEnabled) {
logicOpEnabled = true;
OpenGL::enableLogicOp();
}
}
void disableLogicOp() {
if (logicOpEnabled) {
logicOpEnabled = false;
OpenGL::disableLogicOp();
}
}
void enableClipPlane(GLuint index) {
if (index >= clipPlaneCount) [[unlikely]] {
Helpers::panic("Enabled invalid clipping plane %d\n", index);
}
if ((enabledClipPlanes & (1 << index)) == 0) {
enabledClipPlanes |= 1 << index; // Enable relevant bit in clipping plane bitfield
OpenGL::enableClipPlane(index); // Enable plane
}
}
void disableClipPlane(GLuint index) {
if (index >= clipPlaneCount) [[unlikely]] {
Helpers::panic("Disabled invalid clipping plane %d\n", index);
}
if ((enabledClipPlanes & (1 << index)) != 0) {
enabledClipPlanes ^= 1 << index; // Disable relevant bit in bitfield by flipping it
OpenGL::disableClipPlane(index); // Disable plane
}
}
void bindVAO(GLuint handle) {
if (boundVAO != handle) {
boundVAO = handle;