From 471da532a31a6757e68c2c82355d964092ac6b0b Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 24 Dec 2007 12:53:04 +0000 Subject: [PATCH] 2007-12-24 Emmanuele Bassi * clutter/cogl/cogl.h: Update cogl_clip_set() to accept the clip components as ClutterFixed values * clutter/cogl/gl/cogl.c (cogl_clip_set): Update the GL implementation of cogl_clip_set() * clutter/cogl/gles/cogl.c: (cogl_rectangle_internal): Provide an internal, inlined rectangle drawing function using fixed point values, to be shared by cogl_clip_set() and cogl_rectangle() (cogl_clip_set), (cogl_rectangle): Update the GLES implementation of cogl_clip_set() and cogl_rectangle() to use the new internal rectangle drawing function * clutter/clutter-actor.c: Make the clip an array of ClutterUnit values instead of pixel-based; this allows higher precision and device independence (_clutter_actor_apply_modelview_transform): Pass the clip components converting from units to fixed point values, using the new cogl_clip_set() signature (clutter_actor_get_property), (clutter_actor_set_clip), (clutter_actor_get_clip): Update the accessors of the clip property --- cogl.h | 5 ++++- gl/cogl.c | 15 +++++++++------ gles/cogl.c | 52 +++++++++++++++++++++++++++++++++------------------- 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/cogl.h b/cogl.h index cb0250a33..7bc5d0dc9 100644 --- a/cogl.h +++ b/cogl.h @@ -107,7 +107,10 @@ void cogl_color (const ClutterColor *color); void -cogl_clip_set (const ClutterGeometry *clip); +cogl_clip_set (ClutterFixed x_offset, + ClutterFixed y_offset, + ClutterFixed width, + ClutterFixed height); void cogl_clip_unset (void); diff --git a/gl/cogl.c b/gl/cogl.c index 4a586341d..7cf7b1f15 100644 --- a/gl/cogl.c +++ b/gl/cogl.c @@ -299,7 +299,10 @@ cogl_color (const ClutterColor *color) } void -cogl_clip_set (const ClutterGeometry *clip) +cogl_clip_set (ClutterFixed x_offset, + ClutterFixed y_offset, + ClutterFixed width, + ClutterFixed height) { GE( glEnable (GL_STENCIL_TEST) ); @@ -311,13 +314,13 @@ cogl_clip_set (const ClutterGeometry *clip) GE( glColor3f (1.0f, 1.0f, 1.0f) ); - GE( glRecti (clip->x, - clip->y, - clip->x + clip->width, - clip->y + clip->height) ); + GE( glRectf (CLUTTER_FIXED_TO_FLOAT (x_offset), + CLUTTER_FIXED_TO_FLOAT (y_offset), + CLUTTER_FIXED_TO_FLOAT (x_offset + width), + CLUTTER_FIXED_TO_FLOAT (y_offset + height)) ); GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) ); -; GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) ); + GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) ); } void diff --git a/gles/cogl.c b/gles/cogl.c index e10efc52c..3d325ffee 100644 --- a/gles/cogl.c +++ b/gles/cogl.c @@ -262,8 +262,30 @@ cogl_color (const ClutterColor *color) #endif } +static inline void +cogl_rectangle_internal (ClutterFixed x, + ClutterFixed y, + ClutterFixed width, + ClutterFixed height) +{ + GLfixed rect_verts[4] = { + x, y, + x + width, y, + x, y + height, + x + width, y + height + }; + + GE( glEnableClientState (GL_VERTEX_ARRAY) ); + GE( glVertexPointer (2, GL_FIXED, 0, rect_verts) ); + GE( glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) ); + GE( glDisableClientState (GL_VERTEX_ARRAY) ); +} + void -cogl_clip_set (const ClutterGeometry *clip) +cogl_clip_set (ClutterFixed x_offset, + ClutterFixed y_offset, + ClutterFixed width, + ClutterFixed height) { GE( glEnable (GL_STENCIL_TEST) ); @@ -275,8 +297,8 @@ cogl_clip_set (const ClutterGeometry *clip) GE( glColor4x (CFX_ONE, CFX_ONE, CFX_ONE, CFX_ONE ) ); - cogl_rectangle (clip->x, clip->y, clip->width, clip->height); - + cogl_rectangle_internal (x_offset, y_offset, width, height); + GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) ); GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) ); } @@ -432,23 +454,15 @@ cogl_texture_sub_image_2d (COGLenum target, } void -cogl_rectangle (gint x, gint y, guint width, guint height) +cogl_rectangle (gint x, + gint y, + guint width, + guint height) { -#define FIX CLUTTER_INT_TO_FIXED - - GLfixed rect_verts[] = { - FIX(x), FIX(y), - FIX((x + width)), FIX(y), - FIX(x), FIX((y + height)), - FIX((x + width)), FIX((y + height)), - }; - -#undef FIX - - GE( glEnableClientState(GL_VERTEX_ARRAY) ); - GE( glVertexPointer(2, GL_FIXED, 0, rect_verts) ); - GE( glDrawArrays(GL_TRIANGLE_STRIP, 0, 4) ); - GE( glDisableClientState(GL_VERTEX_ARRAY) ); + cogl_rectangle_internal (CLUTTER_INT_TO_FIXED (x), + CLUTTER_INT_TO_FIXED (y), + CLUTTER_INT_TO_FIXED (width), + CLUTTER_INT_TO_FIXED (height)); } /* FIXME: Should use ClutterReal or Fixed */