diff options
| author | 2019-02-20 21:47:46 -0500 | |
|---|---|---|
| committer | 2019-02-20 21:47:46 -0500 | |
| commit | 9539c4203b4e39d8715ba0fed88f56f063d0a548 (patch) | |
| tree | 5bd6b2e1d0034240bc2a36008af36d44204c704d | |
| parent | Merge pull request #2130 from lioncash/system_engine (diff) | |
| parent | gl_state: Synchronize gl_state even when state is disabled (diff) | |
| download | yuzu-9539c4203b4e39d8715ba0fed88f56f063d0a548.tar.gz yuzu-9539c4203b4e39d8715ba0fed88f56f063d0a548.tar.xz yuzu-9539c4203b4e39d8715ba0fed88f56f063d0a548.zip | |
Merge pull request #2125 from ReinUsesLisp/fixup-glstate
gl_state: Synchronize gl_state even when state is disabled
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 144 |
1 files changed, 61 insertions, 83 deletions
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 81af803bc..219f08053 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -11,7 +11,9 @@ | |||
| 11 | namespace OpenGL { | 11 | namespace OpenGL { |
| 12 | 12 | ||
| 13 | OpenGLState OpenGLState::cur_state; | 13 | OpenGLState OpenGLState::cur_state; |
| 14 | |||
| 14 | bool OpenGLState::s_rgb_used; | 15 | bool OpenGLState::s_rgb_used; |
| 16 | |||
| 15 | OpenGLState::OpenGLState() { | 17 | OpenGLState::OpenGLState() { |
| 16 | // These all match default OpenGL values | 18 | // These all match default OpenGL values |
| 17 | geometry_shaders.enabled = false; | 19 | geometry_shaders.enabled = false; |
| @@ -112,7 +114,6 @@ void OpenGLState::ApplyDefaultState() { | |||
| 112 | } | 114 | } |
| 113 | 115 | ||
| 114 | void OpenGLState::ApplySRgb() const { | 116 | void OpenGLState::ApplySRgb() const { |
| 115 | // sRGB | ||
| 116 | if (framebuffer_srgb.enabled != cur_state.framebuffer_srgb.enabled) { | 117 | if (framebuffer_srgb.enabled != cur_state.framebuffer_srgb.enabled) { |
| 117 | if (framebuffer_srgb.enabled) { | 118 | if (framebuffer_srgb.enabled) { |
| 118 | // Track if sRGB is used | 119 | // Track if sRGB is used |
| @@ -125,23 +126,20 @@ void OpenGLState::ApplySRgb() const { | |||
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | void OpenGLState::ApplyCulling() const { | 128 | void OpenGLState::ApplyCulling() const { |
| 128 | // Culling | 129 | if (cull.enabled != cur_state.cull.enabled) { |
| 129 | const bool cull_changed = cull.enabled != cur_state.cull.enabled; | ||
| 130 | if (cull_changed) { | ||
| 131 | if (cull.enabled) { | 130 | if (cull.enabled) { |
| 132 | glEnable(GL_CULL_FACE); | 131 | glEnable(GL_CULL_FACE); |
| 133 | } else { | 132 | } else { |
| 134 | glDisable(GL_CULL_FACE); | 133 | glDisable(GL_CULL_FACE); |
| 135 | } | 134 | } |
| 136 | } | 135 | } |
| 137 | if (cull.enabled) { | ||
| 138 | if (cull_changed || cull.mode != cur_state.cull.mode) { | ||
| 139 | glCullFace(cull.mode); | ||
| 140 | } | ||
| 141 | 136 | ||
| 142 | if (cull_changed || cull.front_face != cur_state.cull.front_face) { | 137 | if (cull.mode != cur_state.cull.mode) { |
| 143 | glFrontFace(cull.front_face); | 138 | glCullFace(cull.mode); |
| 144 | } | 139 | } |
| 140 | |||
| 141 | if (cull.front_face != cur_state.cull.front_face) { | ||
| 142 | glFrontFace(cull.front_face); | ||
| 145 | } | 143 | } |
| 146 | } | 144 | } |
| 147 | 145 | ||
| @@ -172,72 +170,63 @@ void OpenGLState::ApplyColorMask() const { | |||
| 172 | } | 170 | } |
| 173 | 171 | ||
| 174 | void OpenGLState::ApplyDepth() const { | 172 | void OpenGLState::ApplyDepth() const { |
| 175 | // Depth test | 173 | if (depth.test_enabled != cur_state.depth.test_enabled) { |
| 176 | const bool depth_test_changed = depth.test_enabled != cur_state.depth.test_enabled; | ||
| 177 | if (depth_test_changed) { | ||
| 178 | if (depth.test_enabled) { | 174 | if (depth.test_enabled) { |
| 179 | glEnable(GL_DEPTH_TEST); | 175 | glEnable(GL_DEPTH_TEST); |
| 180 | } else { | 176 | } else { |
| 181 | glDisable(GL_DEPTH_TEST); | 177 | glDisable(GL_DEPTH_TEST); |
| 182 | } | 178 | } |
| 183 | } | 179 | } |
| 184 | if (depth.test_enabled && | 180 | |
| 185 | (depth_test_changed || depth.test_func != cur_state.depth.test_func)) { | 181 | if (depth.test_func != cur_state.depth.test_func) { |
| 186 | glDepthFunc(depth.test_func); | 182 | glDepthFunc(depth.test_func); |
| 187 | } | 183 | } |
| 188 | // Depth mask | 184 | |
| 189 | if (depth.write_mask != cur_state.depth.write_mask) { | 185 | if (depth.write_mask != cur_state.depth.write_mask) { |
| 190 | glDepthMask(depth.write_mask); | 186 | glDepthMask(depth.write_mask); |
| 191 | } | 187 | } |
| 192 | } | 188 | } |
| 193 | 189 | ||
| 194 | void OpenGLState::ApplyPrimitiveRestart() const { | 190 | void OpenGLState::ApplyPrimitiveRestart() const { |
| 195 | const bool primitive_restart_changed = | 191 | if (primitive_restart.enabled != cur_state.primitive_restart.enabled) { |
| 196 | primitive_restart.enabled != cur_state.primitive_restart.enabled; | ||
| 197 | if (primitive_restart_changed) { | ||
| 198 | if (primitive_restart.enabled) { | 192 | if (primitive_restart.enabled) { |
| 199 | glEnable(GL_PRIMITIVE_RESTART); | 193 | glEnable(GL_PRIMITIVE_RESTART); |
| 200 | } else { | 194 | } else { |
| 201 | glDisable(GL_PRIMITIVE_RESTART); | 195 | glDisable(GL_PRIMITIVE_RESTART); |
| 202 | } | 196 | } |
| 203 | } | 197 | } |
| 204 | if (primitive_restart_changed || | 198 | |
| 205 | (primitive_restart.enabled && | 199 | if (primitive_restart.index != cur_state.primitive_restart.index) { |
| 206 | primitive_restart.index != cur_state.primitive_restart.index)) { | ||
| 207 | glPrimitiveRestartIndex(primitive_restart.index); | 200 | glPrimitiveRestartIndex(primitive_restart.index); |
| 208 | } | 201 | } |
| 209 | } | 202 | } |
| 210 | 203 | ||
| 211 | void OpenGLState::ApplyStencilTest() const { | 204 | void OpenGLState::ApplyStencilTest() const { |
| 212 | const bool stencil_test_changed = stencil.test_enabled != cur_state.stencil.test_enabled; | 205 | if (stencil.test_enabled != cur_state.stencil.test_enabled) { |
| 213 | if (stencil_test_changed) { | ||
| 214 | if (stencil.test_enabled) { | 206 | if (stencil.test_enabled) { |
| 215 | glEnable(GL_STENCIL_TEST); | 207 | glEnable(GL_STENCIL_TEST); |
| 216 | } else { | 208 | } else { |
| 217 | glDisable(GL_STENCIL_TEST); | 209 | glDisable(GL_STENCIL_TEST); |
| 218 | } | 210 | } |
| 219 | } | 211 | } |
| 220 | if (stencil.test_enabled) { | 212 | |
| 221 | auto config_stencil = [stencil_test_changed](GLenum face, const auto& config, | 213 | const auto ConfigStencil = [](GLenum face, const auto& config, const auto& prev_config) { |
| 222 | const auto& prev_config) { | 214 | if (config.test_func != prev_config.test_func || config.test_ref != prev_config.test_ref || |
| 223 | if (stencil_test_changed || config.test_func != prev_config.test_func || | 215 | config.test_mask != prev_config.test_mask) { |
| 224 | config.test_ref != prev_config.test_ref || | 216 | glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask); |
| 225 | config.test_mask != prev_config.test_mask) { | 217 | } |
| 226 | glStencilFuncSeparate(face, config.test_func, config.test_ref, config.test_mask); | 218 | if (config.action_depth_fail != prev_config.action_depth_fail || |
| 227 | } | 219 | config.action_depth_pass != prev_config.action_depth_pass || |
| 228 | if (stencil_test_changed || config.action_depth_fail != prev_config.action_depth_fail || | 220 | config.action_stencil_fail != prev_config.action_stencil_fail) { |
| 229 | config.action_depth_pass != prev_config.action_depth_pass || | 221 | glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail, |
| 230 | config.action_stencil_fail != prev_config.action_stencil_fail) { | 222 | config.action_depth_pass); |
| 231 | glStencilOpSeparate(face, config.action_stencil_fail, config.action_depth_fail, | 223 | } |
| 232 | config.action_depth_pass); | 224 | if (config.write_mask != prev_config.write_mask) { |
| 233 | } | 225 | glStencilMaskSeparate(face, config.write_mask); |
| 234 | if (config.write_mask != prev_config.write_mask) { | 226 | } |
| 235 | glStencilMaskSeparate(face, config.write_mask); | 227 | }; |
| 236 | } | 228 | ConfigStencil(GL_FRONT, stencil.front, cur_state.stencil.front); |
| 237 | }; | 229 | ConfigStencil(GL_BACK, stencil.back, cur_state.stencil.back); |
| 238 | config_stencil(GL_FRONT, stencil.front, cur_state.stencil.front); | ||
| 239 | config_stencil(GL_BACK, stencil.back, cur_state.stencil.back); | ||
| 240 | } | ||
| 241 | } | 230 | } |
| 242 | // Viewport does not affects glClearBuffer so emulate viewport using scissor test | 231 | // Viewport does not affects glClearBuffer so emulate viewport using scissor test |
| 243 | void OpenGLState::EmulateViewportWithScissor() { | 232 | void OpenGLState::EmulateViewportWithScissor() { |
| @@ -278,19 +267,18 @@ void OpenGLState::ApplyViewport() const { | |||
| 278 | updated.depth_range_far != current.depth_range_far) { | 267 | updated.depth_range_far != current.depth_range_far) { |
| 279 | glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far); | 268 | glDepthRangeIndexed(i, updated.depth_range_near, updated.depth_range_far); |
| 280 | } | 269 | } |
| 281 | const bool scissor_changed = updated.scissor.enabled != current.scissor.enabled; | 270 | |
| 282 | if (scissor_changed) { | 271 | if (updated.scissor.enabled != current.scissor.enabled) { |
| 283 | if (updated.scissor.enabled) { | 272 | if (updated.scissor.enabled) { |
| 284 | glEnablei(GL_SCISSOR_TEST, i); | 273 | glEnablei(GL_SCISSOR_TEST, i); |
| 285 | } else { | 274 | } else { |
| 286 | glDisablei(GL_SCISSOR_TEST, i); | 275 | glDisablei(GL_SCISSOR_TEST, i); |
| 287 | } | 276 | } |
| 288 | } | 277 | } |
| 289 | if (updated.scissor.enabled && | 278 | |
| 290 | (scissor_changed || updated.scissor.x != current.scissor.x || | 279 | if (updated.scissor.x != current.scissor.x || updated.scissor.y != current.scissor.y || |
| 291 | updated.scissor.y != current.scissor.y || | 280 | updated.scissor.width != current.scissor.width || |
| 292 | updated.scissor.width != current.scissor.width || | 281 | updated.scissor.height != current.scissor.height) { |
| 293 | updated.scissor.height != current.scissor.height)) { | ||
| 294 | glScissorIndexed(i, updated.scissor.x, updated.scissor.y, updated.scissor.width, | 282 | glScissorIndexed(i, updated.scissor.x, updated.scissor.y, updated.scissor.width, |
| 295 | updated.scissor.height); | 283 | updated.scissor.height); |
| 296 | } | 284 | } |
| @@ -302,22 +290,23 @@ void OpenGLState::ApplyViewport() const { | |||
| 302 | updated.height != current.height) { | 290 | updated.height != current.height) { |
| 303 | glViewport(updated.x, updated.y, updated.width, updated.height); | 291 | glViewport(updated.x, updated.y, updated.width, updated.height); |
| 304 | } | 292 | } |
| 293 | |||
| 305 | if (updated.depth_range_near != current.depth_range_near || | 294 | if (updated.depth_range_near != current.depth_range_near || |
| 306 | updated.depth_range_far != current.depth_range_far) { | 295 | updated.depth_range_far != current.depth_range_far) { |
| 307 | glDepthRange(updated.depth_range_near, updated.depth_range_far); | 296 | glDepthRange(updated.depth_range_near, updated.depth_range_far); |
| 308 | } | 297 | } |
| 309 | const bool scissor_changed = updated.scissor.enabled != current.scissor.enabled; | 298 | |
| 310 | if (scissor_changed) { | 299 | if (updated.scissor.enabled != current.scissor.enabled) { |
| 311 | if (updated.scissor.enabled) { | 300 | if (updated.scissor.enabled) { |
| 312 | glEnable(GL_SCISSOR_TEST); | 301 | glEnable(GL_SCISSOR_TEST); |
| 313 | } else { | 302 | } else { |
| 314 | glDisable(GL_SCISSOR_TEST); | 303 | glDisable(GL_SCISSOR_TEST); |
| 315 | } | 304 | } |
| 316 | } | 305 | } |
| 317 | if (updated.scissor.enabled && (scissor_changed || updated.scissor.x != current.scissor.x || | 306 | |
| 318 | updated.scissor.y != current.scissor.y || | 307 | if (updated.scissor.x != current.scissor.x || updated.scissor.y != current.scissor.y || |
| 319 | updated.scissor.width != current.scissor.width || | 308 | updated.scissor.width != current.scissor.width || |
| 320 | updated.scissor.height != current.scissor.height)) { | 309 | updated.scissor.height != current.scissor.height) { |
| 321 | glScissor(updated.scissor.x, updated.scissor.y, updated.scissor.width, | 310 | glScissor(updated.scissor.x, updated.scissor.y, updated.scissor.width, |
| 322 | updated.scissor.height); | 311 | updated.scissor.height); |
| 323 | } | 312 | } |
| @@ -327,8 +316,7 @@ void OpenGLState::ApplyViewport() const { | |||
| 327 | void OpenGLState::ApplyGlobalBlending() const { | 316 | void OpenGLState::ApplyGlobalBlending() const { |
| 328 | const Blend& current = cur_state.blend[0]; | 317 | const Blend& current = cur_state.blend[0]; |
| 329 | const Blend& updated = blend[0]; | 318 | const Blend& updated = blend[0]; |
| 330 | const bool blend_changed = updated.enabled != current.enabled; | 319 | if (updated.enabled != current.enabled) { |
| 331 | if (blend_changed) { | ||
| 332 | if (updated.enabled) { | 320 | if (updated.enabled) { |
| 333 | glEnable(GL_BLEND); | 321 | glEnable(GL_BLEND); |
| 334 | } else { | 322 | } else { |
| @@ -338,15 +326,14 @@ void OpenGLState::ApplyGlobalBlending() const { | |||
| 338 | if (!updated.enabled) { | 326 | if (!updated.enabled) { |
| 339 | return; | 327 | return; |
| 340 | } | 328 | } |
| 341 | if (blend_changed || updated.src_rgb_func != current.src_rgb_func || | 329 | if (updated.src_rgb_func != current.src_rgb_func || |
| 342 | updated.dst_rgb_func != current.dst_rgb_func || updated.src_a_func != current.src_a_func || | 330 | updated.dst_rgb_func != current.dst_rgb_func || updated.src_a_func != current.src_a_func || |
| 343 | updated.dst_a_func != current.dst_a_func) { | 331 | updated.dst_a_func != current.dst_a_func) { |
| 344 | glBlendFuncSeparate(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func, | 332 | glBlendFuncSeparate(updated.src_rgb_func, updated.dst_rgb_func, updated.src_a_func, |
| 345 | updated.dst_a_func); | 333 | updated.dst_a_func); |
| 346 | } | 334 | } |
| 347 | 335 | ||
| 348 | if (blend_changed || updated.rgb_equation != current.rgb_equation || | 336 | if (updated.rgb_equation != current.rgb_equation || updated.a_equation != current.a_equation) { |
| 349 | updated.a_equation != current.a_equation) { | ||
| 350 | glBlendEquationSeparate(updated.rgb_equation, updated.a_equation); | 337 | glBlendEquationSeparate(updated.rgb_equation, updated.a_equation); |
| 351 | } | 338 | } |
| 352 | } | 339 | } |
| @@ -354,26 +341,22 @@ void OpenGLState::ApplyGlobalBlending() const { | |||
| 354 | void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) const { | 341 | void OpenGLState::ApplyTargetBlending(std::size_t target, bool force) const { |
| 355 | const Blend& updated = blend[target]; | 342 | const Blend& updated = blend[target]; |
| 356 | const Blend& current = cur_state.blend[target]; | 343 | const Blend& current = cur_state.blend[target]; |
| 357 | const bool blend_changed = updated.enabled != current.enabled || force; | 344 | if (updated.enabled != current.enabled || force) { |
| 358 | if (blend_changed) { | ||
| 359 | if (updated.enabled) { | 345 | if (updated.enabled) { |
| 360 | glEnablei(GL_BLEND, static_cast<GLuint>(target)); | 346 | glEnablei(GL_BLEND, static_cast<GLuint>(target)); |
| 361 | } else { | 347 | } else { |
| 362 | glDisablei(GL_BLEND, static_cast<GLuint>(target)); | 348 | glDisablei(GL_BLEND, static_cast<GLuint>(target)); |
| 363 | } | 349 | } |
| 364 | } | 350 | } |
| 365 | if (!updated.enabled) { | 351 | |
| 366 | return; | 352 | if (updated.src_rgb_func != current.src_rgb_func || |
| 367 | } | ||
| 368 | if (blend_changed || updated.src_rgb_func != current.src_rgb_func || | ||
| 369 | updated.dst_rgb_func != current.dst_rgb_func || updated.src_a_func != current.src_a_func || | 353 | updated.dst_rgb_func != current.dst_rgb_func || updated.src_a_func != current.src_a_func || |
| 370 | updated.dst_a_func != current.dst_a_func) { | 354 | updated.dst_a_func != current.dst_a_func) { |
| 371 | glBlendFuncSeparatei(static_cast<GLuint>(target), updated.src_rgb_func, | 355 | glBlendFuncSeparatei(static_cast<GLuint>(target), updated.src_rgb_func, |
| 372 | updated.dst_rgb_func, updated.src_a_func, updated.dst_a_func); | 356 | updated.dst_rgb_func, updated.src_a_func, updated.dst_a_func); |
| 373 | } | 357 | } |
| 374 | 358 | ||
| 375 | if (blend_changed || updated.rgb_equation != current.rgb_equation || | 359 | if (updated.rgb_equation != current.rgb_equation || updated.a_equation != current.a_equation) { |
| 376 | updated.a_equation != current.a_equation) { | ||
| 377 | glBlendEquationSeparatei(static_cast<GLuint>(target), updated.rgb_equation, | 360 | glBlendEquationSeparatei(static_cast<GLuint>(target), updated.rgb_equation, |
| 378 | updated.a_equation); | 361 | updated.a_equation); |
| 379 | } | 362 | } |
| @@ -397,8 +380,7 @@ void OpenGLState::ApplyBlending() const { | |||
| 397 | } | 380 | } |
| 398 | 381 | ||
| 399 | void OpenGLState::ApplyLogicOp() const { | 382 | void OpenGLState::ApplyLogicOp() const { |
| 400 | const bool logic_op_changed = logic_op.enabled != cur_state.logic_op.enabled; | 383 | if (logic_op.enabled != cur_state.logic_op.enabled) { |
| 401 | if (logic_op_changed) { | ||
| 402 | if (logic_op.enabled) { | 384 | if (logic_op.enabled) { |
| 403 | glEnable(GL_COLOR_LOGIC_OP); | 385 | glEnable(GL_COLOR_LOGIC_OP); |
| 404 | } else { | 386 | } else { |
| @@ -406,14 +388,12 @@ void OpenGLState::ApplyLogicOp() const { | |||
| 406 | } | 388 | } |
| 407 | } | 389 | } |
| 408 | 390 | ||
| 409 | if (logic_op.enabled && | 391 | if (logic_op.operation != cur_state.logic_op.operation) { |
| 410 | (logic_op_changed || logic_op.operation != cur_state.logic_op.operation)) { | ||
| 411 | glLogicOp(logic_op.operation); | 392 | glLogicOp(logic_op.operation); |
| 412 | } | 393 | } |
| 413 | } | 394 | } |
| 414 | 395 | ||
| 415 | void OpenGLState::ApplyPolygonOffset() const { | 396 | void OpenGLState::ApplyPolygonOffset() const { |
| 416 | |||
| 417 | const bool fill_enable_changed = | 397 | const bool fill_enable_changed = |
| 418 | polygon_offset.fill_enable != cur_state.polygon_offset.fill_enable; | 398 | polygon_offset.fill_enable != cur_state.polygon_offset.fill_enable; |
| 419 | const bool line_enable_changed = | 399 | const bool line_enable_changed = |
| @@ -448,9 +428,7 @@ void OpenGLState::ApplyPolygonOffset() const { | |||
| 448 | } | 428 | } |
| 449 | } | 429 | } |
| 450 | 430 | ||
| 451 | if ((polygon_offset.fill_enable || polygon_offset.line_enable || polygon_offset.point_enable) && | 431 | if (factor_changed || units_changed || clamp_changed) { |
| 452 | (factor_changed || units_changed || clamp_changed)) { | ||
| 453 | |||
| 454 | if (GLAD_GL_EXT_polygon_offset_clamp && polygon_offset.clamp != 0) { | 432 | if (GLAD_GL_EXT_polygon_offset_clamp && polygon_offset.clamp != 0) { |
| 455 | glPolygonOffsetClamp(polygon_offset.factor, polygon_offset.units, polygon_offset.clamp); | 433 | glPolygonOffsetClamp(polygon_offset.factor, polygon_offset.units, polygon_offset.clamp); |
| 456 | } else { | 434 | } else { |
| @@ -528,9 +506,9 @@ void OpenGLState::ApplyDepthClamp() const { | |||
| 528 | depth_clamp.near_plane == cur_state.depth_clamp.near_plane) { | 506 | depth_clamp.near_plane == cur_state.depth_clamp.near_plane) { |
| 529 | return; | 507 | return; |
| 530 | } | 508 | } |
| 531 | if (depth_clamp.far_plane != depth_clamp.near_plane) { | 509 | UNIMPLEMENTED_IF_MSG(depth_clamp.far_plane != depth_clamp.near_plane, |
| 532 | UNIMPLEMENTED_MSG("Unimplemented Depth Clamp Separation!"); | 510 | "Unimplemented Depth Clamp Separation!"); |
| 533 | } | 511 | |
| 534 | if (depth_clamp.far_plane || depth_clamp.near_plane) { | 512 | if (depth_clamp.far_plane || depth_clamp.near_plane) { |
| 535 | glEnable(GL_DEPTH_CLAMP); | 513 | glEnable(GL_DEPTH_CLAMP); |
| 536 | } else { | 514 | } else { |