diff options
| author | 2018-08-22 00:17:54 -0400 | |
|---|---|---|
| committer | 2018-08-23 11:08:46 -0400 | |
| commit | c4ed0b16b1c22658fd7e388a3244f472609622a6 (patch) | |
| tree | 085f826d9b6025f2ef7f1ac7f7af54f3844f1ce3 | |
| parent | Merge pull request #1157 from lioncash/vec (diff) | |
| download | yuzu-c4ed0b16b1c22658fd7e388a3244f472609622a6.tar.gz yuzu-c4ed0b16b1c22658fd7e388a3244f472609622a6.tar.xz yuzu-c4ed0b16b1c22658fd7e388a3244f472609622a6.zip | |
gl_state: Update to handle stencil front/back face separately.
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 53 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 18 |
2 files changed, 38 insertions, 33 deletions
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index e1a887d67..60a4defd1 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -27,13 +27,17 @@ OpenGLState::OpenGLState() { | |||
| 27 | color_mask.alpha_enabled = GL_TRUE; | 27 | color_mask.alpha_enabled = GL_TRUE; |
| 28 | 28 | ||
| 29 | stencil.test_enabled = false; | 29 | stencil.test_enabled = false; |
| 30 | stencil.test_func = GL_ALWAYS; | 30 | auto reset_stencil = [](auto& config) { |
| 31 | stencil.test_ref = 0; | 31 | config.test_func = GL_ALWAYS; |
| 32 | stencil.test_mask = 0xFF; | 32 | config.test_ref = 0; |
| 33 | stencil.write_mask = 0xFF; | 33 | config.test_mask = 0xFFFFFFFF; |
| 34 | stencil.action_depth_fail = GL_KEEP; | 34 | config.write_mask = 0xFFFFFFFF; |
| 35 | stencil.action_depth_pass = GL_KEEP; | 35 | config.action_depth_fail = GL_KEEP; |
| 36 | stencil.action_stencil_fail = GL_KEEP; | 36 | config.action_depth_pass = GL_KEEP; |
| 37 | config.action_stencil_fail = GL_KEEP; | ||
| 38 | }; | ||
| 39 | reset_stencil(stencil.front); | ||
| 40 | reset_stencil(stencil.back); | ||
| 37 | 41 | ||
| 38 | blend.enabled = true; | 42 | blend.enabled = true; |
| 39 | blend.rgb_equation = GL_FUNC_ADD; | 43 | blend.rgb_equation = GL_FUNC_ADD; |
| @@ -129,24 +133,23 @@ void OpenGLState::Apply() const { | |||
| 129 | glDisable(GL_STENCIL_TEST); | 133 | glDisable(GL_STENCIL_TEST); |
| 130 | } | 134 | } |
| 131 | } | 135 | } |
| 132 | 136 | auto config_stencil = [](GLenum face, const auto& config, const auto& prev_config) { | |
| 133 | if (stencil.test_func != cur_state.stencil.test_func || | 137 | if (config.test_func != prev_config.test_func || config.test_ref != prev_config.test_ref || |
| 134 | stencil.test_ref != cur_state.stencil.test_ref || | 138 | config.test_mask != prev_config.test_mask) { |
| 135 | stencil.test_mask != cur_state.stencil.test_mask) { | 139 | glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask); |
| 136 | glStencilFunc(stencil.test_func, stencil.test_ref, stencil.test_mask); | 140 | } |
| 137 | } | 141 | if (config.action_depth_fail != prev_config.action_depth_fail || |
| 138 | 142 | config.action_depth_pass != prev_config.action_depth_pass || | |
| 139 | if (stencil.action_depth_fail != cur_state.stencil.action_depth_fail || | 143 | config.action_stencil_fail != prev_config.action_stencil_fail) { |
| 140 | stencil.action_depth_pass != cur_state.stencil.action_depth_pass || | 144 | glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail, |
| 141 | stencil.action_stencil_fail != cur_state.stencil.action_stencil_fail) { | 145 | config.action_depth_pass); |
| 142 | glStencilOp(stencil.action_stencil_fail, stencil.action_depth_fail, | 146 | } |
| 143 | stencil.action_depth_pass); | 147 | if (config.write_mask != prev_config.write_mask) { |
| 144 | } | 148 | glStencilMaskSeparate(face, config.write_mask); |
| 145 | 149 | } | |
| 146 | // Stencil mask | 150 | }; |
| 147 | if (stencil.write_mask != cur_state.stencil.write_mask) { | 151 | config_stencil(GL_FRONT, stencil.front, cur_state.stencil.front); |
| 148 | glStencilMask(stencil.write_mask); | 152 | config_stencil(GL_BACK, stencil.back, cur_state.stencil.back); |
| 149 | } | ||
| 150 | 153 | ||
| 151 | // Blending | 154 | // Blending |
| 152 | if (blend.enabled != cur_state.blend.enabled) { | 155 | if (blend.enabled != cur_state.blend.enabled) { |
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 22b0b1e41..46e96a97d 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h | |||
| @@ -58,14 +58,16 @@ public: | |||
| 58 | } color_mask; // GL_COLOR_WRITEMASK | 58 | } color_mask; // GL_COLOR_WRITEMASK |
| 59 | 59 | ||
| 60 | struct { | 60 | struct { |
| 61 | bool test_enabled; // GL_STENCIL_TEST | 61 | bool test_enabled; // GL_STENCIL_TEST |
| 62 | GLenum test_func; // GL_STENCIL_FUNC | 62 | struct { |
| 63 | GLint test_ref; // GL_STENCIL_REF | 63 | GLenum test_func; // GL_STENCIL_FUNC |
| 64 | GLuint test_mask; // GL_STENCIL_VALUE_MASK | 64 | GLint test_ref; // GL_STENCIL_REF |
| 65 | GLuint write_mask; // GL_STENCIL_WRITEMASK | 65 | GLuint test_mask; // GL_STENCIL_VALUE_MASK |
| 66 | GLenum action_stencil_fail; // GL_STENCIL_FAIL | 66 | GLuint write_mask; // GL_STENCIL_WRITEMASK |
| 67 | GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL | 67 | GLenum action_stencil_fail; // GL_STENCIL_FAIL |
| 68 | GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS | 68 | GLenum action_depth_fail; // GL_STENCIL_PASS_DEPTH_FAIL |
| 69 | GLenum action_depth_pass; // GL_STENCIL_PASS_DEPTH_PASS | ||
| 70 | } front, back; | ||
| 69 | } stencil; | 71 | } stencil; |
| 70 | 72 | ||
| 71 | struct { | 73 | struct { |