2008-06-23 10:57:36 -04:00
|
|
|
/*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Cogl
|
2008-06-23 10:57:36 -04:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-06-23 10:57:36 -04:00
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
* Copyright (C) 2007,2008,2009 Intel Corporation.
|
2008-06-23 10:57:36 -04:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
#include <string.h>
|
2009-05-08 11:32:01 -04:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-clip-stack.h"
|
2008-12-04 08:45:09 -05:00
|
|
|
#include "cogl-primitives.h"
|
|
|
|
#include "cogl-context.h"
|
2009-05-08 11:32:01 -04:00
|
|
|
#include "cogl-internal.h"
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
/* These are defined in the particular backend (float in GL vs fixed
|
|
|
|
in GL ES) */
|
2009-01-20 11:20:54 -05:00
|
|
|
void _cogl_set_clip_planes (float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height);
|
|
|
|
void _cogl_add_stencil_clip (float x,
|
|
|
|
float y,
|
|
|
|
float width,
|
|
|
|
float height,
|
2008-06-23 10:57:36 -04:00
|
|
|
gboolean first);
|
2009-01-20 11:20:54 -05:00
|
|
|
void _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
|
|
|
|
floatVec2 nodes_max,
|
2008-12-04 08:45:09 -05:00
|
|
|
guint path_size,
|
|
|
|
CoglPathNode *path,
|
|
|
|
gboolean merge);
|
|
|
|
void _cogl_enable_clip_planes (void);
|
2008-06-23 10:57:36 -04:00
|
|
|
void _cogl_disable_clip_planes (void);
|
|
|
|
void _cogl_disable_stencil_buffer (void);
|
2009-02-18 13:54:54 -05:00
|
|
|
void _cogl_set_matrix (const CoglMatrix *matrix);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
typedef struct _CoglClipStack CoglClipStack;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
typedef struct _CoglClipStackEntryRect CoglClipStackEntryRect;
|
2009-05-08 11:32:01 -04:00
|
|
|
typedef struct _CoglClipStackEntryWindowRect CoglClipStackEntryWindowRect;
|
2008-12-04 08:45:09 -05:00
|
|
|
typedef struct _CoglClipStackEntryPath CoglClipStackEntryPath;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COGL_CLIP_STACK_RECT,
|
2009-05-08 11:32:01 -04:00
|
|
|
COGL_CLIP_STACK_WINDOW_RECT,
|
2008-12-04 08:45:09 -05:00
|
|
|
COGL_CLIP_STACK_PATH
|
|
|
|
} CoglClipStackEntryType;
|
|
|
|
|
|
|
|
struct _CoglClipStack
|
|
|
|
{
|
|
|
|
GList *stack_top;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _CoglClipStackEntryRect
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStackEntryType type;
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
/* The rectangle for this clip */
|
2009-01-20 11:20:54 -05:00
|
|
|
float x_offset;
|
|
|
|
float y_offset;
|
|
|
|
float width;
|
|
|
|
float height;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
/* The matrix that was current when the clip was set */
|
2009-02-18 13:54:54 -05:00
|
|
|
CoglMatrix matrix;
|
2008-06-23 10:57:36 -04:00
|
|
|
};
|
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
struct _CoglClipStackEntryWindowRect
|
|
|
|
{
|
|
|
|
CoglClipStackEntryType type;
|
|
|
|
|
|
|
|
/* The window space rectangle for this clip */
|
|
|
|
float x0;
|
|
|
|
float y0;
|
|
|
|
float x1;
|
|
|
|
float y1;
|
|
|
|
};
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
struct _CoglClipStackEntryPath
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStackEntryType type;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
/* The matrix that was current when the clip was set */
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglMatrix matrix;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-01-20 11:20:54 -05:00
|
|
|
floatVec2 path_nodes_min;
|
|
|
|
floatVec2 path_nodes_max;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
guint path_size;
|
|
|
|
CoglPathNode path[1];
|
2008-12-04 08:45:09 -05:00
|
|
|
};
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
void
|
|
|
|
cogl_clip_push_window_rect (float x_offset,
|
|
|
|
float y_offset,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
|
|
|
CoglClipStackEntryWindowRect *entry;
|
|
|
|
CoglClipStack *stack;
|
|
|
|
float v[4];
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
|
|
|
|
|
|
|
cogl_get_viewport (v);
|
|
|
|
|
|
|
|
entry = g_slice_new (CoglClipStackEntryWindowRect);
|
|
|
|
|
|
|
|
/* We convert from coords with (0,0) at top left to coords
|
|
|
|
* with (0,0) at bottom left. */
|
|
|
|
entry->type = COGL_CLIP_STACK_WINDOW_RECT;
|
|
|
|
entry->x0 = x_offset;
|
|
|
|
entry->y0 = v[3] - y_offset - height;
|
|
|
|
entry->x1 = x_offset + width;
|
|
|
|
entry->y1 = v[3] - y_offset;
|
|
|
|
|
|
|
|
/* Store it in the stack */
|
|
|
|
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
|
|
|
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Scale from OpenGL <-1,1> coordinates system to window coordinates
|
|
|
|
* <0,window-size> with (0,0) being top left. */
|
|
|
|
#define VIEWPORT_SCALE_X(x, w, width, origin) \
|
|
|
|
((((((x) / (w)) + 1.0) / 2) * (width)) + (origin))
|
|
|
|
#define VIEWPORT_SCALE_Y(y, w, height, origin) \
|
|
|
|
((height) - (((((y) / (w)) + 1.0) / 2) * (height)) + (origin))
|
|
|
|
|
|
|
|
static void
|
|
|
|
transform_point (CoglMatrix *matrix_mv,
|
|
|
|
CoglMatrix *matrix_p,
|
|
|
|
float *viewport,
|
|
|
|
float *x,
|
|
|
|
float *y)
|
|
|
|
{
|
|
|
|
float z = 0;
|
|
|
|
float w = 1;
|
|
|
|
|
|
|
|
/* Apply the model view matrix */
|
|
|
|
cogl_matrix_transform_point (matrix_mv, x, y, &z, &w);
|
|
|
|
|
|
|
|
/* Apply the projection matrix */
|
|
|
|
cogl_matrix_transform_point (matrix_p, x, y, &z, &w);
|
|
|
|
/* Apply viewport transform */
|
|
|
|
*x = VIEWPORT_SCALE_X (*x, w, viewport[2], viewport[0]);
|
|
|
|
*y = VIEWPORT_SCALE_Y (*y, w, viewport[3], viewport[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef VIEWPORT_SCALE_X
|
|
|
|
#undef VIEWPORT_SCALE_Y
|
|
|
|
|
|
|
|
/* Try to push a rectangle given in object coordinates as a rectangle in window
|
|
|
|
* coordinates instead of object coordinates */
|
|
|
|
gboolean
|
|
|
|
try_pushing_rect_as_window_rect (float x_offset,
|
|
|
|
float y_offset,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
|
|
|
CoglMatrix matrix;
|
|
|
|
CoglMatrix matrix_p;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (matrix.xy != 0 || matrix.xz != 0 ||
|
|
|
|
matrix.yx != 0 || matrix.yz != 0 ||
|
|
|
|
matrix.zx != 0 || matrix.zy != 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
cogl_get_projection_matrix (&matrix_p);
|
|
|
|
cogl_get_viewport (v);
|
|
|
|
|
|
|
|
transform_point (&matrix, &matrix_p, v, &_x0, &_y0);
|
|
|
|
transform_point (&matrix, &matrix_p, v, &_x1, &_y1);
|
|
|
|
|
|
|
|
cogl_clip_push_window_rect (_x0, _y0, _x1 - _x0, _y1 - _y0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
void
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_push (float x_offset,
|
|
|
|
float y_offset,
|
|
|
|
float width,
|
|
|
|
float height)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStackEntryRect *entry;
|
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
/* Try and catch window space rectangles so we can redirect to
|
|
|
|
* cogl_clip_push_window_rect which will use scissoring. */
|
|
|
|
if (try_pushing_rect_as_window_rect (x_offset, y_offset, width, height))
|
|
|
|
return;
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
|
|
|
|
|
|
|
entry = g_slice_new (CoglClipStackEntryRect);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
/* Make a new entry */
|
2008-12-04 08:45:09 -05:00
|
|
|
entry->type = COGL_CLIP_STACK_RECT;
|
2008-06-23 10:57:36 -04:00
|
|
|
entry->x_offset = x_offset;
|
|
|
|
entry->y_offset = y_offset;
|
|
|
|
entry->width = width;
|
|
|
|
entry->height = height;
|
|
|
|
|
2009-02-18 13:54:54 -05:00
|
|
|
cogl_get_modelview_matrix (&entry->matrix);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
/* Store it in the stack */
|
|
|
|
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
|
|
|
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_push_from_path_preserve (void)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
|
|
|
CoglClipStackEntryPath *entry;
|
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
|
|
|
|
|
|
|
entry = g_malloc (sizeof (CoglClipStackEntryPath)
|
|
|
|
+ sizeof (CoglPathNode) * (ctx->path_nodes->len - 1));
|
|
|
|
|
|
|
|
entry->type = COGL_CLIP_STACK_PATH;
|
|
|
|
entry->path_nodes_min = ctx->path_nodes_min;
|
|
|
|
entry->path_nodes_max = ctx->path_nodes_max;
|
|
|
|
entry->path_size = ctx->path_nodes->len;
|
|
|
|
memcpy (entry->path, ctx->path_nodes->data,
|
|
|
|
sizeof (CoglPathNode) * ctx->path_nodes->len);
|
|
|
|
|
2009-02-18 13:54:54 -05:00
|
|
|
cogl_get_modelview_matrix (&entry->matrix);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
/* Store it in the stack */
|
2008-12-04 08:45:09 -05:00
|
|
|
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
|
|
|
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_push_from_path (void)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_push_from_path_preserve ();
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
cogl_path_new ();
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_pop (void)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
gpointer entry;
|
|
|
|
CoglClipStack *stack;
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStackEntryType type;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
|
|
|
|
|
|
|
g_return_if_fail (stack->stack_top != NULL);
|
|
|
|
|
|
|
|
entry = stack->stack_top->data;
|
2009-05-08 11:32:01 -04:00
|
|
|
type = *(CoglClipStackEntryType *) entry;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
/* Remove the top entry from the stack */
|
2009-05-08 11:32:01 -04:00
|
|
|
if (type == COGL_CLIP_STACK_RECT)
|
2008-12-04 08:45:09 -05:00
|
|
|
g_slice_free (CoglClipStackEntryRect, entry);
|
2009-05-08 11:32:01 -04:00
|
|
|
else if (type == COGL_CLIP_STACK_WINDOW_RECT)
|
|
|
|
g_slice_free (CoglClipStackEntryWindowRect, entry);
|
2008-12-04 08:45:09 -05:00
|
|
|
else
|
|
|
|
g_free (entry);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
stack->stack_top = g_list_delete_link (stack->stack_top,
|
|
|
|
stack->stack_top);
|
|
|
|
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-04 08:45:09 -05:00
|
|
|
_cogl_clip_stack_rebuild (void)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
|
|
|
int has_clip_planes = cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES);
|
2008-12-04 08:45:09 -05:00
|
|
|
gboolean using_clip_planes = FALSE;
|
|
|
|
gboolean using_stencil_buffer = FALSE;
|
2008-06-23 10:57:36 -04:00
|
|
|
GList *node;
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
2009-06-21 19:58:32 -04:00
|
|
|
gint scissor_x0 = 0;
|
|
|
|
gint scissor_y0 = 0;
|
|
|
|
gint scissor_x1 = G_MAXINT;
|
|
|
|
gint scissor_y1 = G_MAXINT;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
[cogl] Improving Cogl journal to minimize driver overheads + GPU state changes
Previously the journal was always flushed at the end of
_cogl_rectangles_with_multitexture_coords, (i.e. the end of any
cogl_rectangle* calls) but now we have broadened the potential for batching
geometry. In ideal circumstances we will only flush once per scene.
In summary the journal works like this:
When you use any of the cogl_rectangle* APIs then nothing is emitted to the
GPU at this point, we just log one or more quads into the journal. A
journal entry consists of the quad coordinates, an associated material
reference, and a modelview matrix. Ideally the journal only gets flushed
once at the end of a scene, but in fact there are things to consider that
may cause unwanted flushing, including:
- modifying materials mid-scene
This is because each quad in the journal has an associated material
reference (i.e. not copy), so if you try and modify a material that is
already referenced in the journal we force a flush first)
NOTE: For now this means you should avoid using cogl_set_source_color()
since that currently uses a single shared material. Later we
should change it to use a pool of materials that is recycled
when the journal is flushed.
- modifying any state that isn't currently logged, such as depth, fog and
backface culling enables.
The first thing that happens when flushing, is to upload all the vertex data
associated with the journal into a single VBO.
We then go through a process of splitting up the journal into batches that
have compatible state so they can be emitted to the GPU together. This is
currently broken up into 3 levels so we can stagger the state changes:
1) we break the journal up according to changes in the number of material layers
associated with logged quads. The number of layers in a material determines
the stride of the associated vertices, so we have to update our vertex
array offsets at this level. (i.e. calling gl{Vertex,Color},Pointer etc)
2) we further split batches up according to material compatability. (e.g.
materials with different textures) We flush material state at this level.
3) Finally we split batches up according to modelview changes. At this level
we update the modelview matrix and actually emit the actual draw command.
This commit is largely about putting the initial design in-place; this will be
followed by other changes that take advantage of the extended batching.
2009-06-17 13:46:42 -04:00
|
|
|
/* The current primitive journal does not support tracking changes to the
|
|
|
|
* clip stack... */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
ctx->clip.stack_dirty = FALSE;
|
|
|
|
ctx->clip.stencil_used = FALSE;
|
|
|
|
|
|
|
|
_cogl_disable_clip_planes ();
|
|
|
|
_cogl_disable_stencil_buffer ();
|
2009-05-08 11:32:01 -04:00
|
|
|
GE (glDisable (GL_SCISSOR_TEST));
|
2009-02-12 06:08:00 -05:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
/* If the stack is empty then there's nothing else to do */
|
|
|
|
if (stack->stack_top == NULL)
|
|
|
|
return;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-08-01 08:23:57 -04:00
|
|
|
/* Find the bottom of the stack */
|
2008-12-04 08:45:09 -05:00
|
|
|
for (node = stack->stack_top; node->next; node = node->next);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
/* Re-add every entry from the bottom of the stack up */
|
2008-12-04 08:45:09 -05:00
|
|
|
for (; node; node = node->prev)
|
|
|
|
{
|
|
|
|
gpointer entry = node->data;
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStackEntryType type = *(CoglClipStackEntryType *) entry;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
if (type == COGL_CLIP_STACK_PATH)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
|
|
|
CoglClipStackEntryPath *path = (CoglClipStackEntryPath *) entry;
|
|
|
|
|
|
|
|
cogl_push_matrix ();
|
2009-02-18 13:54:54 -05:00
|
|
|
_cogl_set_matrix (&path->matrix);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_cogl_add_path_to_stencil_buffer (path->path_nodes_min,
|
|
|
|
path->path_nodes_max,
|
|
|
|
path->path_size,
|
|
|
|
path->path,
|
|
|
|
using_stencil_buffer);
|
|
|
|
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
|
|
|
|
using_stencil_buffer = TRUE;
|
|
|
|
|
|
|
|
/* We can't use clip planes any more */
|
|
|
|
has_clip_planes = FALSE;
|
|
|
|
}
|
2009-05-08 11:32:01 -04:00
|
|
|
else if (type == COGL_CLIP_STACK_RECT)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
|
|
|
CoglClipStackEntryRect *rect = (CoglClipStackEntryRect *) entry;
|
|
|
|
|
|
|
|
cogl_push_matrix ();
|
2009-02-18 13:54:54 -05:00
|
|
|
_cogl_set_matrix (&rect->matrix);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
/* If this is the first entry and we support clip planes then use
|
|
|
|
that instead */
|
|
|
|
if (has_clip_planes)
|
|
|
|
{
|
|
|
|
_cogl_set_clip_planes (rect->x_offset,
|
|
|
|
rect->y_offset,
|
|
|
|
rect->width,
|
|
|
|
rect->height);
|
|
|
|
using_clip_planes = TRUE;
|
|
|
|
/* We can't use clip planes a second time */
|
|
|
|
has_clip_planes = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_cogl_add_stencil_clip (rect->x_offset,
|
|
|
|
rect->y_offset,
|
|
|
|
rect->width,
|
|
|
|
rect->height,
|
|
|
|
!using_stencil_buffer);
|
|
|
|
using_stencil_buffer = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_pop_matrix ();
|
|
|
|
}
|
2009-05-08 11:32:01 -04:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Get the intersection of all window space rectangles in the clip
|
|
|
|
* stack */
|
|
|
|
CoglClipStackEntryWindowRect *window_rect = entry;
|
|
|
|
scissor_x0 = MAX (scissor_x0, window_rect->x0);
|
|
|
|
scissor_y0 = MAX (scissor_y0, window_rect->y0);
|
|
|
|
scissor_x1 = MIN (scissor_x1, window_rect->x1);
|
|
|
|
scissor_y1 = MIN (scissor_y1, window_rect->y1);
|
|
|
|
}
|
2008-12-04 08:45:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enabling clip planes is delayed to now so that they won't affect
|
|
|
|
setting up the stencil buffer */
|
|
|
|
if (using_clip_planes)
|
|
|
|
_cogl_enable_clip_planes ();
|
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
if (scissor_x0 >= scissor_x1 || scissor_y0 >= scissor_y1)
|
|
|
|
scissor_x0 = scissor_y0 = scissor_x1 = scissor_y1 = 0;
|
|
|
|
|
|
|
|
if (!(scissor_x0 == 0 && scissor_y0 == 0 &&
|
2009-06-21 19:58:32 -04:00
|
|
|
scissor_x1 == G_MAXINT && scissor_y1 == G_MAXINT))
|
2009-05-08 11:32:01 -04:00
|
|
|
{
|
|
|
|
GE (glEnable (GL_SCISSOR_TEST));
|
|
|
|
GE (glScissor (scissor_x0, scissor_y0,
|
|
|
|
scissor_x1 - scissor_x0,
|
|
|
|
scissor_y1 - scissor_y0));
|
|
|
|
}
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
ctx->clip.stencil_used = using_stencil_buffer;
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-12-04 08:45:09 -05:00
|
|
|
cogl_clip_ensure (void)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
if (ctx->clip.stack_dirty)
|
|
|
|
_cogl_clip_stack_rebuild ();
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
2008-08-01 08:23:57 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
cogl_clip_stack_save (void)
|
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
stack = g_slice_new (CoglClipStack);
|
|
|
|
stack->stack_top = NULL;
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
ctx->clip.stacks = g_slist_prepend (ctx->clip.stacks, stack);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
ctx->clip.stack_dirty = TRUE;
|
2008-08-01 08:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_clip_stack_restore (void)
|
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
g_return_if_fail (ctx->clip.stacks != NULL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
stack = (CoglClipStack *) ctx->clip.stacks->data;
|
|
|
|
|
|
|
|
/* Empty the current stack */
|
|
|
|
while (stack->stack_top)
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_pop ();
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
/* Revert to an old stack */
|
|
|
|
g_slice_free (CoglClipStack, stack);
|
|
|
|
ctx->clip.stacks = g_slist_delete_link (ctx->clip.stacks,
|
|
|
|
ctx->clip.stacks);
|
|
|
|
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
|
|
|
}
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
void
|
|
|
|
_cogl_clip_stack_state_init (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
ctx->clip.stacks = NULL;
|
|
|
|
ctx->clip.stack_dirty = TRUE;
|
2009-02-12 06:08:00 -05:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
/* Add an intial stack */
|
|
|
|
cogl_clip_stack_save ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_clip_stack_state_destroy (void)
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
/* Destroy all of the stacks */
|
|
|
|
while (ctx->clip.stacks)
|
|
|
|
cogl_clip_stack_restore ();
|
2008-08-01 08:23:57 -04:00
|
|
|
}
|