Просмотр исходного кода

gl_state_tracker: Implement depth dirty flags

ReinUsesLisp 6 лет назад
Родитель
Сommit
40a2c57df5

+ 15 - 5
src/video_core/renderer_opengl/gl_rasterizer.cpp

@@ -1024,13 +1024,23 @@ void RasterizerOpenGL::SyncPrimitiveRestart() {
 }
 }
 
 
 void RasterizerOpenGL::SyncDepthTestState() {
 void RasterizerOpenGL::SyncDepthTestState() {
-    const auto& regs = system.GPU().Maxwell3D().regs;
+    auto& gpu = system.GPU().Maxwell3D();
+    auto& flags = gpu.dirty.flags;
 
 
-    glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE);
+    const auto& regs = gpu.regs;
+    if (flags[Dirty::DepthMask]) {
+        flags[Dirty::DepthMask] = false;
+        glDepthMask(regs.depth_write_enabled ? GL_TRUE : GL_FALSE);
+    }
 
 
-    oglEnable(GL_DEPTH_TEST, regs.depth_test_enable);
-    if (regs.depth_test_enable) {
-        glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func));
+    if (flags[Dirty::DepthTest]) {
+        flags[Dirty::DepthTest] = false;
+        if (regs.depth_test_enable) {
+            glEnable(GL_DEPTH_TEST);
+            glDepthFunc(MaxwellToGL::ComparisonOp(regs.depth_test_func));
+        } else {
+            glDisable(GL_DEPTH_TEST);
+        }
     }
     }
 }
 }
 
 

+ 8 - 0
src/video_core/renderer_opengl/gl_state_tracker.cpp

@@ -129,6 +129,13 @@ void SetupDirtyShaders(Tables& tables) {
               Shaders);
               Shaders);
 }
 }
 
 
+void SetupDirtyDepthTest(Tables& tables) {
+    auto& table = tables[0];
+    table[OFF(depth_test_enable)] = DepthTest;
+    table[OFF(depth_write_enabled)] = DepthMask;
+    table[OFF(depth_test_func)] = DepthTest;
+}
+
 void SetupDirtyBlend(Tables& tables) {
 void SetupDirtyBlend(Tables& tables) {
     FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendColor);
     FillBlock(tables[0], OFF(blend_color), NUM(blend_color), BlendColor);
 
 
@@ -169,6 +176,7 @@ void StateTracker::Initialize() {
     SetupDirtyVertexArrays(tables);
     SetupDirtyVertexArrays(tables);
     SetupDirtyVertexFormat(tables);
     SetupDirtyVertexFormat(tables);
     SetupDirtyShaders(tables);
     SetupDirtyShaders(tables);
+    SetupDirtyDepthTest(tables);
     SetupDirtyBlend(tables);
     SetupDirtyBlend(tables);
     SetupDirtyMisc(tables);
     SetupDirtyMisc(tables);
 
 

+ 7 - 1
src/video_core/renderer_opengl/gl_state_tracker.h

@@ -58,8 +58,9 @@ enum : u8 {
 
 
     FrontFace,
     FrontFace,
     CullTest,
     CullTest,
-    PrimitiveRestart,
+    DepthMask,
     DepthTest,
     DepthTest,
+    PrimitiveRestart,
     StencilTest,
     StencilTest,
     ColorMask,
     ColorMask,
     PolygonOffset,
     PolygonOffset,
@@ -129,6 +130,11 @@ public:
         flags[OpenGL::Dirty::CullTest] = true;
         flags[OpenGL::Dirty::CullTest] = true;
     }
     }
 
 
+    void NotifyDepthTest() {
+        auto& flags = system.GPU().Maxwell3D().dirty.flags;
+        flags[OpenGL::Dirty::DepthTest] = true;
+    }
+
 private:
 private:
     Core::System& system;
     Core::System& system;
 };
 };

+ 1 - 0
src/video_core/renderer_opengl/renderer_opengl.cpp

@@ -584,6 +584,7 @@ void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
     state_tracker.NotifyFramebuffer();
     state_tracker.NotifyFramebuffer();
     state_tracker.NotifyFrontFace();
     state_tracker.NotifyFrontFace();
     state_tracker.NotifyCullTest();
     state_tracker.NotifyCullTest();
+    state_tracker.NotifyDepthTest();
 
 
     program_manager.UseVertexShader(vertex_program.handle);
     program_manager.UseVertexShader(vertex_program.handle);
     program_manager.UseGeometryShader(0);
     program_manager.UseGeometryShader(0);