From cf92670fbbff1fdb70231cb23e4cc891035597b9 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Wed, 12 Jan 2011 19:13:45 +0000 Subject: [PATCH] clip-stack: Adds _cogl_clip_stack_get_bounds API 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() --- cogl/cogl-clip-stack.c | 45 ++++++++++++++++++++++++++++++------------ cogl/cogl-clip-stack.h | 7 +++++++ 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/cogl/cogl-clip-stack.c b/cogl/cogl-clip-stack.c index ffc00003a..c5e2fe79d 100644 --- a/cogl/cogl-clip-stack.c +++ b/cogl/cogl-clip-stack.c @@ -531,16 +531,41 @@ _cogl_clip_stack_pop (CoglClipStack *stack) return new_top; } +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) diff --git a/cogl/cogl-clip-stack.h b/cogl/cogl-clip-stack.h index 2baa4e29b..307d7ef7f 100644 --- a/cogl/cogl-clip-stack.h +++ b/cogl/cogl-clip-stack.h @@ -170,6 +170,13 @@ _cogl_clip_stack_push_from_path (CoglClipStack *stack, 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);