cogl-clip-stack: Fix flushing multiple stencil rectangles
authorNeil Roberts <neil@linux.intel.com>
Mon, 24 Jan 2011 17:32:06 +0000 (17:32 +0000)
committerNeil Roberts <neil@linux.intel.com>
Mon, 24 Jan 2011 17:40:07 +0000 (17:40 +0000)
When flushing a clip stack that contains more than one rectangle which
needs to use the stencil buffer the code takes a different path so
that it can combine the new rectangle with the existing contents of
the stencil buffer. However it was not correctly flushing the
modelview and projection matrices so that rectangle would be in the
wrong place.

clutter/cogl/cogl/cogl-clip-stack.c

index 082d623..ef0313b 100644 (file)
@@ -203,6 +203,14 @@ add_stencil_clip_rectangle (float x_1,
   /* temporarily swap in our special stenciling pipeline */
   cogl_push_source (ctx->stencil_pipeline);
 
+  /* This can be called from the journal code which doesn't flush
+     the matrix stacks between calls so we need to ensure they're
+     flushed now */
+  _cogl_matrix_stack_flush_to_gl (modelview_stack,
+                                  COGL_MATRIX_MODELVIEW);
+  _cogl_matrix_stack_flush_to_gl (projection_stack,
+                                  COGL_MATRIX_PROJECTION);
+
   if (first)
     {
       GE( glEnable (GL_STENCIL_TEST) );
@@ -215,14 +223,6 @@ add_stencil_clip_rectangle (float x_1,
       GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
       GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
 
-      /* This can be called from the journal code which doesn't flush
-         the matrix stacks between calls so we need to ensure they're
-         flushed now */
-      _cogl_matrix_stack_flush_to_gl (modelview_stack,
-                                      COGL_MATRIX_MODELVIEW);
-      _cogl_matrix_stack_flush_to_gl (projection_stack,
-                                      COGL_MATRIX_PROJECTION);
-
       _cogl_rectangle_immediate (x_1, y_1, x_2, y_2);
     }
   else