mirror of
https://github.com/brl/mutter.git
synced 2025-02-15 12:54:10 +00:00
[clip-stack] Internally track model space clip rects as (x0,y0)(x1,y1) pairs
Don't track the rectangles as x0,y0,width,height. This is in preparation for some API tidy up.
This commit is contained in:
parent
7752ed98f1
commit
6cd49fdd40
@ -66,10 +66,10 @@ struct _CoglClipStackEntryRect
|
|||||||
CoglClipStackEntryType type;
|
CoglClipStackEntryType type;
|
||||||
|
|
||||||
/* The rectangle for this clip */
|
/* The rectangle for this clip */
|
||||||
float x_offset;
|
float x0;
|
||||||
float y_offset;
|
float y0;
|
||||||
float width;
|
float x1;
|
||||||
float height;
|
float y1;
|
||||||
|
|
||||||
/* The matrix that was current when the clip was set */
|
/* The matrix that was current when the clip was set */
|
||||||
CoglMatrix matrix;
|
CoglMatrix matrix;
|
||||||
@ -178,10 +178,10 @@ set_clip_plane (GLint plane_num,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_clip_planes (float x_offset,
|
set_clip_planes (float x_1,
|
||||||
float y_offset,
|
float y_1,
|
||||||
float width,
|
float x_2,
|
||||||
float height)
|
float y_2)
|
||||||
{
|
{
|
||||||
CoglHandle draw_buffer = _cogl_get_draw_buffer ();
|
CoglHandle draw_buffer = _cogl_get_draw_buffer ();
|
||||||
CoglMatrixStack *modelview_stack =
|
CoglMatrixStack *modelview_stack =
|
||||||
@ -191,11 +191,10 @@ set_clip_planes (float x_offset,
|
|||||||
_cogl_draw_buffer_get_projection_stack (draw_buffer);
|
_cogl_draw_buffer_get_projection_stack (draw_buffer);
|
||||||
CoglMatrix projection_matrix;
|
CoglMatrix projection_matrix;
|
||||||
|
|
||||||
float vertex_tl[4] = { x_offset, y_offset, 0, 1.0 };
|
float vertex_tl[4] = { x_1, y_1, 0, 1.0 };
|
||||||
float vertex_tr[4] = { x_offset + width, y_offset, 0, 1.0 };
|
float vertex_tr[4] = { x_2, y_1, 0, 1.0 };
|
||||||
float vertex_bl[4] = { x_offset, y_offset + height, 0, 1.0 };
|
float vertex_bl[4] = { x_1, y_2, 0, 1.0 };
|
||||||
float vertex_br[4] = { x_offset + width, y_offset + height,
|
float vertex_br[4] = { x_2, y_2, 0, 1.0 };
|
||||||
0, 1.0 };
|
|
||||||
|
|
||||||
_cogl_matrix_stack_get (projection_stack, &projection_matrix);
|
_cogl_matrix_stack_get (projection_stack, &projection_matrix);
|
||||||
_cogl_matrix_stack_get (modelview_stack, &modelview_matrix);
|
_cogl_matrix_stack_get (modelview_stack, &modelview_matrix);
|
||||||
@ -229,10 +228,10 @@ set_clip_planes (float x_offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
add_stencil_clip_rectangle (float x_offset,
|
add_stencil_clip_rectangle (float x_1,
|
||||||
float y_offset,
|
float y_1,
|
||||||
float width,
|
float x_2,
|
||||||
float height,
|
float y_2,
|
||||||
gboolean first)
|
gboolean first)
|
||||||
{
|
{
|
||||||
CoglHandle current_source;
|
CoglHandle current_source;
|
||||||
@ -262,8 +261,7 @@ add_stencil_clip_rectangle (float x_offset,
|
|||||||
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
|
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
|
||||||
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
|
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
|
||||||
|
|
||||||
cogl_rectangle (x_offset, y_offset,
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
||||||
x_offset + width, y_offset + height);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -276,8 +274,7 @@ add_stencil_clip_rectangle (float x_offset,
|
|||||||
rectangle */
|
rectangle */
|
||||||
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
|
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
|
||||||
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
|
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
|
||||||
cogl_rectangle (x_offset, y_offset,
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
||||||
x_offset + width, y_offset + height);
|
|
||||||
|
|
||||||
/* make sure our rectangle hits the stencil buffer before we
|
/* make sure our rectangle hits the stencil buffer before we
|
||||||
* change the stencil operation */
|
* change the stencil operation */
|
||||||
@ -441,18 +438,14 @@ transform_point (CoglMatrix *matrix_mv,
|
|||||||
/* Try to push a rectangle given in object coordinates as a rectangle in window
|
/* Try to push a rectangle given in object coordinates as a rectangle in window
|
||||||
* coordinates instead of object coordinates */
|
* coordinates instead of object coordinates */
|
||||||
gboolean
|
gboolean
|
||||||
try_pushing_rect_as_window_rect (float x_offset,
|
try_pushing_rect_as_window_rect (float x_1,
|
||||||
float y_offset,
|
float y_1,
|
||||||
float width,
|
float x_2,
|
||||||
float height)
|
float y_2)
|
||||||
{
|
{
|
||||||
CoglMatrix matrix;
|
CoglMatrix matrix;
|
||||||
CoglMatrix matrix_p;
|
CoglMatrix matrix_p;
|
||||||
float v[4];
|
float v[4];
|
||||||
float _x0 = x_offset;
|
|
||||||
float _y0 = y_offset;
|
|
||||||
float _x1 = x_offset + width;
|
|
||||||
float _y1 = y_offset + height;
|
|
||||||
|
|
||||||
cogl_get_modelview_matrix (&matrix);
|
cogl_get_modelview_matrix (&matrix);
|
||||||
|
|
||||||
@ -473,27 +466,27 @@ try_pushing_rect_as_window_rect (float x_offset,
|
|||||||
cogl_get_projection_matrix (&matrix_p);
|
cogl_get_projection_matrix (&matrix_p);
|
||||||
cogl_get_viewport (v);
|
cogl_get_viewport (v);
|
||||||
|
|
||||||
transform_point (&matrix, &matrix_p, v, &_x0, &_y0);
|
transform_point (&matrix, &matrix_p, v, &x_1, &y_1);
|
||||||
transform_point (&matrix, &matrix_p, v, &_x1, &_y1);
|
transform_point (&matrix, &matrix_p, v, &x_2, &y_2);
|
||||||
|
|
||||||
/* Consider that the modelview matrix may flip the rectangle
|
/* Consider that the modelview matrix may flip the rectangle
|
||||||
* along the x or y axis... */
|
* along the x or y axis... */
|
||||||
#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0)
|
#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0)
|
||||||
if (_x0 > _x1)
|
if (x_1 > x_2)
|
||||||
SWAP (_x0, _x1);
|
SWAP (x_1, x_2);
|
||||||
if (_y0 > _y1)
|
if (y_1 > y_2)
|
||||||
SWAP (_y0, _y1);
|
SWAP (y_1, y_2);
|
||||||
#undef SWAP
|
#undef SWAP
|
||||||
|
|
||||||
cogl_clip_push_window_rect (_x0, _y0, _x1 - _x0, _y1 - _y0);
|
cogl_clip_push_window_rect (x_1, y_1, x_2 - x_1, y_2 - y_1);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
cogl_clip_push (float x_offset,
|
_cogl_clip_push_rectangle (float x_1,
|
||||||
float y_offset,
|
float y_1,
|
||||||
float width,
|
float x_2,
|
||||||
float height)
|
float y_2)
|
||||||
{
|
{
|
||||||
CoglHandle draw_buffer;
|
CoglHandle draw_buffer;
|
||||||
CoglClipStackState *clip_state;
|
CoglClipStackState *clip_state;
|
||||||
@ -508,7 +501,7 @@ cogl_clip_push (float x_offset,
|
|||||||
|
|
||||||
/* Try and catch window space rectangles so we can redirect to
|
/* Try and catch window space rectangles so we can redirect to
|
||||||
* cogl_clip_push_window_rect which will use scissoring. */
|
* cogl_clip_push_window_rect which will use scissoring. */
|
||||||
if (try_pushing_rect_as_window_rect (x_offset, y_offset, width, height))
|
if (try_pushing_rect_as_window_rect (x_1, y_1, x_2, y_2))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
draw_buffer = _cogl_get_draw_buffer ();
|
draw_buffer = _cogl_get_draw_buffer ();
|
||||||
@ -520,10 +513,10 @@ cogl_clip_push (float x_offset,
|
|||||||
|
|
||||||
/* Make a new entry */
|
/* Make a new entry */
|
||||||
entry->type = COGL_CLIP_STACK_RECT;
|
entry->type = COGL_CLIP_STACK_RECT;
|
||||||
entry->x_offset = x_offset;
|
entry->x0 = x_1;
|
||||||
entry->y_offset = y_offset;
|
entry->y0 = y_1;
|
||||||
entry->width = width;
|
entry->x1 = x_2;
|
||||||
entry->height = height;
|
entry->y1 = y_2;
|
||||||
|
|
||||||
cogl_get_modelview_matrix (&entry->matrix);
|
cogl_get_modelview_matrix (&entry->matrix);
|
||||||
|
|
||||||
@ -533,6 +526,18 @@ cogl_clip_push (float x_offset,
|
|||||||
clip_state->stack_dirty = TRUE;
|
clip_state->stack_dirty = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
cogl_clip_push (float x_offset,
|
||||||
|
float y_offset,
|
||||||
|
float width,
|
||||||
|
float height)
|
||||||
|
{
|
||||||
|
_cogl_clip_push_rectangle (x_offset,
|
||||||
|
y_offset,
|
||||||
|
x_offset + width,
|
||||||
|
y_offset + height);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
cogl_clip_push_from_path_preserve (void)
|
cogl_clip_push_from_path_preserve (void)
|
||||||
{
|
{
|
||||||
@ -707,20 +712,20 @@ _cogl_flush_clip_state (CoglClipStackState *clip_state)
|
|||||||
that instead */
|
that instead */
|
||||||
if (has_clip_planes)
|
if (has_clip_planes)
|
||||||
{
|
{
|
||||||
set_clip_planes (rect->x_offset,
|
set_clip_planes (rect->x0,
|
||||||
rect->y_offset,
|
rect->y0,
|
||||||
rect->width,
|
rect->x1,
|
||||||
rect->height);
|
rect->y1);
|
||||||
using_clip_planes = TRUE;
|
using_clip_planes = TRUE;
|
||||||
/* We can't use clip planes a second time */
|
/* We can't use clip planes a second time */
|
||||||
has_clip_planes = FALSE;
|
has_clip_planes = FALSE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
add_stencil_clip_rectangle (rect->x_offset,
|
add_stencil_clip_rectangle (rect->x0,
|
||||||
rect->y_offset,
|
rect->y0,
|
||||||
rect->width,
|
rect->x1,
|
||||||
rect->height,
|
rect->y1,
|
||||||
!using_stencil_buffer);
|
!using_stencil_buffer);
|
||||||
using_stencil_buffer = TRUE;
|
using_stencil_buffer = TRUE;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user