summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/video_core/engines/maxwell_3d.h30
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp12
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h3
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp57
-rw-r--r--src/video_core/renderer_opengl/gl_state.h10
5 files changed, 107 insertions, 5 deletions
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h
index 0c403e16a..286cde201 100644
--- a/src/video_core/engines/maxwell_3d.h
+++ b/src/video_core/engines/maxwell_3d.h
@@ -590,10 +590,18 @@ public:
590 590
591 float clear_color[4]; 591 float clear_color[4];
592 float clear_depth; 592 float clear_depth;
593
593 INSERT_PADDING_WORDS(0x3); 594 INSERT_PADDING_WORDS(0x3);
595
594 s32 clear_stencil; 596 s32 clear_stencil;
595 597
596 INSERT_PADDING_WORDS(0x17); 598 INSERT_PADDING_WORDS(0x7);
599
600 u32 polygon_offset_point_enable;
601 u32 polygon_offset_line_enable;
602 u32 polygon_offset_fill_enable;
603
604 INSERT_PADDING_WORDS(0xD);
597 605
598 std::array<ScissorTest, NumViewports> scissor_test; 606 std::array<ScissorTest, NumViewports> scissor_test;
599 607
@@ -762,7 +770,11 @@ public:
762 } 770 }
763 } tsc; 771 } tsc;
764 772
765 INSERT_PADDING_WORDS(0x3); 773 INSERT_PADDING_WORDS(0x1);
774
775 float polygon_offset_factor;
776
777 INSERT_PADDING_WORDS(0x1);
766 778
767 struct { 779 struct {
768 u32 tic_address_high; 780 u32 tic_address_high;
@@ -787,7 +799,9 @@ public:
787 799
788 u32 framebuffer_srgb; 800 u32 framebuffer_srgb;
789 801
790 INSERT_PADDING_WORDS(0x12); 802 float polygon_offset_units;
803
804 INSERT_PADDING_WORDS(0x11);
791 805
792 union { 806 union {
793 BitField<2, 1, u32> coord_origin; 807 BitField<2, 1, u32> coord_origin;
@@ -864,7 +878,9 @@ public:
864 878
865 INSERT_PADDING_WORDS(0x7); 879 INSERT_PADDING_WORDS(0x7);
866 880
867 INSERT_PADDING_WORDS(0x20); 881 INSERT_PADDING_WORDS(0x1F);
882
883 float polygon_offset_clamp;
868 884
869 struct { 885 struct {
870 u32 is_instanced[NumVertexArrays]; 886 u32 is_instanced[NumVertexArrays];
@@ -1137,6 +1153,9 @@ ASSERT_REG_POSITION(vertex_buffer, 0x35D);
1137ASSERT_REG_POSITION(clear_color[0], 0x360); 1153ASSERT_REG_POSITION(clear_color[0], 0x360);
1138ASSERT_REG_POSITION(clear_depth, 0x364); 1154ASSERT_REG_POSITION(clear_depth, 0x364);
1139ASSERT_REG_POSITION(clear_stencil, 0x368); 1155ASSERT_REG_POSITION(clear_stencil, 0x368);
1156ASSERT_REG_POSITION(polygon_offset_point_enable, 0x370);
1157ASSERT_REG_POSITION(polygon_offset_line_enable, 0x371);
1158ASSERT_REG_POSITION(polygon_offset_fill_enable, 0x372);
1140ASSERT_REG_POSITION(scissor_test, 0x380); 1159ASSERT_REG_POSITION(scissor_test, 0x380);
1141ASSERT_REG_POSITION(stencil_back_func_ref, 0x3D5); 1160ASSERT_REG_POSITION(stencil_back_func_ref, 0x3D5);
1142ASSERT_REG_POSITION(stencil_back_mask, 0x3D6); 1161ASSERT_REG_POSITION(stencil_back_mask, 0x3D6);
@@ -1175,6 +1194,7 @@ ASSERT_REG_POSITION(point_size, 0x546);
1175ASSERT_REG_POSITION(zeta_enable, 0x54E); 1194ASSERT_REG_POSITION(zeta_enable, 0x54E);
1176ASSERT_REG_POSITION(multisample_control, 0x54F); 1195ASSERT_REG_POSITION(multisample_control, 0x54F);
1177ASSERT_REG_POSITION(tsc, 0x557); 1196ASSERT_REG_POSITION(tsc, 0x557);
1197ASSERT_REG_POSITION(polygon_offset_factor, 0x55b);
1178ASSERT_REG_POSITION(tic, 0x55D); 1198ASSERT_REG_POSITION(tic, 0x55D);
1179ASSERT_REG_POSITION(stencil_two_side_enable, 0x565); 1199ASSERT_REG_POSITION(stencil_two_side_enable, 0x565);
1180ASSERT_REG_POSITION(stencil_back_op_fail, 0x566); 1200ASSERT_REG_POSITION(stencil_back_op_fail, 0x566);
@@ -1182,11 +1202,13 @@ ASSERT_REG_POSITION(stencil_back_op_zfail, 0x567);
1182ASSERT_REG_POSITION(stencil_back_op_zpass, 0x568); 1202ASSERT_REG_POSITION(stencil_back_op_zpass, 0x568);
1183ASSERT_REG_POSITION(stencil_back_func_func, 0x569); 1203ASSERT_REG_POSITION(stencil_back_func_func, 0x569);
1184ASSERT_REG_POSITION(framebuffer_srgb, 0x56E); 1204ASSERT_REG_POSITION(framebuffer_srgb, 0x56E);
1205ASSERT_REG_POSITION(polygon_offset_units, 0x56F);
1185ASSERT_REG_POSITION(point_coord_replace, 0x581); 1206ASSERT_REG_POSITION(point_coord_replace, 0x581);
1186ASSERT_REG_POSITION(code_address, 0x582); 1207ASSERT_REG_POSITION(code_address, 0x582);
1187ASSERT_REG_POSITION(draw, 0x585); 1208ASSERT_REG_POSITION(draw, 0x585);
1188ASSERT_REG_POSITION(primitive_restart, 0x591); 1209ASSERT_REG_POSITION(primitive_restart, 0x591);
1189ASSERT_REG_POSITION(index_array, 0x5F2); 1210ASSERT_REG_POSITION(index_array, 0x5F2);
1211ASSERT_REG_POSITION(polygon_offset_clamp, 0x61F);
1190ASSERT_REG_POSITION(instanced_arrays, 0x620); 1212ASSERT_REG_POSITION(instanced_arrays, 0x620);
1191ASSERT_REG_POSITION(cull, 0x646); 1213ASSERT_REG_POSITION(cull, 0x646);
1192ASSERT_REG_POSITION(logic_op, 0x671); 1214ASSERT_REG_POSITION(logic_op, 0x671);
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
1182void 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
1182void RasterizerOpenGL::CheckAlphaTests() { 1192void 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
97void OpenGLState::ApplyDefaultState() { 104void OpenGLState::ApplyDefaultState() {
@@ -406,6 +413,55 @@ void OpenGLState::ApplyLogicOp() const {
406 } 413 }
407} 414}
408 415
416void 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
409void OpenGLState::ApplyTextures() const { 465void 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