2008-06-23 14:57:36 +00:00
|
|
|
/*
|
2009-04-27 14:48:12 +00:00
|
|
|
* Cogl
|
2008-06-23 14:57:36 +00:00
|
|
|
*
|
2009-04-27 14:48:12 +00:00
|
|
|
* An object oriented GL/GLES Abstraction/Utility Layer
|
2008-06-23 14:57:36 +00:00
|
|
|
*
|
2010-04-14 18:41:08 +00:00
|
|
|
* Copyright (C) 2007,2008,2009,2010 Intel Corporation.
|
2008-06-23 14:57:36 +00: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
|
2010-03-01 12:56:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*
|
2008-06-23 14:57:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
#include <string.h>
|
2009-11-04 19:42:17 +00:00
|
|
|
#include <math.h>
|
2009-05-08 15:32:01 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
|
2008-06-23 14:57:36 +00:00
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-clip-stack.h"
|
2008-12-04 13:45:09 +00:00
|
|
|
#include "cogl-primitives.h"
|
|
|
|
#include "cogl-context.h"
|
2009-05-08 15:32:01 +00:00
|
|
|
#include "cogl-internal.h"
|
2009-11-26 19:06:35 +00:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2010-02-10 18:18:30 +00:00
|
|
|
#include "cogl-journal-private.h"
|
2010-02-17 15:58:32 +00:00
|
|
|
#include "cogl-util.h"
|
2010-04-08 16:43:27 +00:00
|
|
|
#include "cogl-path-private.h"
|
2010-04-22 13:33:47 +00:00
|
|
|
#include "cogl-matrix-private.h"
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
typedef struct _CoglClipStackEntry CoglClipStackEntry;
|
2008-12-04 13:45:09 +00:00
|
|
|
typedef struct _CoglClipStackEntryRect CoglClipStackEntryRect;
|
2009-05-08 15:32:01 +00:00
|
|
|
typedef struct _CoglClipStackEntryWindowRect CoglClipStackEntryWindowRect;
|
2008-12-04 13:45:09 +00:00
|
|
|
typedef struct _CoglClipStackEntryPath CoglClipStackEntryPath;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
COGL_CLIP_STACK_RECT,
|
2009-05-08 15:32:01 +00:00
|
|
|
COGL_CLIP_STACK_WINDOW_RECT,
|
2008-12-04 13:45:09 +00:00
|
|
|
COGL_CLIP_STACK_PATH
|
|
|
|
} CoglClipStackEntryType;
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
/* A clip stack consists a list of entries. Each entry has a reference
|
|
|
|
* count and a link to its parent node. The child takes a reference on
|
|
|
|
* the parent and the CoglClipStack holds a reference to the top of
|
|
|
|
* the stack. There are no links back from the parent to the
|
|
|
|
* children. This allows stacks that have common ancestry to share the
|
|
|
|
* entries.
|
|
|
|
*
|
|
|
|
* For example, the following sequence of operations would generate
|
|
|
|
* the tree below:
|
|
|
|
*
|
2010-05-28 00:01:28 +00:00
|
|
|
* CoglClipStack *stack_a = _cogl_clip_stack_new ();
|
2010-04-14 12:17:26 +00:00
|
|
|
* _cogl_set_clip_stack (stack_a);
|
|
|
|
* cogl_clip_stack_push_rectangle (...);
|
|
|
|
* cogl_clip_stack_push_rectangle (...);
|
2010-05-28 00:01:28 +00:00
|
|
|
* CoglClipStack *stack_b = _cogl_clip_stack_copy (stack_a);
|
2010-04-14 12:17:26 +00:00
|
|
|
* cogl_clip_stack_push_from_path ();
|
|
|
|
* cogl_set_clip_stack (stack_b);
|
|
|
|
* cogl_clip_stack_push_window_rectangle (...);
|
|
|
|
*
|
|
|
|
* stack_a
|
|
|
|
* \ holds a ref to
|
|
|
|
* +-----------+
|
|
|
|
* | path node |
|
|
|
|
* |ref count 1|
|
|
|
|
* +-----------+
|
|
|
|
* \
|
|
|
|
* +-----------+ +-----------+
|
|
|
|
* both tops hold | rect node | | rect node |
|
|
|
|
* a ref to the |ref count 2|--|ref count 1|
|
|
|
|
* same rect node +-----------+ +-----------+
|
|
|
|
* /
|
|
|
|
* +-----------+
|
|
|
|
* | win. rect |
|
|
|
|
* |ref count 1|
|
|
|
|
* +-----------+
|
|
|
|
* / holds a ref to
|
|
|
|
* stack_b
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
struct _CoglClipStack
|
|
|
|
{
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglObject _parent;
|
2010-04-15 09:27:43 +00:00
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry *stack_top;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _CoglClipStackEntry
|
|
|
|
{
|
|
|
|
CoglClipStackEntryType type;
|
|
|
|
|
|
|
|
/* This will be null if there is no parent. If it is not null then
|
|
|
|
this node must be holding a reference to the parent */
|
|
|
|
CoglClipStackEntry *parent;
|
|
|
|
|
2010-04-22 13:33:47 +00:00
|
|
|
/* All clip entries have a window-space bounding box which we can
|
|
|
|
use to calculate a scissor. The scissor limits the clip so that
|
|
|
|
we don't need to do a full stencil clear if the stencil buffer is
|
|
|
|
needed. This is stored in Cogl's coordinate space (ie, 0,0 is the
|
|
|
|
top left) */
|
|
|
|
int bounds_x0;
|
|
|
|
int bounds_y0;
|
|
|
|
int bounds_x1;
|
|
|
|
int bounds_y1;
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
unsigned int ref_count;
|
2008-12-04 13:45:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _CoglClipStackEntryRect
|
2008-06-23 14:57:36 +00:00
|
|
|
{
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry _parent_data;
|
2008-08-01 12:23:57 +00:00
|
|
|
|
2008-06-23 14:57:36 +00:00
|
|
|
/* The rectangle for this clip */
|
2009-11-04 20:17:56 +00:00
|
|
|
float x0;
|
|
|
|
float y0;
|
|
|
|
float x1;
|
|
|
|
float y1;
|
2008-06-23 14:57:36 +00:00
|
|
|
|
|
|
|
/* The matrix that was current when the clip was set */
|
2009-02-18 18:54:54 +00:00
|
|
|
CoglMatrix matrix;
|
2008-06-23 14:57:36 +00:00
|
|
|
};
|
|
|
|
|
2009-05-08 15:32:01 +00:00
|
|
|
struct _CoglClipStackEntryWindowRect
|
|
|
|
{
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry _parent_data;
|
2009-05-08 15:32:01 +00:00
|
|
|
|
2010-04-22 13:33:47 +00:00
|
|
|
/* The window rect clip doesn't need any specific data because it
|
|
|
|
just adds to the scissor clip */
|
2009-05-08 15:32:01 +00:00
|
|
|
};
|
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
struct _CoglClipStackEntryPath
|
2008-06-23 14:57:36 +00:00
|
|
|
{
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry _parent_data;
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
/* The matrix that was current when the clip was set */
|
2009-05-08 15:32:01 +00:00
|
|
|
CoglMatrix matrix;
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglPath *path;
|
2008-12-04 13:45:09 +00:00
|
|
|
};
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2010-04-15 09:27:43 +00:00
|
|
|
static void _cogl_clip_stack_free (CoglClipStack *stack);
|
|
|
|
|
2010-07-09 17:46:31 +00:00
|
|
|
COGL_OBJECT_INTERNAL_DEFINE (ClipStack, clip_stack);
|
2010-04-15 09:27:43 +00:00
|
|
|
|
|
|
|
#define COGL_CLIP_STACK(stack) ((CoglClipStack *) (stack))
|
|
|
|
|
2009-11-04 19:42:17 +00:00
|
|
|
static void
|
|
|
|
project_vertex (const CoglMatrix *modelview_matrix,
|
|
|
|
const CoglMatrix *projection_matrix,
|
|
|
|
float *vertex)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Apply the modelview matrix */
|
|
|
|
cogl_matrix_transform_point (modelview_matrix,
|
|
|
|
&vertex[0], &vertex[1],
|
|
|
|
&vertex[2], &vertex[3]);
|
|
|
|
/* Apply the projection matrix */
|
|
|
|
cogl_matrix_transform_point (projection_matrix,
|
|
|
|
&vertex[0], &vertex[1],
|
|
|
|
&vertex[2], &vertex[3]);
|
|
|
|
/* Convert from homogenized coordinates */
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
vertex[i] /= vertex[3];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_clip_plane (GLint plane_num,
|
|
|
|
const float *vertex_a,
|
|
|
|
const float *vertex_b)
|
|
|
|
{
|
|
|
|
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
|
|
|
GLfloat plane[4];
|
|
|
|
#else
|
|
|
|
GLdouble plane[4];
|
|
|
|
#endif
|
|
|
|
GLfloat angle;
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrix inverse_projection;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_get_inverse (projection_stack, &inverse_projection);
|
|
|
|
|
|
|
|
/* Calculate the angle between the axes and the line crossing the
|
|
|
|
two points */
|
|
|
|
angle = atan2f (vertex_b[1] - vertex_a[1],
|
|
|
|
vertex_b[0] - vertex_a[0]) * (180.0/G_PI);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
|
|
|
|
/* Load the inverse of the projection matrix so we can specify the plane
|
|
|
|
* in screen coordinates */
|
|
|
|
_cogl_matrix_stack_set (modelview_stack, &inverse_projection);
|
|
|
|
|
|
|
|
/* Rotate about point a */
|
|
|
|
_cogl_matrix_stack_translate (modelview_stack,
|
|
|
|
vertex_a[0], vertex_a[1], vertex_a[2]);
|
|
|
|
/* Rotate the plane by the calculated angle so that it will connect
|
|
|
|
the two points */
|
|
|
|
_cogl_matrix_stack_rotate (modelview_stack, angle, 0.0f, 0.0f, 1.0f);
|
|
|
|
_cogl_matrix_stack_translate (modelview_stack,
|
|
|
|
-vertex_a[0], -vertex_a[1], -vertex_a[2]);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_flush_to_gl (modelview_stack, COGL_MATRIX_MODELVIEW);
|
|
|
|
|
|
|
|
plane[0] = 0;
|
|
|
|
plane[1] = -1.0;
|
|
|
|
plane[2] = 0;
|
|
|
|
plane[3] = vertex_a[1];
|
|
|
|
#if defined (HAVE_COGL_GLES2) || defined (HAVE_COGL_GLES)
|
|
|
|
GE( glClipPlanef (plane_num, plane) );
|
|
|
|
#else
|
|
|
|
GE( glClipPlane (plane_num, plane) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-11-04 20:17:56 +00:00
|
|
|
set_clip_planes (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2009-11-04 19:42:17 +00:00
|
|
|
{
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrix modelview_matrix;
|
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrix projection_matrix;
|
2010-04-20 13:58:57 +00:00
|
|
|
float signed_area;
|
2009-11-04 19:42:17 +00:00
|
|
|
|
2009-11-04 20:17:56 +00:00
|
|
|
float vertex_tl[4] = { x_1, y_1, 0, 1.0 };
|
|
|
|
float vertex_tr[4] = { x_2, y_1, 0, 1.0 };
|
|
|
|
float vertex_bl[4] = { x_1, y_2, 0, 1.0 };
|
|
|
|
float vertex_br[4] = { x_2, y_2, 0, 1.0 };
|
2009-11-04 19:42:17 +00:00
|
|
|
|
|
|
|
_cogl_matrix_stack_get (projection_stack, &projection_matrix);
|
|
|
|
_cogl_matrix_stack_get (modelview_stack, &modelview_matrix);
|
|
|
|
|
|
|
|
project_vertex (&modelview_matrix, &projection_matrix, vertex_tl);
|
|
|
|
project_vertex (&modelview_matrix, &projection_matrix, vertex_tr);
|
|
|
|
project_vertex (&modelview_matrix, &projection_matrix, vertex_bl);
|
|
|
|
project_vertex (&modelview_matrix, &projection_matrix, vertex_br);
|
|
|
|
|
2010-04-20 13:58:57 +00:00
|
|
|
/* Calculate the signed area of the polygon formed by the four
|
|
|
|
vertices so that we can know its orientation */
|
|
|
|
signed_area = (vertex_tl[0] * (vertex_tr[1] - vertex_bl[1])
|
|
|
|
+ vertex_tr[0] * (vertex_br[1] - vertex_tl[1])
|
|
|
|
+ vertex_br[0] * (vertex_bl[1] - vertex_tr[1])
|
|
|
|
+ vertex_bl[0] * (vertex_tl[1] - vertex_br[1]));
|
|
|
|
|
|
|
|
/* Set the clip planes to form lines between all of the vertices
|
|
|
|
using the same orientation as we calculated */
|
|
|
|
if (signed_area > 0.0f)
|
2009-11-04 19:42:17 +00:00
|
|
|
{
|
2010-04-20 13:58:57 +00:00
|
|
|
/* counter-clockwise */
|
|
|
|
set_clip_plane (GL_CLIP_PLANE0, vertex_tl, vertex_bl);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE1, vertex_bl, vertex_br);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE2, vertex_br, vertex_tr);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE3, vertex_tr, vertex_tl);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* clockwise */
|
|
|
|
set_clip_plane (GL_CLIP_PLANE0, vertex_tl, vertex_tr);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE1, vertex_tr, vertex_br);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE2, vertex_br, vertex_bl);
|
|
|
|
set_clip_plane (GL_CLIP_PLANE3, vertex_bl, vertex_tl);
|
2009-11-04 19:42:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-27 12:28:43 +00:00
|
|
|
static void
|
2009-11-04 20:17:56 +00:00
|
|
|
add_stencil_clip_rectangle (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
2009-11-04 19:42:17 +00:00
|
|
|
gboolean first)
|
|
|
|
{
|
|
|
|
CoglHandle current_source;
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 19:42:17 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
/* We don't log changes to the stencil buffer so need to flush any
|
|
|
|
* batched geometry before we start... */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_flush_state (framebuffer, 0);
|
2009-11-04 19:42:17 +00:00
|
|
|
|
|
|
|
/* temporarily swap in our special stenciling material */
|
2010-05-28 00:01:28 +00:00
|
|
|
current_source = cogl_object_ref (ctx->source_material);
|
2009-11-04 19:42:17 +00:00
|
|
|
cogl_set_source (ctx->stencil_material);
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
{
|
|
|
|
GE( glEnable (GL_STENCIL_TEST) );
|
|
|
|
|
|
|
|
/* Initially disallow everything */
|
|
|
|
GE( glClearStencil (0) );
|
|
|
|
GE( glClear (GL_STENCIL_BUFFER_BIT) );
|
|
|
|
|
|
|
|
/* Punch out a hole to allow the rectangle */
|
|
|
|
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
|
|
|
|
GE( glStencilOp (GL_REPLACE, GL_REPLACE, GL_REPLACE) );
|
|
|
|
|
2009-11-04 20:17:56 +00:00
|
|
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
2009-11-04 19:42:17 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 19:42:17 +00:00
|
|
|
|
|
|
|
/* Add one to every pixel of the stencil buffer in the
|
|
|
|
rectangle */
|
|
|
|
GE( glStencilFunc (GL_NEVER, 0x1, 0x3) );
|
|
|
|
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
|
2009-11-04 20:17:56 +00:00
|
|
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
2009-11-04 19:42:17 +00:00
|
|
|
|
|
|
|
/* make sure our rectangle hits the stencil buffer before we
|
|
|
|
* change the stencil operation */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
|
|
|
/* Subtract one from all pixels in the stencil buffer so that
|
|
|
|
only pixels where both the original stencil buffer and the
|
|
|
|
rectangle are set will be valid */
|
|
|
|
GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
|
|
|
|
|
|
|
|
_cogl_matrix_stack_push (projection_stack);
|
|
|
|
_cogl_matrix_stack_load_identity (projection_stack);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
_cogl_matrix_stack_load_identity (modelview_stack);
|
|
|
|
|
|
|
|
cogl_rectangle (-1.0, -1.0, 1.0, 1.0);
|
|
|
|
|
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
|
|
|
_cogl_matrix_stack_pop (projection_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure our rectangles hit the stencil buffer before we restore
|
|
|
|
* the stencil function / operation */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
|
|
|
/* Restore the stencil mode */
|
|
|
|
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
|
|
|
|
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
|
|
|
|
|
|
|
|
/* restore the original source material */
|
|
|
|
cogl_set_source (current_source);
|
2010-05-28 00:01:28 +00:00
|
|
|
cogl_object_unref (current_source);
|
2009-11-04 19:42:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
disable_stencil_buffer (void)
|
|
|
|
{
|
|
|
|
GE( glDisable (GL_STENCIL_TEST) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
enable_clip_planes (void)
|
|
|
|
{
|
|
|
|
GE( glEnable (GL_CLIP_PLANE0) );
|
|
|
|
GE( glEnable (GL_CLIP_PLANE1) );
|
|
|
|
GE( glEnable (GL_CLIP_PLANE2) );
|
|
|
|
GE( glEnable (GL_CLIP_PLANE3) );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
disable_clip_planes (void)
|
|
|
|
{
|
|
|
|
GE( glDisable (GL_CLIP_PLANE3) );
|
|
|
|
GE( glDisable (GL_CLIP_PLANE2) );
|
|
|
|
GE( glDisable (GL_CLIP_PLANE1) );
|
|
|
|
GE( glDisable (GL_CLIP_PLANE0) );
|
|
|
|
}
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
static gpointer
|
|
|
|
_cogl_clip_stack_push_entry (CoglClipStack *clip_stack,
|
|
|
|
size_t size,
|
|
|
|
CoglClipStackEntryType type)
|
|
|
|
{
|
|
|
|
CoglClipStackEntry *entry = g_slice_alloc (size);
|
|
|
|
|
|
|
|
/* The new entry starts with a ref count of 1 because the stack
|
|
|
|
holds a reference to it as it is the top entry */
|
|
|
|
entry->ref_count = 1;
|
|
|
|
entry->type = type;
|
|
|
|
entry->parent = clip_stack->stack_top;
|
|
|
|
clip_stack->stack_top = entry;
|
|
|
|
|
|
|
|
/* We don't need to take a reference to the parent from the entry
|
|
|
|
because the clip_stack would have had to reference the top of
|
|
|
|
the stack and we can just steal that */
|
|
|
|
|
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
2010-04-22 13:33:47 +00:00
|
|
|
/* Sets the window-space bounds of the entry based on the projected
|
|
|
|
coordinates of the given rectangle */
|
|
|
|
static void
|
|
|
|
_cogl_clip_stack_entry_set_bounds (CoglClipStackEntry *entry,
|
|
|
|
float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
|
|
|
const CoglMatrix *modelview)
|
|
|
|
{
|
|
|
|
CoglMatrix projection;
|
|
|
|
float viewport[4];
|
|
|
|
float verts[4 * 2] = { x_1, y_1, x_2, y_1, x_2, y_2, x_1, y_2 };
|
|
|
|
float min_x = G_MAXFLOAT, min_y = G_MAXFLOAT;
|
|
|
|
float max_x = -G_MAXFLOAT, max_y = -G_MAXFLOAT;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cogl_get_projection_matrix (&projection);
|
|
|
|
cogl_get_viewport (viewport);
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
float *v = verts + i * 2;
|
|
|
|
|
|
|
|
/* Project the coordinates to window space coordinates */
|
|
|
|
_cogl_transform_point (modelview, &projection, viewport, v, v + 1);
|
|
|
|
|
|
|
|
if (v[0] > max_x)
|
|
|
|
max_x = v[0];
|
|
|
|
if (v[0] < min_x)
|
|
|
|
min_x = v[0];
|
|
|
|
if (v[1] > max_y)
|
|
|
|
max_y = v[1];
|
|
|
|
if (v[1] < min_y)
|
|
|
|
min_y = v[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->bounds_x0 = floorf (min_x);
|
|
|
|
entry->bounds_x1 = ceilf (max_x);
|
|
|
|
entry->bounds_y0 = floorf (min_y);
|
|
|
|
entry->bounds_y1 = ceilf (max_y);
|
|
|
|
}
|
|
|
|
|
2009-05-08 15:32:01 +00:00
|
|
|
void
|
2010-05-28 00:01:28 +00:00
|
|
|
_cogl_clip_stack_push_window_rectangle (CoglClipStack *stack,
|
2010-04-14 18:41:08 +00:00
|
|
|
int x_offset,
|
|
|
|
int y_offset,
|
|
|
|
int width,
|
|
|
|
int height)
|
2009-05-08 15:32:01 +00:00
|
|
|
{
|
2010-04-22 13:33:47 +00:00
|
|
|
CoglClipStackEntry *entry;
|
2009-05-08 15:32:01 +00:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
entry = _cogl_clip_stack_push_entry (stack,
|
|
|
|
sizeof (CoglClipStackEntryWindowRect),
|
|
|
|
COGL_CLIP_STACK_WINDOW_RECT);
|
2009-05-08 15:32:01 +00:00
|
|
|
|
2010-04-22 13:33:47 +00:00
|
|
|
entry->bounds_x0 = x_offset;
|
|
|
|
entry->bounds_x1 = x_offset + width;
|
|
|
|
entry->bounds_y0 = y_offset;
|
|
|
|
entry->bounds_y1 = y_offset + height;
|
2009-05-08 15:32:01 +00:00
|
|
|
}
|
|
|
|
|
[cogl-clip] deprecate parts and cleanup the API
cogl_clip_push() which accepts a rectangle in model space shouldn't have
been defined to take x,y,width,height arguments because this isn't consistant
with other Cogl API dealing with model space rectangles. If you are using a
coordinate system with the origin at the center and the y+ extending up,
then x,y,width,height isn't as natural as (x0,y0)(x1,y1). This API has
now been replace with cogl_clip_push_rectangle()
(As a general note: the Cogl API should only use the x,y,width,height style
when the appropriate coordinate space is defined by Cogl to have a top left
origin. E.g. window coordinates, or potentially texture coordinates)
cogl_clip_push_window_rect() shouldn't have been defined to take float
arguments since we only clip with integral pixel precision. We also
shouldn't have abbreviated "rectangle". This API has been replaced with
cogl_clip_push_window_rectangle()
cogl_clip_ensure() wasn't documented at all in Clutter 1.0 and probably
no one even knew it existed. This API isn't useful, and so it's now
deprecated. If no one complains we may remove the API altogether for
Clutter 1.2.
cogl_clip_stack_save() and cogl_clip_stack_restore() were originally added
to allow us to save/restore the clip when switching to/from offscreen
rendering. Now that offscreen draw buffers are defined to own their clip
state and the state will be automatically saved and restored this API is now
redundant and so deprecated.
2009-11-04 19:31:43 +00:00
|
|
|
void
|
2010-05-28 00:01:28 +00:00
|
|
|
_cogl_clip_stack_push_rectangle (CoglClipStack *stack,
|
2010-04-14 18:41:08 +00:00
|
|
|
float x_1,
|
|
|
|
float y_1,
|
2009-11-04 20:17:56 +00:00
|
|
|
float x_2,
|
2010-04-14 18:41:08 +00:00
|
|
|
float y_2,
|
|
|
|
const CoglMatrix *modelview_matrix)
|
2008-06-23 14:57:36 +00:00
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglClipStackEntryRect *entry;
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2008-06-23 14:57:36 +00:00
|
|
|
/* Make a new entry */
|
2010-04-14 12:17:26 +00:00
|
|
|
entry = _cogl_clip_stack_push_entry (stack,
|
|
|
|
sizeof (CoglClipStackEntryRect),
|
|
|
|
COGL_CLIP_STACK_RECT);
|
|
|
|
|
2009-11-04 20:17:56 +00:00
|
|
|
entry->x0 = x_1;
|
|
|
|
entry->y0 = y_1;
|
|
|
|
entry->x1 = x_2;
|
|
|
|
entry->y1 = y_2;
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
entry->matrix = *modelview_matrix;
|
2010-04-22 13:33:47 +00:00
|
|
|
|
|
|
|
_cogl_clip_stack_entry_set_bounds ((CoglClipStackEntry *) entry,
|
|
|
|
x_1, y_1, x_2, y_2, modelview_matrix);
|
2009-11-04 20:17:56 +00:00
|
|
|
}
|
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
void
|
2010-05-28 00:01:28 +00:00
|
|
|
_cogl_clip_stack_push_from_path (CoglClipStack *stack,
|
|
|
|
CoglPath *path,
|
2010-04-14 18:41:08 +00:00
|
|
|
const CoglMatrix *modelview_matrix)
|
2008-12-04 13:45:09 +00:00
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglClipStackEntryPath *entry;
|
2010-04-22 13:33:47 +00:00
|
|
|
float x_1, y_1, x_2, y_2;
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
entry = _cogl_clip_stack_push_entry (stack,
|
|
|
|
sizeof (CoglClipStackEntryPath),
|
|
|
|
COGL_CLIP_STACK_PATH);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
entry->path = cogl_path_copy (path);
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
entry->matrix = *modelview_matrix;
|
2010-04-22 13:33:47 +00:00
|
|
|
|
|
|
|
_cogl_path_get_bounds (path, &x_1, &y_1, &x_2, &y_2);
|
|
|
|
|
|
|
|
_cogl_clip_stack_entry_set_bounds ((CoglClipStackEntry *) entry,
|
|
|
|
x_1, y_1, x_2, y_2, modelview_matrix);
|
2008-06-23 14:57:36 +00:00
|
|
|
}
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
static void
|
|
|
|
_cogl_clip_stack_entry_unref (CoglClipStackEntry *entry)
|
|
|
|
{
|
|
|
|
/* Unref all of the entries until we hit the root of the list or the
|
|
|
|
entry still has a remaining reference */
|
|
|
|
while (entry && --entry->ref_count <= 0)
|
|
|
|
{
|
|
|
|
CoglClipStackEntry *parent = entry->parent;
|
|
|
|
|
|
|
|
switch (entry->type)
|
|
|
|
{
|
|
|
|
case COGL_CLIP_STACK_RECT:
|
|
|
|
g_slice_free1 (sizeof (CoglClipStackEntryRect), entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_CLIP_STACK_WINDOW_RECT:
|
|
|
|
g_slice_free1 (sizeof (CoglClipStackEntryWindowRect), entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COGL_CLIP_STACK_PATH:
|
2010-05-28 00:01:28 +00:00
|
|
|
cogl_object_unref (((CoglClipStackEntryPath *) entry)->path);
|
2010-04-14 12:17:26 +00:00
|
|
|
g_slice_free1 (sizeof (CoglClipStackEntryPath), entry);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = parent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
void
|
2010-05-28 00:01:28 +00:00
|
|
|
_cogl_clip_stack_pop (CoglClipStack *stack)
|
2008-06-23 14:57:36 +00:00
|
|
|
{
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry *entry;
|
2008-12-04 13:45:09 +00:00
|
|
|
|
|
|
|
g_return_if_fail (stack->stack_top != NULL);
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
/* To pop we are moving the top of the stack to the old top's parent
|
|
|
|
node. The stack always needs to have a reference to the top entry
|
|
|
|
so we must take a reference to the new top. The stack would have
|
|
|
|
previously had a reference to the old top so we need to decrease
|
|
|
|
the ref count on that. We need to ref the new head first in case
|
|
|
|
this stack was the only thing referencing the old top. In that
|
|
|
|
case the call to _cogl_clip_stack_entry_unref will unref the
|
|
|
|
parent. */
|
|
|
|
entry = stack->stack_top;
|
|
|
|
stack->stack_top = entry->parent;
|
|
|
|
if (stack->stack_top)
|
|
|
|
stack->stack_top->ref_count++;
|
|
|
|
_cogl_clip_stack_entry_unref (entry);
|
2008-06-23 14:57:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-05-28 00:01:28 +00:00
|
|
|
_cogl_clip_stack_flush (CoglClipStack *stack,
|
2010-04-14 18:41:08 +00:00
|
|
|
gboolean *stencil_used_p)
|
2008-06-23 14:57:36 +00:00
|
|
|
{
|
2009-09-25 13:34:34 +00:00
|
|
|
int has_clip_planes;
|
2008-12-04 13:45:09 +00:00
|
|
|
gboolean using_clip_planes = FALSE;
|
|
|
|
gboolean using_stencil_buffer = FALSE;
|
cogl: improves header and coding style consistency
We've had complaints that our Cogl code/headers are a bit "special" so
this is a first pass at tidying things up by giving them some
consistency. These changes are all consistent with how new code in Cogl
is being written, but the style isn't consistently applied across all
code yet.
There are two parts to this patch; but since each one required a large
amount of effort to maintain tidy indenting it made sense to combine the
changes to reduce the time spent re indenting the same lines.
The first change is to use a consistent style for declaring function
prototypes in headers. Cogl headers now consistently use this style for
prototypes:
return_type
cogl_function_name (CoglType arg0,
CoglType arg1);
Not everyone likes this style, but it seems that most of the currently
active Cogl developers agree on it.
The second change is to constrain the use of redundant glib data types
in Cogl. Uses of gint, guint, gfloat, glong, gulong and gchar have all
been replaced with int, unsigned int, float, long, unsigned long and char
respectively. When talking about pixel data; use of guchar has been
replaced with guint8, otherwise unsigned char can be used.
The glib types that we continue to use for portability are gboolean,
gint{8,16,32,64}, guint{8,16,32,64} and gsize.
The general intention is that Cogl should look palatable to the widest
range of C programmers including those outside the Gnome community so
- especially for the public API - we want to minimize the number of
foreign looking typedefs.
2010-02-10 01:57:32 +00:00
|
|
|
int scissor_x0 = 0;
|
|
|
|
int scissor_y0 = 0;
|
|
|
|
int scissor_x1 = G_MAXINT;
|
|
|
|
int scissor_y1 = G_MAXINT;
|
2009-09-25 13:34:34 +00:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 19:06:35 +00:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2010-04-14 12:17:26 +00:00
|
|
|
CoglClipStackEntry *entry;
|
2010-04-22 13:33:47 +00:00
|
|
|
int scissor_y_start;
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2009-09-25 13:34:34 +00:00
|
|
|
has_clip_planes = cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES);
|
|
|
|
|
2010-06-08 17:38:25 +00:00
|
|
|
if (has_clip_planes)
|
|
|
|
disable_clip_planes ();
|
2009-11-04 19:42:17 +00:00
|
|
|
disable_stencil_buffer ();
|
2009-02-12 11:08:00 +00:00
|
|
|
|
2008-12-04 13:45:09 +00:00
|
|
|
/* If the stack is empty then there's nothing else to do */
|
|
|
|
if (stack->stack_top == NULL)
|
2010-05-06 13:15:04 +00:00
|
|
|
{
|
|
|
|
*stencil_used_p = FALSE;
|
2010-04-22 13:33:47 +00:00
|
|
|
GE (glDisable (GL_SCISSOR_TEST));
|
2010-05-06 13:15:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-06-23 14:57:36 +00:00
|
|
|
|
2010-04-22 13:33:47 +00:00
|
|
|
/* Calculate the scissor rect first so that if we eventually have to
|
|
|
|
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->stack_top; 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable scissoring as soon as possible */
|
|
|
|
if (scissor_x0 >= scissor_x1 || scissor_y0 >= scissor_y1)
|
|
|
|
scissor_x0 = scissor_y0 = scissor_x1 = scissor_y1 = scissor_y_start = 0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglFramebuffer *framebuffer = _cogl_get_framebuffer ();
|
|
|
|
|
|
|
|
/* We store the entry coordinates in Cogl coordinate space
|
|
|
|
* but OpenGL requires the window origin to be the bottom
|
|
|
|
* left so we may need to convert the incoming coordinates.
|
|
|
|
*
|
|
|
|
* NB: Cogl forces all offscreen rendering to be done upside
|
|
|
|
* down so in this case no conversion is needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (cogl_is_offscreen (framebuffer))
|
|
|
|
scissor_y_start = scissor_y0;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int framebuffer_height =
|
|
|
|
_cogl_framebuffer_get_height (framebuffer);
|
|
|
|
|
|
|
|
scissor_y_start = framebuffer_height - scissor_y1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GE (glEnable (GL_SCISSOR_TEST));
|
|
|
|
GE (glScissor (scissor_x0, scissor_y_start,
|
|
|
|
scissor_x1 - scissor_x0,
|
|
|
|
scissor_y1 - scissor_y0));
|
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
/* Add all of the entries. This will end up adding them in the
|
|
|
|
reverse order that they were specified but as all of the clips
|
|
|
|
are intersecting it should work out the same regardless of the
|
|
|
|
order */
|
|
|
|
for (entry = stack->stack_top; entry; entry = entry->parent)
|
2008-12-04 13:45:09 +00:00
|
|
|
{
|
2010-04-14 12:17:26 +00:00
|
|
|
if (entry->type == COGL_CLIP_STACK_PATH)
|
2008-12-04 13:45:09 +00:00
|
|
|
{
|
2010-04-08 16:43:27 +00:00
|
|
|
CoglClipStackEntryPath *path_entry = (CoglClipStackEntryPath *) entry;
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
2010-04-08 16:43:27 +00:00
|
|
|
_cogl_matrix_stack_set (modelview_stack, &path_entry->matrix);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-04-08 16:43:27 +00:00
|
|
|
_cogl_add_path_to_stencil_buffer (path_entry->path,
|
2009-10-05 12:37:11 +00:00
|
|
|
using_stencil_buffer,
|
|
|
|
TRUE);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
|
|
|
using_stencil_buffer = TRUE;
|
|
|
|
}
|
2010-04-14 12:17:26 +00:00
|
|
|
else if (entry->type == COGL_CLIP_STACK_RECT)
|
2008-12-04 13:45:09 +00:00
|
|
|
{
|
|
|
|
CoglClipStackEntryRect *rect = (CoglClipStackEntryRect *) entry;
|
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
_cogl_matrix_stack_set (modelview_stack, &rect->matrix);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-04-14 12:17:26 +00:00
|
|
|
/* If we support clip planes and we haven't already used
|
|
|
|
them then use that instead */
|
2008-12-04 13:45:09 +00:00
|
|
|
if (has_clip_planes)
|
|
|
|
{
|
2009-11-04 20:17:56 +00:00
|
|
|
set_clip_planes (rect->x0,
|
|
|
|
rect->y0,
|
|
|
|
rect->x1,
|
|
|
|
rect->y1);
|
2008-12-04 13:45:09 +00:00
|
|
|
using_clip_planes = TRUE;
|
|
|
|
/* We can't use clip planes a second time */
|
|
|
|
has_clip_planes = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-04 20:17:56 +00:00
|
|
|
add_stencil_clip_rectangle (rect->x0,
|
|
|
|
rect->y0,
|
|
|
|
rect->x1,
|
|
|
|
rect->y1,
|
2009-11-04 19:42:17 +00:00
|
|
|
!using_stencil_buffer);
|
2008-12-04 13:45:09 +00:00
|
|
|
using_stencil_buffer = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-13 22:09:42 +00:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2008-12-04 13:45:09 +00:00
|
|
|
}
|
2010-04-22 13:33:47 +00:00
|
|
|
/* We don't need to do anything for window space rectangles
|
|
|
|
because their functionality is entirely implemented by the
|
|
|
|
entry bounding box */
|
2008-12-04 13:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enabling clip planes is delayed to now so that they won't affect
|
|
|
|
setting up the stencil buffer */
|
|
|
|
if (using_clip_planes)
|
2009-11-04 19:42:17 +00:00
|
|
|
enable_clip_planes ();
|
2008-12-04 13:45:09 +00:00
|
|
|
|
2010-04-14 18:41:08 +00:00
|
|
|
*stencil_used_p = using_stencil_buffer;
|
2008-06-23 14:57:36 +00:00
|
|
|
}
|
2008-08-01 12:23:57 +00:00
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglClipStack *
|
2010-04-14 18:41:08 +00:00
|
|
|
_cogl_clip_stack_new (void)
|
2008-08-01 12:23:57 +00:00
|
|
|
{
|
2008-12-04 13:45:09 +00:00
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
stack = g_slice_new (CoglClipStack);
|
|
|
|
stack->stack_top = NULL;
|
2008-08-01 12:23:57 +00:00
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
return _cogl_clip_stack_object_new (stack);
|
2008-08-01 12:23:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-14 18:41:08 +00:00
|
|
|
_cogl_clip_stack_free (CoglClipStack *stack)
|
2008-08-01 12:23:57 +00:00
|
|
|
{
|
2010-04-14 18:41:08 +00:00
|
|
|
/* We only need to unref the top node and this
|
2010-04-14 12:17:26 +00:00
|
|
|
should end up freeing all of the parents if need be */
|
|
|
|
if (stack->stack_top)
|
|
|
|
_cogl_clip_stack_entry_unref (stack->stack_top);
|
2008-12-04 13:45:09 +00:00
|
|
|
|
|
|
|
g_slice_free (CoglClipStack, stack);
|
2009-09-25 13:34:34 +00:00
|
|
|
}
|
2010-04-15 09:58:28 +00:00
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglClipStack *
|
|
|
|
_cogl_clip_stack_copy (CoglClipStack *old_stack)
|
2010-04-15 09:58:28 +00:00
|
|
|
{
|
2010-05-28 00:01:28 +00:00
|
|
|
CoglClipStack *new_stack;
|
2010-04-15 09:58:28 +00:00
|
|
|
|
2010-07-09 17:46:31 +00:00
|
|
|
if (!_cogl_is_clip_stack (old_stack))
|
2010-05-28 00:01:28 +00:00
|
|
|
return NULL;
|
2010-04-15 09:58:28 +00:00
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
new_stack = _cogl_clip_stack_new ();
|
2010-04-15 09:58:28 +00:00
|
|
|
|
|
|
|
/* We can copy the stack by just referencing the other stack's
|
|
|
|
data. There's no need to implement copy-on-write because the
|
|
|
|
entries of the stack can't be modified. If the other stack pops
|
|
|
|
some entries off they will still be kept alive because this stack
|
|
|
|
holds a reference. */
|
|
|
|
new_stack->stack_top = old_stack->stack_top;
|
|
|
|
if (new_stack->stack_top)
|
|
|
|
new_stack->stack_top->ref_count++;
|
|
|
|
|
2010-05-28 00:01:28 +00:00
|
|
|
return new_stack;
|
2010-04-15 09:58:28 +00:00
|
|
|
}
|