[Cogl] [PATCH] Fix depth testing, write enable bug

Robert Bragg robert at sixbynine.org
Mon May 14 14:21:18 PDT 2012


From: Robert Bragg <robert at linux.intel.com>

This fixes a bug in _cogl_pipeline_flush_color_blend_alpha_depth_state
whereby we were only calling flush_depth_state if we knew that at least
depth testing was enabled. This didn't take into account that enabling
and disabling depth writing is a useful change to make even if depth
testing is disabled. It also seemed a bit messy to flush the
depth-testing enable separately from the other depth state.

_cogl_pipeline_flush_color_blend_alpha_depth_state now simply calls
flush_depth_state() if there is a _DEPTH_STATE difference and
flush_depth_state() also handles flushing the depth-testing enable
in along with all the other depth state.
---
 cogl/cogl-pipeline-opengl.c |   30 +++++++++++++-----------------
 1 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/cogl/cogl-pipeline-opengl.c b/cogl/cogl-pipeline-opengl.c
index 5341803..a047e81 100644
--- a/cogl/cogl-pipeline-opengl.c
+++ b/cogl/cogl-pipeline-opengl.c
@@ -401,11 +401,20 @@ blend_factor_uses_constant (GLenum blend_factor)
 #endif
 
 static void
-flush_depth_state (CoglDepthState *depth_state)
+flush_depth_state (CoglContext *ctx,
+                   CoglDepthState *depth_state)
 {
-  _COGL_GET_CONTEXT (ctx, NO_RETVAL);
+  if (ctx->depth_test_enabled_cache != depth_state->test_enabled)
+    {
+      if (depth_state->test_enabled == TRUE)
+        GE (ctx, glEnable (GL_DEPTH_TEST));
+      else
+        GE (ctx, glDisable (GL_DEPTH_TEST));
+      ctx->depth_test_enabled_cache = depth_state->test_enabled;
+    }
 
-  if (ctx->depth_test_function_cache != depth_state->test_function)
+  if (ctx->depth_test_function_cache != depth_state->test_function &&
+      depth_state->test_enabled == TRUE)
     {
       GE (ctx, glDepthFunc (depth_state->test_function));
       ctx->depth_test_function_cache = depth_state->test_function;
@@ -571,20 +580,7 @@ _cogl_pipeline_flush_color_blend_alpha_depth_state (
         _cogl_pipeline_get_authority (pipeline, COGL_PIPELINE_STATE_DEPTH);
       CoglDepthState *depth_state = &authority->big_state->depth_state;
 
-      if (depth_state->test_enabled)
-        {
-          if (ctx->depth_test_enabled_cache != TRUE)
-            {
-              GE (ctx, glEnable (GL_DEPTH_TEST));
-              ctx->depth_test_enabled_cache = depth_state->test_enabled;
-            }
-          flush_depth_state (depth_state);
-        }
-      else if (ctx->depth_test_enabled_cache != FALSE)
-        {
-          GE (ctx, glDisable (GL_DEPTH_TEST));
-          ctx->depth_test_enabled_cache = depth_state->test_enabled;
-        }
+      flush_depth_state (ctx, depth_state);
     }
 
   if (pipelines_difference & COGL_PIPELINE_STATE_LOGIC_OPS)
-- 
1.7.7.6



More information about the Cogl mailing list