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-11-04 14:42:17 -05:00
|
|
|
#include <math.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"
|
2009-11-26 14:06:35 -05:00
|
|
|
#include "cogl-framebuffer-private.h"
|
2010-02-10 13:18:30 -05:00
|
|
|
#include "cogl-journal-private.h"
|
2010-02-17 10:58:32 -05:00
|
|
|
#include "cogl-util.h"
|
2008-06-23 10:57:36 -04:00
|
|
|
|
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-09 20:57:32 -05:00
|
|
|
void _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
|
|
|
|
floatVec2 nodes_max,
|
|
|
|
unsigned int path_size,
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglPathNode *path,
|
2009-10-05 08:37:11 -04:00
|
|
|
gboolean merge,
|
|
|
|
gboolean need_clear);
|
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-11-04 15:17:56 -05:00
|
|
|
float x0;
|
|
|
|
float y0;
|
|
|
|
float x1;
|
|
|
|
float y1;
|
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
|
|
|
|
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-09 20:57:32 -05:00
|
|
|
unsigned int path_size;
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglPathNode path[1];
|
2008-12-04 08:45:09 -05:00
|
|
|
};
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2009-11-04 14:42:17 -05: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;
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 14:42:17 -05: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 15:17:56 -05:00
|
|
|
set_clip_planes (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2009-11-04 14:42:17 -05:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrix modelview_matrix;
|
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrix projection_matrix;
|
|
|
|
|
2009-11-04 15:17:56 -05: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 14:42:17 -05: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);
|
|
|
|
|
|
|
|
/* If the order of the top and bottom lines is different from the
|
|
|
|
order of the left and right lines then the clip rect must have
|
|
|
|
been transformed so that the back is visible. We therefore need
|
|
|
|
to swap one pair of vertices otherwise all of the planes will be
|
|
|
|
the wrong way around */
|
|
|
|
if ((vertex_tl[0] < vertex_tr[0] ? 1 : 0)
|
|
|
|
!= (vertex_bl[1] < vertex_tl[1] ? 1 : 0))
|
|
|
|
{
|
|
|
|
float temp[4];
|
|
|
|
memcpy (temp, vertex_tl, sizeof (temp));
|
|
|
|
memcpy (vertex_tl, vertex_tr, sizeof (temp));
|
|
|
|
memcpy (vertex_tr, temp, sizeof (temp));
|
|
|
|
memcpy (temp, vertex_bl, sizeof (temp));
|
|
|
|
memcpy (vertex_bl, vertex_br, sizeof (temp));
|
|
|
|
memcpy (vertex_br, temp, sizeof (temp));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-11-04 15:17:56 -05:00
|
|
|
add_stencil_clip_rectangle (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2,
|
2009-11-04 14:42:17 -05:00
|
|
|
gboolean first)
|
|
|
|
{
|
|
|
|
CoglHandle current_source;
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer = _cogl_get_framebuffer ();
|
2009-11-04 14:42:17 -05: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 14:06:35 -05:00
|
|
|
_cogl_framebuffer_flush_state (framebuffer, 0);
|
2009-11-04 14:42:17 -05:00
|
|
|
|
|
|
|
/* temporarily swap in our special stenciling material */
|
|
|
|
current_source = cogl_handle_ref (ctx->source_material);
|
|
|
|
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 15:17:56 -05:00
|
|
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
2009-11-04 14:42:17 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (framebuffer);
|
2009-11-04 14:42:17 -05:00
|
|
|
CoglMatrixStack *projection_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_projection_stack (framebuffer);
|
2009-11-04 14:42:17 -05: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 15:17:56 -05:00
|
|
|
cogl_rectangle (x_1, y_1, x_2, y_2);
|
2009-11-04 14:42:17 -05: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);
|
|
|
|
cogl_handle_unref (current_source);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) );
|
|
|
|
}
|
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
void
|
[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 14:31:43 -05:00
|
|
|
cogl_clip_push_window_rectangle (int x_offset,
|
|
|
|
int y_offset,
|
|
|
|
int width,
|
|
|
|
int height)
|
2009-05-08 11:32:01 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStack *stack;
|
2009-11-26 14:06:35 -05:00
|
|
|
int framebuffer_height;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackEntryWindowRect *entry;
|
2009-05-08 11:32:01 -04:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
2009-05-08 11:32:01 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
stack = clip_state->stacks->data;
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer_height = _cogl_framebuffer_get_height (framebuffer);
|
2009-05-08 11:32:01 -04:00
|
|
|
|
|
|
|
entry = g_slice_new (CoglClipStackEntryWindowRect);
|
|
|
|
|
2009-10-30 19:57:56 -04:00
|
|
|
/* We store the entry coordinates in OpenGL window coordinate space and so
|
|
|
|
* because Cogl defines the window origin to be top left but OpenGL defines
|
|
|
|
* it as bottom left 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.
|
|
|
|
*/
|
2009-05-08 11:32:01 -04:00
|
|
|
entry->type = COGL_CLIP_STACK_WINDOW_RECT;
|
|
|
|
entry->x0 = x_offset;
|
|
|
|
entry->x1 = x_offset + width;
|
2009-11-26 14:06:35 -05:00
|
|
|
if (cogl_is_offscreen (framebuffer))
|
2009-10-30 19:57:56 -04:00
|
|
|
{
|
|
|
|
entry->y0 = y_offset;
|
|
|
|
entry->y1 = y_offset + height;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
entry->y0 = framebuffer_height - y_offset - height;
|
|
|
|
entry->y1 = framebuffer_height - y_offset;
|
2009-10-30 19:57:56 -04:00
|
|
|
}
|
2009-05-08 11:32:01 -04:00
|
|
|
|
|
|
|
/* Store it in the stack */
|
|
|
|
stack->stack_top = g_list_prepend (stack->stack_top, entry);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stack_dirty = TRUE;
|
2009-05-08 11:32:01 -04: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 14:31:43 -05:00
|
|
|
/* XXX: This is deprecated API */
|
|
|
|
void
|
|
|
|
cogl_clip_push_window_rect (float x_offset,
|
|
|
|
float y_offset,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
|
|
|
cogl_clip_push_window_rectangle (x_offset, y_offset, width, height);
|
|
|
|
}
|
|
|
|
|
2009-10-21 18:22:45 -04:00
|
|
|
/* Scale from OpenGL normalized device coordinates (ranging from -1 to 1)
|
2009-11-26 14:06:35 -05:00
|
|
|
* to Cogl window/framebuffer coordinates (ranging from 0 to buffer-size) with
|
2009-10-21 18:22:45 -04:00
|
|
|
* (0,0) being top left. */
|
|
|
|
#define VIEWPORT_TRANSFORM_X(x, vp_origin_x, vp_width) \
|
|
|
|
( ( ((x) + 1.0) * ((vp_width) / 2.0) ) + (vp_origin_x) )
|
|
|
|
/* Note: for Y we first flip all coordinates around the X axis while in
|
|
|
|
* normalized device coodinates */
|
|
|
|
#define VIEWPORT_TRANSFORM_Y(y, vp_origin_y, vp_height) \
|
|
|
|
( ( ((-(y)) + 1.0) * ((vp_height) / 2.0) ) + (vp_origin_y) )
|
|
|
|
|
|
|
|
/* Transform a homogeneous vertex position from model space to Cogl
|
|
|
|
* window coordinates (with 0,0 being top left) */
|
2009-05-08 11:32:01 -04:00
|
|
|
static void
|
|
|
|
transform_point (CoglMatrix *matrix_mv,
|
|
|
|
CoglMatrix *matrix_p,
|
|
|
|
float *viewport,
|
|
|
|
float *x,
|
|
|
|
float *y)
|
|
|
|
{
|
|
|
|
float z = 0;
|
|
|
|
float w = 1;
|
|
|
|
|
2009-10-21 18:22:45 -04:00
|
|
|
/* Apply the modelview matrix transform */
|
2009-05-08 11:32:01 -04:00
|
|
|
cogl_matrix_transform_point (matrix_mv, x, y, &z, &w);
|
|
|
|
|
2009-10-21 18:22:45 -04:00
|
|
|
/* Apply the projection matrix transform */
|
2009-05-08 11:32:01 -04:00
|
|
|
cogl_matrix_transform_point (matrix_p, x, y, &z, &w);
|
2009-10-21 18:22:45 -04:00
|
|
|
|
|
|
|
/* Perform perspective division */
|
|
|
|
*x /= w;
|
|
|
|
*y /= w;
|
|
|
|
|
2009-05-08 11:32:01 -04:00
|
|
|
/* Apply viewport transform */
|
2009-10-21 18:22:45 -04:00
|
|
|
*x = VIEWPORT_TRANSFORM_X (*x, viewport[0], viewport[2]);
|
|
|
|
*y = VIEWPORT_TRANSFORM_Y (*y, viewport[1], viewport[3]);
|
2009-05-08 11:32:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#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
|
2009-11-04 15:17:56 -05:00
|
|
|
try_pushing_rect_as_window_rect (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2009-05-08 11:32:01 -04:00
|
|
|
{
|
|
|
|
CoglMatrix matrix;
|
|
|
|
CoglMatrix matrix_p;
|
|
|
|
float v[4];
|
|
|
|
|
|
|
|
cogl_get_modelview_matrix (&matrix);
|
|
|
|
|
2009-10-16 19:31:26 -04:00
|
|
|
/* If the modelview meets these constraints then a transformed rectangle
|
|
|
|
* should still be a rectangle when it reaches screen coordinates.
|
|
|
|
*
|
|
|
|
* FIXME: we are are making certain assumptions about the projection
|
|
|
|
* matrix a.t.m and should really be looking at the combined modelview
|
|
|
|
* and projection matrix.
|
|
|
|
* FIXME: we don't consider rotations that are a multiple of 90 degrees
|
|
|
|
* which could be quite common.
|
|
|
|
*/
|
2009-05-08 11:32:01 -04:00
|
|
|
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);
|
|
|
|
|
2009-11-04 15:17:56 -05:00
|
|
|
transform_point (&matrix, &matrix_p, v, &x_1, &y_1);
|
|
|
|
transform_point (&matrix, &matrix_p, v, &x_2, &y_2);
|
2009-05-08 11:32:01 -04:00
|
|
|
|
2009-10-16 19:31:26 -04:00
|
|
|
/* Consider that the modelview matrix may flip the rectangle
|
|
|
|
* along the x or y axis... */
|
|
|
|
#define SWAP(A,B) do { float tmp = B; B = A; A = tmp; } while (0)
|
2009-11-04 15:17:56 -05:00
|
|
|
if (x_1 > x_2)
|
|
|
|
SWAP (x_1, x_2);
|
|
|
|
if (y_1 > y_2)
|
|
|
|
SWAP (y_1, y_2);
|
2009-10-16 19:31:26 -04:00
|
|
|
#undef SWAP
|
|
|
|
|
2010-02-17 10:58:32 -05:00
|
|
|
cogl_clip_push_window_rectangle (COGL_UTIL_NEARBYINT (x_1),
|
|
|
|
COGL_UTIL_NEARBYINT (y_1),
|
|
|
|
COGL_UTIL_NEARBYINT (x_2 - x_1),
|
|
|
|
COGL_UTIL_NEARBYINT (y_2 - y_1));
|
2009-05-08 11:32:01 -04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
[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 14:31:43 -05:00
|
|
|
void
|
|
|
|
cogl_clip_push_rectangle (float x_1,
|
|
|
|
float y_1,
|
|
|
|
float x_2,
|
|
|
|
float y_2)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackEntryRect *entry;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
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. */
|
2009-11-04 15:17:56 -05:00
|
|
|
if (try_pushing_rect_as_window_rect (x_1, y_1, x_2, y_2))
|
2009-05-08 11:32:01 -04:00
|
|
|
return;
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
stack = clip_state->stacks->data;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
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;
|
2009-11-04 15:17:56 -05:00
|
|
|
entry->x0 = x_1;
|
|
|
|
entry->y0 = y_1;
|
|
|
|
entry->x1 = x_2;
|
|
|
|
entry->y1 = y_2;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
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);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stack_dirty = TRUE;
|
2008-12-04 08:45:09 -05: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 14:31:43 -05:00
|
|
|
/* XXX: Deprecated API */
|
2009-11-04 15:17:56 -05:00
|
|
|
void
|
|
|
|
cogl_clip_push (float x_offset,
|
|
|
|
float y_offset,
|
|
|
|
float width,
|
|
|
|
float height)
|
|
|
|
{
|
[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 14:31:43 -05:00
|
|
|
cogl_clip_push_rectangle (x_offset,
|
|
|
|
y_offset,
|
|
|
|
x_offset + width,
|
|
|
|
y_offset + height);
|
2009-11-04 15:17:56 -05:00
|
|
|
}
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
void
|
2009-02-12 06:08:00 -05:00
|
|
|
cogl_clip_push_from_path_preserve (void)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackEntryPath *entry;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
stack = clip_state->stacks->data;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stack_dirty = TRUE;
|
2008-12-04 08:45:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
static void
|
|
|
|
_cogl_clip_pop_real (CoglClipStackState *clip_state)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
2009-09-25 09:34:34 -04:00
|
|
|
gpointer entry;
|
2009-05-08 11:32:01 -04:00
|
|
|
CoglClipStackEntryType type;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
stack = clip_state->stacks->data;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stack_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_clip_pop (void)
|
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
_cogl_clip_pop_real (clip_state);
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_flush_clip_state (CoglClipStackState *clip_state)
|
2008-06-23 10:57:36 -04:00
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStack *stack;
|
|
|
|
int has_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;
|
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-09 20:57:32 -05:00
|
|
|
int scissor_x0 = 0;
|
|
|
|
int scissor_y0 = 0;
|
|
|
|
int scissor_x1 = G_MAXINT;
|
|
|
|
int scissor_y1 = G_MAXINT;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglMatrixStack *modelview_stack =
|
2009-11-26 14:06:35 -05:00
|
|
|
_cogl_framebuffer_get_modelview_stack (_cogl_get_framebuffer ());
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
if (!clip_state->stack_dirty)
|
|
|
|
return;
|
2009-10-13 18:09:42 -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 ();
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* XXX: the handling of clipping is quite complex. It may involve use of
|
|
|
|
* the Cogl Journal or other Cogl APIs which may end up recursively
|
|
|
|
* wanting to ensure the clip state is flushed. We need to ensure we
|
|
|
|
* don't recurse infinitely...
|
|
|
|
*/
|
|
|
|
clip_state->stack_dirty = FALSE;
|
|
|
|
|
|
|
|
has_clip_planes = cogl_features_available (COGL_FEATURE_FOUR_CLIP_PLANES);
|
|
|
|
|
|
|
|
stack = clip_state->stacks->data;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stencil_used = FALSE;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-11-04 14:42:17 -05:00
|
|
|
disable_clip_planes ();
|
|
|
|
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;
|
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
_cogl_matrix_stack_set (modelview_stack, &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,
|
2009-10-05 08:37:11 -04:00
|
|
|
using_stencil_buffer,
|
|
|
|
TRUE);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
_cogl_matrix_stack_push (modelview_stack);
|
|
|
|
_cogl_matrix_stack_set (modelview_stack, &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)
|
|
|
|
{
|
2009-11-04 15:17:56 -05:00
|
|
|
set_clip_planes (rect->x0,
|
|
|
|
rect->y0,
|
|
|
|
rect->x1,
|
|
|
|
rect->y1);
|
2008-12-04 08:45:09 -05:00
|
|
|
using_clip_planes = TRUE;
|
|
|
|
/* We can't use clip planes a second time */
|
|
|
|
has_clip_planes = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-11-04 15:17:56 -05:00
|
|
|
add_stencil_clip_rectangle (rect->x0,
|
|
|
|
rect->y0,
|
|
|
|
rect->x1,
|
|
|
|
rect->y1,
|
2009-11-04 14:42:17 -05:00
|
|
|
!using_stencil_buffer);
|
2008-12-04 08:45:09 -05:00
|
|
|
using_stencil_buffer = TRUE;
|
|
|
|
}
|
|
|
|
|
2009-10-13 18:09:42 -04:00
|
|
|
_cogl_matrix_stack_pop (modelview_stack);
|
2008-12-04 08:45:09 -05:00
|
|
|
}
|
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)
|
2009-11-04 14:42:17 -05:00
|
|
|
enable_clip_planes ();
|
2008-12-04 08:45:09 -05:00
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stencil_used = using_stencil_buffer;
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* XXX: This should never have been made public API! */
|
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
|
|
|
{
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
2008-06-23 10:57:36 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (_cogl_get_framebuffer ());
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_flush_clip_state (clip_state);
|
2008-06-23 10:57:36 -04:00
|
|
|
}
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
static void
|
|
|
|
_cogl_clip_stack_save_real (CoglClipStackState *clip_state)
|
2008-08-01 08:23:57 -04:00
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
CoglClipStack *stack;
|
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
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
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stacks = g_slist_prepend (clip_state->stacks, stack);
|
|
|
|
clip_state->stack_dirty = TRUE;
|
2008-08-01 08:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-25 09:34:34 -04:00
|
|
|
cogl_clip_stack_save (void)
|
2008-08-01 08:23:57 -04:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
_cogl_clip_stack_save_real (clip_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cogl_clip_stack_restore_real (CoglClipStackState *clip_state)
|
|
|
|
{
|
|
|
|
CoglClipStack *stack;
|
|
|
|
|
|
|
|
g_return_if_fail (clip_state->stacks != NULL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
/* We don't log clip stack changes in the journal so we must flush
|
|
|
|
* it before making modifications */
|
|
|
|
_cogl_journal_flush ();
|
|
|
|
|
|
|
|
stack = clip_state->stacks->data;
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
/* Empty the current stack */
|
|
|
|
while (stack->stack_top)
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_clip_pop_real (clip_state);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
|
|
|
/* Revert to an old stack */
|
|
|
|
g_slice_free (CoglClipStack, stack);
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stacks = g_slist_delete_link (clip_state->stacks,
|
|
|
|
clip_state->stacks);
|
2008-12-04 08:45:09 -05:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stack_dirty = TRUE;
|
2008-12-04 08:45:09 -05:00
|
|
|
}
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
void
|
2009-09-25 09:34:34 -04:00
|
|
|
cogl_clip_stack_restore (void)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
2009-11-26 14:06:35 -05:00
|
|
|
CoglHandle framebuffer;
|
2009-09-25 09:34:34 -04:00
|
|
|
CoglClipStackState *clip_state;
|
|
|
|
|
2008-12-04 08:45:09 -05:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2009-11-26 14:06:35 -05:00
|
|
|
framebuffer = _cogl_get_framebuffer ();
|
|
|
|
clip_state = _cogl_framebuffer_get_clip_state (framebuffer);
|
2009-02-12 06:08:00 -05:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_clip_stack_restore_real (clip_state);
|
2008-12-04 08:45:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-09-25 09:34:34 -04:00
|
|
|
_cogl_clip_stack_state_init (CoglClipStackState *clip_state)
|
2008-12-04 08:45:09 -05:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
2008-08-01 08:23:57 -04:00
|
|
|
|
2009-09-25 09:34:34 -04:00
|
|
|
clip_state->stacks = NULL;
|
|
|
|
clip_state->stack_dirty = TRUE;
|
|
|
|
|
|
|
|
/* Add an intial stack */
|
|
|
|
_cogl_clip_stack_save_real (clip_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_clip_stack_state_destroy (CoglClipStackState *clip_state)
|
|
|
|
{
|
2008-12-04 08:45:09 -05:00
|
|
|
/* Destroy all of the stacks */
|
2009-09-25 09:34:34 -04:00
|
|
|
while (clip_state->stacks)
|
|
|
|
_cogl_clip_stack_restore_real (clip_state);
|
2008-08-01 08:23:57 -04:00
|
|
|
}
|
2009-09-25 09:34:34 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
_cogl_clip_stack_state_dirty (CoglClipStackState *clip_state)
|
|
|
|
{
|
|
|
|
clip_state->stack_dirty = TRUE;
|
|
|
|
}
|
|
|
|
|