2007-05-28 Matthew Allum <mallum@openedhand.com>

* clutter/clutter-backend.c:
        * clutter/clutter-backend.h:
        * clutter/glx/clutter-stage-glx.c:
        * clutter/glx/clutter-backend-glx.c:
        Fix up rendering pipeline removing clutter_backend_XXX_stage_paint
        and adding clutter_backend_XXX_redraw instead. Duplicates less
        code in backends, avoids clutter_actor_paint() getting called
        before stage is set up (viewport wise) and unbreaks things like
        picking.

        * clutter/clutter-actor.c:
        * clutter/clutter-actor.h:
        * clutter/clutter-main.c:
        * clutter/clutter-private.h:
        * clutter/clutter-stage.c: (clutter_stage_get_actor_at_pos):
        Redo picking functionality a different way (via color indexing)
        as to provide more flexibility, possibly speed and more likely
        work with GL/ES (doesn't currently however - not sure why).

        * clutter/clutter-group.c:
        Add groups own 'pick' method.

        * clutter/cogl/cogl.h:
        * clutter/cogl/gl/cogl.c:
        * clutter/cogl/gles/cogl.c:
        Move clipping funtionality into cogl.

        * clutter/cogl/gles/cogl-defines.h:
        Hack around missing BGR format in GL/ES.

        * clutter/egl/clutter-backend-egl.c:
        * clutter/egl/clutter-backend-egl.h:
        * clutter/egl/clutter-stage-egl.c:
        * clutter/sdl/clutter-backend-sdl.c:
        * clutter/sdl/clutter-backend-sdl.h:
        * clutter/sdl/clutter-event-sdl.c:
        * clutter/sdl/clutter-stage-sdl.c:
        Update backends to newer API.
        Add basic mouse event translation to SDL.
This commit is contained in:
Matthew Allum 2007-05-28 18:49:34 +00:00
parent 4df0665012
commit 7c7fcc2cb9
4 changed files with 86 additions and 84 deletions

10
cogl.h
View File

@ -77,7 +77,7 @@ cogl_setup_viewport (guint width,
ClutterFixed z_far);
void
cogl_paint_init (ClutterColor *color);
cogl_paint_init (const ClutterColor *color);
void
cogl_push_matrix (void);
@ -101,7 +101,13 @@ void
cogl_rotate (gint angle, gint x, gint y, gint z);
void
cogl_color (ClutterColor *color);
cogl_color (const ClutterColor *color);
void
cogl_clip_set (const ClutterGeometry *clip);
void
cogl_clip_unset (void);
void
cogl_enable (gulong flags);

104
gl/cogl.c
View File

@ -139,7 +139,7 @@ cogl_check_extension (const gchar *name, const gchar *ext)
}
void
cogl_paint_init (ClutterColor *color)
cogl_paint_init (const ClutterColor *color)
{
GE( glClearColor (((float) color->red / 0xff * 1.0),
((float) color->green / 0xff * 1.0),
@ -266,11 +266,39 @@ cogl_enable (gulong flags)
}
void
cogl_color (ClutterColor *color)
cogl_color (const ClutterColor *color)
{
glColor4ub (color->red, color->green, color->blue, color->alpha);
}
void
cogl_clip_set (const ClutterGeometry *clip)
{
GE( glEnable (GL_STENCIL_TEST) );
GE( glClearStencil (0.0f) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glColor3f (1.0f, 1.0f, 1.0f) );
GE( glRecti (clip->x,
clip->y,
clip->x + clip->width,
clip->y + clip->height) );
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
; GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
}
void
cogl_clip_unset (void)
{
GE( glDisable (GL_STENCIL_TEST) );
}
gboolean
cogl_texture_can_size (COGLenum pixel_format,
COGLenum pixel_type,
@ -423,7 +451,6 @@ cogl_trapezoid (gint y1,
GE( glEnd () );
}
void
cogl_alpha_func (COGLenum func,
ClutterFixed ref)
@ -431,61 +458,6 @@ cogl_alpha_func (COGLenum func,
GE( glAlphaFunc (func, CLUTTER_FIXED_TO_FLOAT(ref)) );
}
#if 0
/*
* Original floating point implementaiton of the perspective function,
* retained for reference purposes
*/
static inline void
frustum (GLfloat left,
GLfloat right,
GLfloat bottom,
GLfloat top,
GLfloat nearval,
GLfloat farval)
{
GLfloat x, y, a, b, c, d;
GLfloat m[16];
x = (2.0 * nearval) / (right - left);
y = (2.0 * nearval) / (top - bottom);
a = (right + left) / (right - left);
b = (top + bottom) / (top - bottom);
c = -(farval + nearval) / ( farval - nearval);
d = -(2.0 * farval * nearval) / (farval - nearval);
#define M(row,col) m[col*4+row]
M(0,0) = x; M(0,1) = 0.0F; M(0,2) = a; M(0,3) = 0.0F;
M(1,0) = 0.0F; M(1,1) = y; M(1,2) = b; M(1,3) = 0.0F;
M(2,0) = 0.0F; M(2,1) = 0.0F; M(2,2) = c; M(2,3) = d;
M(3,0) = 0.0F; M(3,1) = 0.0F; M(3,2) = -1.0F; M(3,3) = 0.0F;
#undef M
GE( glMultMatrixf (m) );
}
static inline void
perspective (GLfloat fovy,
GLfloat aspect,
GLfloat zNear,
GLfloat zFar)
{
GLfloat xmin, xmax, ymin, ymax;
ymax = zNear * tan (fovy * M_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
xmax = ymax * aspect;
printf ("%f, %f, %f, %f\n", xmin, xmax, ymin, ymax);
frustum (xmin, xmax, ymin, ymax, zNear, zFar);
}
#endif
/*
* Fixed point implementation of the perspective function
*/
void
cogl_perspective (ClutterAngle fovy,
ClutterFixed aspect,
@ -495,11 +467,7 @@ cogl_perspective (ClutterAngle fovy,
ClutterFixed xmax, ymax;
ClutterFixed x, y, c, d;
#ifdef HAVE_COGL_GL
GLfloat m[16];
#else
GLfixed m[16];
#endif
memset (&m[0], 0, sizeof (m));
@ -521,7 +489,6 @@ cogl_perspective (ClutterAngle fovy,
d = CFX_DIV (-(clutter_qmulx (2*zFar, zNear)), (zFar - zNear));
#define M(row,col) m[col*4+row]
#ifdef HAVE_COGL_GL
M(0,0) = CLUTTER_FIXED_TO_FLOAT (x);
M(1,1) = CLUTTER_FIXED_TO_FLOAT (y);
M(2,2) = CLUTTER_FIXED_TO_FLOAT (c);
@ -529,15 +496,6 @@ cogl_perspective (ClutterAngle fovy,
M(3,2) = -1.0F;
GE( glMultMatrixf (m) );
#else
M(0,0) = x;
M(1,1) = y;
M(2,2) = c;
M(2,3) = d;
M(3,2) = 1 + ~CFX_ONE;
GE( glMultMatrixx (m) );
#endif
#undef M
}
@ -568,7 +526,7 @@ cogl_setup_viewport (guint width,
GE( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glScalef ( 1.0f / width,
-1.0f / height,
-1.0f / height,
1.0f / width) );
GE( glTranslatef (0.0f, -1.0 * height, 0.0f) );
}

View File

@ -444,6 +444,13 @@ typedef GLint COGLint;
#define CGL_TEXTURE_2D GL_TEXTURE_2D
#define CGL_ARGB GL_ARGB
/* FIXME: There is no BGR support in GLES - so with below BGR textures are
* borked. Will likely need a feature flag and some coversion..
*/
#define CGL_BGR GL_RGB
#define CGL_BGRA GL_RGBA
#define CGL_TEXTURE_RECTANGLE_ARB 0 /* Its unlikely we support this */
G_END_DECLS

View File

@ -100,7 +100,7 @@ cogl_check_extension (const gchar *name, const gchar *ext)
}
void
cogl_paint_init (ClutterColor *color)
cogl_paint_init (const ClutterColor *color)
{
#if COGL_DEBUG
fprintf(stderr, "\n ============== Paint Start ================ \n");
@ -234,7 +234,7 @@ cogl_enable (gulong flags)
}
void
cogl_color (ClutterColor *color)
cogl_color (const ClutterColor *color)
{
GE( glColor4x ((color->red << 16) / 0xff,
(color->green << 16) / 0xff,
@ -242,19 +242,45 @@ cogl_color (ClutterColor *color)
(color->alpha << 16) / 0xff) );
}
void
cogl_clip_set (const ClutterGeometry *clip)
{
GE( glEnable (GL_STENCIL_TEST) );
GE( glClearStencil (0) );
GE( glClear (GL_STENCIL_BUFFER_BIT) );
GE( glStencilFunc (GL_NEVER, 0x1, 0x1) );
GE( glStencilOp (GL_INCR, GL_INCR, GL_INCR) );
GE( glColor4x (CFX_ONE, CFX_ONE, CFX_ONE, CFX_ONE ) );
cogl_rectangle (clip->x, clip->y, clip->width, clip->height);
GE( glStencilFunc (GL_EQUAL, 0x1, 0x1) );
GE( glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
}
void
cogl_clip_unset (void)
{
GE( glDisable (GL_STENCIL_TEST) );
}
gboolean
cogl_texture_can_size (COGLenum pixel_format,
COGLenum pixel_type,
int width,
int height)
{
GLint new_width = 0;
/* FIXME */
return TRUE;
#if 0
GLint new_width = 0;
GE( glTexImage2D (GL_PROXY_TEXTURE_2D, 0, GL_RGBA,
width, height, 0 /* border */,
pixel_format, pixel_type, NULL) );
@ -433,8 +459,6 @@ cogl_alpha_func (COGLenum func,
GE( glAlphaFunc (func, CLUTTER_FIXED_TO_FLOAT(ref)) );
}
/*
* Fixed point implementation of the perspective function
*/
@ -507,8 +531,15 @@ cogl_setup_viewport (guint w,
/* camera distance from screen, 0.5 * tan (FOV) */
#define DEFAULT_Z_CAMERA 0.866025404f
z_camera = clutter_tani (fovy) << 1;
GE( glTranslatex (-1 << 15, -1 << 15, -z_camera );
/*
printf("%i vs %i\n",
CLUTTER_FLOAT_TO_FIXED(DEFAULT_Z_CAMERA),
clutter_tani (fovy) << 1);
*/
GE( glTranslatex (-1 << 15, -1 << 15, /*-z_camera*/
-CLUTTER_FLOAT_TO_FIXED(DEFAULT_Z_CAMERA)));
GE( glScalex ( CFX_ONE / width,
-CFX_ONE / height,