mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-12-04 04:32:50 +01:00
gl_state: Update to handle stencil front/back face separately.
This commit is contained in:
parent
c7f2fb2151
commit
c4ed0b16b1
2 changed files with 38 additions and 33 deletions
|
@ -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 ||
|
||||||
|
config.action_depth_pass != prev_config.action_depth_pass ||
|
||||||
if (stencil.action_depth_fail != cur_state.stencil.action_depth_fail ||
|
config.action_stencil_fail != prev_config.action_stencil_fail) {
|
||||||
stencil.action_depth_pass != cur_state.stencil.action_depth_pass ||
|
glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail,
|
||||||
stencil.action_stencil_fail != cur_state.stencil.action_stencil_fail) {
|
config.action_depth_pass);
|
||||||
glStencilOp(stencil.action_stencil_fail, stencil.action_depth_fail,
|
}
|
||||||
stencil.action_depth_pass);
|
if (config.write_mask != prev_config.write_mask) {
|
||||||
}
|
glStencilMaskSeparate(face, config.write_mask);
|
||||||
|
}
|
||||||
// Stencil mask
|
};
|
||||||
if (stencil.write_mask != cur_state.stencil.write_mask) {
|
config_stencil(GL_FRONT, stencil.front, cur_state.stencil.front);
|
||||||
glStencilMask(stencil.write_mask);
|
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) {
|
||||||
|
|
|
@ -58,14 +58,16 @@ public:
|
||||||
} color_mask; // GL_COLOR_WRITEMASK
|
} color_mask; // GL_COLOR_WRITEMASK
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool test_enabled; // GL_STENCIL_TEST
|
bool test_enabled; // GL_STENCIL_TEST
|
||||||
GLenum test_func; // GL_STENCIL_FUNC
|
struct {
|
||||||
GLint test_ref; // GL_STENCIL_REF
|
GLenum test_func; // GL_STENCIL_FUNC
|
||||||
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
GLint test_ref; // GL_STENCIL_REF
|
||||||
GLuint write_mask; // GL_STENCIL_WRITEMASK
|
GLuint test_mask; // GL_STENCIL_VALUE_MASK
|
||||||
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
GLuint write_mask; // GL_STENCIL_WRITEMASK
|
||||||
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
GLenum action_stencil_fail; // GL_STENCIL_FAIL
|
||||||
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL
|
||||||
|
GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS
|
||||||
|
} front, back;
|
||||||
} stencil;
|
} stencil;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
Loading…
Reference in a new issue