gl_state: Update to handle stencil front/back face separately.
This commit is contained in:
parent
c7f2fb2151
commit
c4ed0b16b1
|
@ -27,13 +27,17 @@ OpenGLState::OpenGLState() {
|
||||||
color_mask.alpha_enabled = GL_TRUE;
|
color_mask.alpha_enabled = GL_TRUE;
|
||||||
|
|
||||||
stencil.test_enabled = false;
|
stencil.test_enabled = false;
|
||||||
stencil.test_func = GL_ALWAYS;
|
auto reset_stencil = [](auto& config) {
|
||||||
stencil.test_ref = 0;
|
config.test_func = GL_ALWAYS;
|
||||||
stencil.test_mask = 0xFF;
|
config.test_ref = 0;
|
||||||
stencil.write_mask = 0xFF;
|
config.test_mask = 0xFFFFFFFF;
|
||||||
stencil.action_depth_fail = GL_KEEP;
|
config.write_mask = 0xFFFFFFFF;
|
||||||
stencil.action_depth_pass = GL_KEEP;
|
config.action_depth_fail = GL_KEEP;
|
||||||
stencil.action_stencil_fail = GL_KEEP;
|
config.action_depth_pass = GL_KEEP;
|
||||||
|
config.action_stencil_fail = GL_KEEP;
|
||||||
|
};
|
||||||
|
reset_stencil(stencil.front);
|
||||||
|
reset_stencil(stencil.back);
|
||||||
|
|
||||||
blend.enabled = true;
|
blend.enabled = true;
|
||||||
blend.rgb_equation = GL_FUNC_ADD;
|
blend.rgb_equation = GL_FUNC_ADD;
|
||||||
|
@ -129,24 +133,23 @@ void OpenGLState::Apply() const {
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
auto config_stencil = [](GLenum face, const auto& config, const auto& prev_config) {
|
||||||
if (stencil.test_func != cur_state.stencil.test_func ||
|
if (config.test_func != prev_config.test_func || config.test_ref != prev_config.test_ref ||
|
||||||
stencil.test_ref != cur_state.stencil.test_ref ||
|
config.test_mask != prev_config.test_mask) {
|
||||||
stencil.test_mask != cur_state.stencil.test_mask) {
|
glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask);
|
||||||
glStencilFunc(stencil.test_func, stencil.test_ref, stencil.test_mask);
|
|
||||||
}
|
}
|
||||||
|
if (config.action_depth_fail != prev_config.action_depth_fail ||
|
||||||
if (stencil.action_depth_fail != cur_state.stencil.action_depth_fail ||
|
config.action_depth_pass != prev_config.action_depth_pass ||
|
||||||
stencil.action_depth_pass != cur_state.stencil.action_depth_pass ||
|
config.action_stencil_fail != prev_config.action_stencil_fail) {
|
||||||
stencil.action_stencil_fail != cur_state.stencil.action_stencil_fail) {
|
glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail,
|
||||||
glStencilOp(stencil.action_stencil_fail, stencil.action_depth_fail,
|
config.action_depth_pass);
|
||||||
stencil.action_depth_pass);
|
|
||||||
}
|
}
|
||||||
|
if (config.write_mask != prev_config.write_mask) {
|
||||||
// Stencil mask
|
glStencilMaskSeparate(face, config.write_mask);
|
||||||
if (stencil.write_mask != cur_state.stencil.write_mask) {
|
|
||||||
glStencilMask(stencil.write_mask);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
config_stencil(GL_FRONT, stencil.front, cur_state.stencil.front);
|
||||||
|
config_stencil(GL_BACK, stencil.back, cur_state.stencil.back);
|
||||||
|
|
||||||
// Blending
|
// Blending
|
||||||
if (blend.enabled != cur_state.blend.enabled) {
|
if (blend.enabled != cur_state.blend.enabled) {
|
||||||
|
|
|
@ -59,6 +59,7 @@ public:
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool test_enabled; // GL_STENCIL_TEST
|
bool test_enabled; // GL_STENCIL_TEST
|
||||||
|
struct {
|
||||||
GLenum test_func; // GL_STENCIL_FUNC
|
GLenum test_func; // GL_STENCIL_FUNC
|
||||||
GLint test_ref; // GL_STENCIL_REF
|
GLint test_ref; // GL_STENCIL_REF
|
||||||
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
||||||
|
@ -66,6 +67,7 @@ public:
|
||||||
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
||||||
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
||||||
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
||||||
|
} front, back;
|
||||||
} stencil;
|
} stencil;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
Loading…
Reference in New Issue