diff options
| author | 2018-11-26 20:31:44 -0300 | |
|---|---|---|
| committer | 2018-11-26 18:31:44 -0500 | |
| commit | cb8d51e37e7d630f1ea3dc816b2d5aaab2295bc2 (patch) | |
| tree | d8eebad471412afebbee0c0e465655695b8df585 /src/video_core/renderer_opengl | |
| parent | Merge pull request #1713 from FernandoS27/bra-cc (diff) | |
| download | yuzu-cb8d51e37e7d630f1ea3dc816b2d5aaab2295bc2.tar.gz yuzu-cb8d51e37e7d630f1ea3dc816b2d5aaab2295bc2.tar.xz yuzu-cb8d51e37e7d630f1ea3dc816b2d5aaab2295bc2.zip | |
GPU States: Implement Polygon Offset. This is used in SMO all the time. (#1784)
* GPU States: Implement Polygon Offset. This is used in SMO all the time.
* Clang Format fixes.
* Initialize polygon_offset in the constructor.
Diffstat (limited to 'src/video_core/renderer_opengl')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 12 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 3 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.cpp | 57 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 10 |
4 files changed, 81 insertions, 1 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 630a58e49..2d5e65f41 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -620,7 +620,7 @@ void RasterizerOpenGL::DrawArrays() { | |||
| 620 | SyncTransformFeedback(); | 620 | SyncTransformFeedback(); |
| 621 | SyncPointState(); | 621 | SyncPointState(); |
| 622 | CheckAlphaTests(); | 622 | CheckAlphaTests(); |
| 623 | 623 | SyncPolygonOffset(); | |
| 624 | // TODO(bunnei): Sync framebuffer_scale uniform here | 624 | // TODO(bunnei): Sync framebuffer_scale uniform here |
| 625 | // TODO(bunnei): Sync scissorbox uniform(s) here | 625 | // TODO(bunnei): Sync scissorbox uniform(s) here |
| 626 | 626 | ||
| @@ -1179,6 +1179,16 @@ void RasterizerOpenGL::SyncPointState() { | |||
| 1179 | state.point.size = regs.point_size; | 1179 | state.point.size = regs.point_size; |
| 1180 | } | 1180 | } |
| 1181 | 1181 | ||
| 1182 | void RasterizerOpenGL::SyncPolygonOffset() { | ||
| 1183 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; | ||
| 1184 | state.polygon_offset.fill_enable = regs.polygon_offset_fill_enable != 0; | ||
| 1185 | state.polygon_offset.line_enable = regs.polygon_offset_line_enable != 0; | ||
| 1186 | state.polygon_offset.point_enable = regs.polygon_offset_point_enable != 0; | ||
| 1187 | state.polygon_offset.units = regs.polygon_offset_units; | ||
| 1188 | state.polygon_offset.factor = regs.polygon_offset_factor; | ||
| 1189 | state.polygon_offset.clamp = regs.polygon_offset_clamp; | ||
| 1190 | } | ||
| 1191 | |||
| 1182 | void RasterizerOpenGL::CheckAlphaTests() { | 1192 | void RasterizerOpenGL::CheckAlphaTests() { |
| 1183 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; | 1193 | const auto& regs = Core::System::GetInstance().GPU().Maxwell3D().regs; |
| 1184 | 1194 | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index f4354289c..dfb4616f2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -183,6 +183,9 @@ private: | |||
| 183 | /// Syncs Color Mask | 183 | /// Syncs Color Mask |
| 184 | void SyncColorMask(); | 184 | void SyncColorMask(); |
| 185 | 185 | ||
| 186 | /// Syncs the polygon offsets | ||
| 187 | void SyncPolygonOffset(); | ||
| 188 | |||
| 186 | /// Check asserts for alpha testing. | 189 | /// Check asserts for alpha testing. |
| 187 | void CheckAlphaTests(); | 190 | void CheckAlphaTests(); |
| 188 | 191 | ||
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 934f4db78..b3bfad6a0 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp | |||
| @@ -92,6 +92,13 @@ OpenGLState::OpenGLState() { | |||
| 92 | 92 | ||
| 93 | point.size = 1; | 93 | point.size = 1; |
| 94 | fragment_color_clamp.enabled = false; | 94 | fragment_color_clamp.enabled = false; |
| 95 | |||
| 96 | polygon_offset.fill_enable = false; | ||
| 97 | polygon_offset.line_enable = false; | ||
| 98 | polygon_offset.point_enable = false; | ||
| 99 | polygon_offset.factor = 0.0f; | ||
| 100 | polygon_offset.units = 0.0f; | ||
| 101 | polygon_offset.clamp = 0.0f; | ||
| 95 | } | 102 | } |
| 96 | 103 | ||
| 97 | void OpenGLState::ApplyDefaultState() { | 104 | void OpenGLState::ApplyDefaultState() { |
| @@ -406,6 +413,55 @@ void OpenGLState::ApplyLogicOp() const { | |||
| 406 | } | 413 | } |
| 407 | } | 414 | } |
| 408 | 415 | ||
| 416 | void OpenGLState::ApplyPolygonOffset() const { | ||
| 417 | |||
| 418 | const bool fill_enable_changed = | ||
| 419 | polygon_offset.fill_enable != cur_state.polygon_offset.fill_enable; | ||
| 420 | const bool line_enable_changed = | ||
| 421 | polygon_offset.line_enable != cur_state.polygon_offset.line_enable; | ||
| 422 | const bool point_enable_changed = | ||
| 423 | polygon_offset.point_enable != cur_state.polygon_offset.point_enable; | ||
| 424 | const bool factor_changed = polygon_offset.factor != cur_state.polygon_offset.factor; | ||
| 425 | const bool units_changed = polygon_offset.units != cur_state.polygon_offset.units; | ||
| 426 | const bool clamp_changed = polygon_offset.clamp != cur_state.polygon_offset.clamp; | ||
| 427 | |||
| 428 | if (fill_enable_changed) { | ||
| 429 | if (polygon_offset.fill_enable) { | ||
| 430 | glEnable(GL_POLYGON_OFFSET_FILL); | ||
| 431 | } else { | ||
| 432 | glDisable(GL_POLYGON_OFFSET_FILL); | ||
| 433 | } | ||
| 434 | } | ||
| 435 | |||
| 436 | if (line_enable_changed) { | ||
| 437 | if (polygon_offset.line_enable) { | ||
| 438 | glEnable(GL_POLYGON_OFFSET_LINE); | ||
| 439 | } else { | ||
| 440 | glDisable(GL_POLYGON_OFFSET_LINE); | ||
| 441 | } | ||
| 442 | } | ||
| 443 | |||
| 444 | if (point_enable_changed) { | ||
| 445 | if (polygon_offset.point_enable) { | ||
| 446 | glEnable(GL_POLYGON_OFFSET_POINT); | ||
| 447 | } else { | ||
| 448 | glDisable(GL_POLYGON_OFFSET_POINT); | ||
| 449 | } | ||
| 450 | } | ||
| 451 | |||
| 452 | if ((polygon_offset.fill_enable || polygon_offset.line_enable || polygon_offset.point_enable) && | ||
| 453 | (factor_changed || units_changed || clamp_changed)) { | ||
| 454 | |||
| 455 | if (GLAD_GL_EXT_polygon_offset_clamp && polygon_offset.clamp != 0) { | ||
| 456 | glPolygonOffsetClamp(polygon_offset.factor, polygon_offset.units, polygon_offset.clamp); | ||
| 457 | } else { | ||
| 458 | glPolygonOffset(polygon_offset.factor, polygon_offset.units); | ||
| 459 | UNIMPLEMENTED_IF_MSG(polygon_offset.clamp != 0, | ||
| 460 | "Unimplemented Depth polygon offset clamp."); | ||
| 461 | } | ||
| 462 | } | ||
| 463 | } | ||
| 464 | |||
| 409 | void OpenGLState::ApplyTextures() const { | 465 | void OpenGLState::ApplyTextures() const { |
| 410 | for (std::size_t i = 0; i < std::size(texture_units); ++i) { | 466 | for (std::size_t i = 0; i < std::size(texture_units); ++i) { |
| 411 | const auto& texture_unit = texture_units[i]; | 467 | const auto& texture_unit = texture_units[i]; |
| @@ -532,6 +588,7 @@ void OpenGLState::Apply() const { | |||
| 532 | ApplyLogicOp(); | 588 | ApplyLogicOp(); |
| 533 | ApplyTextures(); | 589 | ApplyTextures(); |
| 534 | ApplySamplers(); | 590 | ApplySamplers(); |
| 591 | ApplyPolygonOffset(); | ||
| 535 | cur_state = *this; | 592 | cur_state = *this; |
| 536 | } | 593 | } |
| 537 | 594 | ||
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 032fc43f0..0bf19ed07 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h | |||
| @@ -176,6 +176,15 @@ public: | |||
| 176 | float size; // GL_POINT_SIZE | 176 | float size; // GL_POINT_SIZE |
| 177 | } point; | 177 | } point; |
| 178 | 178 | ||
| 179 | struct { | ||
| 180 | bool point_enable; | ||
| 181 | bool line_enable; | ||
| 182 | bool fill_enable; | ||
| 183 | GLfloat units; | ||
| 184 | GLfloat factor; | ||
| 185 | GLfloat clamp; | ||
| 186 | } polygon_offset; | ||
| 187 | |||
| 179 | std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE | 188 | std::array<bool, 2> clip_distance; // GL_CLIP_DISTANCE |
| 180 | 189 | ||
| 181 | OpenGLState(); | 190 | OpenGLState(); |
| @@ -226,6 +235,7 @@ private: | |||
| 226 | void ApplyLogicOp() const; | 235 | void ApplyLogicOp() const; |
| 227 | void ApplyTextures() const; | 236 | void ApplyTextures() const; |
| 228 | void ApplySamplers() const; | 237 | void ApplySamplers() const; |
| 238 | void ApplyPolygonOffset() const; | ||
| 229 | }; | 239 | }; |
| 230 | 240 | ||
| 231 | } // namespace OpenGL | 241 | } // namespace OpenGL |