clip-stack: Adds _cogl_clip_stack_get_bounds API
authorRobert Bragg <robert@linux.intel.com>
Wed, 12 Jan 2011 19:13:45 +0000 (19:13 +0000)
committerRobert Bragg <robert@linux.intel.com>
Fri, 21 Jan 2011 16:18:10 +0000 (16:18 +0000)
This adds an internal function to be able to query the screen space
bounding box of the current clip entries contained in a given
CoglClipStack.

This bounding box which is cheap to determine can be useful to know the
largest extents that might be updated while drawing with this clip
stack.

For example the plan is to use this as part of an optimized read-pixel
path handled on the CPU which will need to track the currently valid
extents of the last call to cogl_clear()

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

index ffc0000..c5e2fe7 100644 (file)
@@ -532,15 +532,40 @@ _cogl_clip_stack_pop (CoglClipStack *stack)
 }
 
 void
+_cogl_clip_stack_get_bounds (CoglClipStack *stack,
+                             int *scissor_x0,
+                             int *scissor_y0,
+                             int *scissor_x1,
+                             int *scissor_y1)
+{
+  CoglClipStack *entry;
+
+  *scissor_x0 = 0;
+  *scissor_y0 = 0;
+  *scissor_x1 = G_MAXINT;
+  *scissor_y1 = G_MAXINT;
+
+  for (entry = stack; entry; entry = entry->parent)
+    {
+      /* Get the intersection of the current scissor and the bounding
+         box of this clip */
+      *scissor_x0 = MAX (*scissor_x0, entry->bounds_x0);
+      *scissor_y0 = MAX (*scissor_y0, entry->bounds_y0);
+      *scissor_x1 = MIN (*scissor_x1, entry->bounds_x1);
+      *scissor_y1 = MIN (*scissor_y1, entry->bounds_y1);
+    }
+}
+
+void
 _cogl_clip_stack_flush (CoglClipStack *stack)
 {
   int has_clip_planes;
   gboolean using_clip_planes = FALSE;
   gboolean using_stencil_buffer = FALSE;
-  int scissor_x0 = 0;
-  int scissor_y0 = 0;
-  int scissor_x1 = G_MAXINT;
-  int scissor_y1 = G_MAXINT;
+  int scissor_x0;
+  int scissor_y0;
+  int scissor_x1;
+  int scissor_y1;
   CoglMatrixStack *modelview_stack;
   CoglClipStack *entry;
   int scissor_y_start;
@@ -581,15 +606,9 @@ _cogl_clip_stack_flush (CoglClipStack *stack)
      clear the stencil buffer then the clear will be clipped to the
      intersection of all of the bounding boxes. This saves having to
      clear the whole stencil buffer */
-  for (entry = stack; entry; entry = entry->parent)
-    {
-      /* Get the intersection of the current scissor and the bounding
-         box of this clip */
-      scissor_x0 = MAX (scissor_x0, entry->bounds_x0);
-      scissor_y0 = MAX (scissor_y0, entry->bounds_y0);
-      scissor_x1 = MIN (scissor_x1, entry->bounds_x1);
-      scissor_y1 = MIN (scissor_y1, entry->bounds_y1);
-    }
+  _cogl_clip_stack_get_bounds (stack,
+                               &scissor_x0, &scissor_y0,
+                               &scissor_x1, &scissor_y1);
 
   /* Enable scissoring as soon as possible */
   if (scissor_x0 >= scissor_x1 || scissor_y0 >= scissor_y1)
index 2baa4e2..307d7ef 100644 (file)
@@ -171,6 +171,13 @@ CoglClipStack *
 _cogl_clip_stack_pop (CoglClipStack *stack);
 
 void
+_cogl_clip_stack_get_bounds (CoglClipStack *stack,
+                             int *scissor_x0,
+                             int *scissor_y0,
+                             int *scissor_x1,
+                             int *scissor_y1);
+
+void
 _cogl_clip_stack_flush (CoglClipStack *stack);
 
 CoglClipStack *