2008-04-25 09:37:36 -04:00
|
|
|
/*
|
|
|
|
* Clutter COGL
|
|
|
|
*
|
|
|
|
* A basic GL/GLES Abstraction/Utility Layer
|
|
|
|
*
|
|
|
|
* Authored By Matthew Allum <mallum@openedhand.com>
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 OpenedHand
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
|
|
|
|
#include "cogl.h"
|
|
|
|
#include "cogl-internal.h"
|
|
|
|
#include "cogl-context.h"
|
2008-06-23 10:57:36 -04:00
|
|
|
#include "cogl-clip-stack.h"
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <gmodule.h>
|
|
|
|
|
|
|
|
#define _COGL_MAX_BEZ_RECURSE_DEPTH 16
|
|
|
|
|
|
|
|
void
|
2008-05-05 08:01:19 -04:00
|
|
|
_cogl_rectangle (gint x,
|
|
|
|
gint y,
|
|
|
|
guint width,
|
|
|
|
guint height)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
cogl_enable (ctx->color_alpha < 255
|
|
|
|
? COGL_ENABLE_BLEND : 0);
|
|
|
|
|
|
|
|
GE( glRecti (x, y, x + width, y + height) );
|
|
|
|
}
|
|
|
|
|
2008-04-28 10:18:29 -04:00
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
void
|
2008-10-30 12:37:55 -04:00
|
|
|
_cogl_rectanglex (CoglFixed x,
|
|
|
|
CoglFixed y,
|
|
|
|
CoglFixed width,
|
|
|
|
CoglFixed height)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
cogl_enable (ctx->color_alpha < 255
|
|
|
|
? COGL_ENABLE_BLEND : 0);
|
|
|
|
|
2008-10-30 12:37:55 -04:00
|
|
|
GE( glRectf (COGL_FIXED_TO_FLOAT (x),
|
|
|
|
COGL_FIXED_TO_FLOAT (y),
|
|
|
|
COGL_FIXED_TO_FLOAT (x + width),
|
|
|
|
COGL_FIXED_TO_FLOAT (y + height)) );
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|
|
|
|
|
2008-04-30 11:05:17 -04:00
|
|
|
void
|
2008-04-25 09:37:36 -04:00
|
|
|
_cogl_path_clear_nodes ()
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
if (ctx->path_nodes)
|
|
|
|
g_free(ctx->path_nodes);
|
|
|
|
|
|
|
|
ctx->path_nodes = (CoglFloatVec2*) g_malloc (2 * sizeof(CoglFloatVec2));
|
|
|
|
ctx->path_nodes_size = 0;
|
|
|
|
ctx->path_nodes_cap = 2;
|
|
|
|
}
|
|
|
|
|
2008-04-30 11:05:17 -04:00
|
|
|
void
|
2008-10-30 12:37:55 -04:00
|
|
|
_cogl_path_add_node (CoglFixed x,
|
|
|
|
CoglFixed y)
|
2008-04-25 09:37:36 -04:00
|
|
|
{
|
|
|
|
CoglFloatVec2 *new_nodes = NULL;
|
|
|
|
|
2008-06-23 07:01:30 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
if (ctx->path_nodes_size == ctx->path_nodes_cap)
|
|
|
|
{
|
|
|
|
new_nodes = g_realloc (ctx->path_nodes,
|
|
|
|
2 * ctx->path_nodes_cap
|
|
|
|
* sizeof (CoglFloatVec2));
|
|
|
|
|
|
|
|
if (new_nodes == NULL) return;
|
|
|
|
|
|
|
|
ctx->path_nodes = new_nodes;
|
|
|
|
ctx->path_nodes_cap *= 2;
|
|
|
|
}
|
|
|
|
|
2008-10-30 12:37:55 -04:00
|
|
|
ctx->path_nodes [ctx->path_nodes_size] .x = COGL_FIXED_TO_FLOAT (x);
|
|
|
|
ctx->path_nodes [ctx->path_nodes_size] .y = COGL_FIXED_TO_FLOAT (y);
|
2008-04-25 09:37:36 -04:00
|
|
|
ctx->path_nodes_size++;
|
|
|
|
|
|
|
|
if (ctx->path_nodes_size == 1)
|
|
|
|
{
|
|
|
|
ctx->path_nodes_min.x = ctx->path_nodes_max.x = x;
|
|
|
|
ctx->path_nodes_min.y = ctx->path_nodes_max.y = y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (x < ctx->path_nodes_min.x) ctx->path_nodes_min.x = x;
|
|
|
|
if (x > ctx->path_nodes_max.x) ctx->path_nodes_max.x = x;
|
|
|
|
if (y < ctx->path_nodes_min.y) ctx->path_nodes_min.y = y;
|
|
|
|
if (y > ctx->path_nodes_max.y) ctx->path_nodes_max.y = y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-30 11:05:17 -04:00
|
|
|
void
|
2008-04-25 09:37:36 -04:00
|
|
|
_cogl_path_stroke_nodes ()
|
|
|
|
{
|
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
|
|
|
cogl_enable (COGL_ENABLE_VERTEX_ARRAY
|
|
|
|
| (ctx->color_alpha < 255
|
|
|
|
? COGL_ENABLE_BLEND : 0));
|
|
|
|
|
|
|
|
GE( glVertexPointer (2, GL_FLOAT, 0, ctx->path_nodes) );
|
|
|
|
GE( glDrawArrays (GL_LINE_STRIP, 0, ctx->path_nodes_size) );
|
|
|
|
}
|
|
|
|
|
2008-05-05 08:01:19 -04:00
|
|
|
void
|
2008-04-25 09:37:36 -04:00
|
|
|
_cogl_path_fill_nodes ()
|
|
|
|
{
|
|
|
|
guint bounds_x;
|
|
|
|
guint bounds_y;
|
|
|
|
guint bounds_w;
|
|
|
|
guint bounds_h;
|
|
|
|
|
2008-06-23 07:01:30 -04:00
|
|
|
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
|
|
|
|
|
2008-04-25 09:37:36 -04:00
|
|
|
GE( glClear (GL_STENCIL_BUFFER_BIT) );
|
|
|
|
|
|
|
|
GE( glEnable (GL_STENCIL_TEST) );
|
2008-06-23 10:57:36 -04:00
|
|
|
GE( glStencilFunc (GL_NEVER, 0x0, 0x1) );
|
2008-04-25 09:37:36 -04:00
|
|
|
GE( glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT) );
|
2008-06-23 10:57:36 -04:00
|
|
|
|
|
|
|
GE( glStencilMask (1) );
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
cogl_enable (COGL_ENABLE_VERTEX_ARRAY
|
2008-04-29 11:41:34 -04:00
|
|
|
| (ctx->color_alpha < 255 ? COGL_ENABLE_BLEND : 0));
|
2008-04-25 09:37:36 -04:00
|
|
|
|
|
|
|
GE( glVertexPointer (2, GL_FLOAT, 0, ctx->path_nodes) );
|
|
|
|
GE( glDrawArrays (GL_TRIANGLE_FAN, 0, ctx->path_nodes_size) );
|
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
GE( glStencilMask (~(GLuint) 0) );
|
|
|
|
|
|
|
|
/* Merge the stencil buffer with any clipping rectangles */
|
|
|
|
_cogl_clip_stack_merge ();
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
|
|
|
|
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
|
|
|
|
|
2008-10-30 12:37:55 -04:00
|
|
|
bounds_x = COGL_FIXED_FLOOR (ctx->path_nodes_min.x);
|
|
|
|
bounds_y = COGL_FIXED_FLOOR (ctx->path_nodes_min.y);
|
|
|
|
bounds_w = COGL_FIXED_CEIL (ctx->path_nodes_max.x - ctx->path_nodes_min.x);
|
|
|
|
bounds_h = COGL_FIXED_CEIL (ctx->path_nodes_max.y - ctx->path_nodes_min.y);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-04-29 11:41:34 -04:00
|
|
|
cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h);
|
2008-04-25 09:37:36 -04:00
|
|
|
|
2008-06-23 10:57:36 -04:00
|
|
|
/* Rebuild the stencil clip */
|
|
|
|
_cogl_clip_stack_rebuild (TRUE);
|
2008-04-25 09:37:36 -04:00
|
|
|
}
|