Normalizes gl vs gles code in preperation for synching material changes

This changes all GLES code to use the OpenGL function names instead of
the cogl_wrap_* names. For GLES2 we now define the OpenGL name to point
to the wrapper, as opposed to defining the wrapper to point to the
OpenGL name for GLES1.

I've also done a quick pass through gl/cogl.c and gles/cogl.c to make
them more easily comparable. (most of the code is now identical)
This commit is contained in:
Robert Bragg 2009-01-24 16:55:04 +00:00
parent 427fff032e
commit 60e81f0fda
7 changed files with 561 additions and 565 deletions

View File

@ -47,8 +47,8 @@ _cogl_path_add_node (gboolean new_sub_path,
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
new_node.x = (x);
new_node.y = (y);
new_node.x = x;
new_node.y = y;
new_node.path_size = 0;
if (new_sub_path || ctx->path_nodes->len == 0)
@ -123,15 +123,23 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
CoglPathNode *path,
gboolean merge)
{
guint path_start = 0;
guint sub_path_num = 0;
float bounds_x;
float bounds_y;
float bounds_w;
float bounds_h;
guint path_start = 0;
guint sub_path_num = 0;
float bounds_x;
float bounds_y;
float bounds_w;
float bounds_h;
gulong enable_flags = COGL_ENABLE_VERTEX_ARRAY;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
/* Just setup a simple material that doesn't use texturing... */
cogl_material_flush_gl_state (ctx->stencil_material, NULL);
enable_flags |=
cogl_material_get_cogl_enable_flags (ctx->source_material);
cogl_enable (enable_flags);
_cogl_path_get_bounds (nodes_min, nodes_max,
&bounds_x, &bounds_y, &bounds_w, &bounds_h);
@ -155,15 +163,6 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
while (path_start < path_size)
{
gulong enable_flags = COGL_ENABLE_VERTEX_ARRAY;
/* Just setup a simple material that doesn't use texturing... */
cogl_material_flush_gl_state (ctx->stencil_material, NULL);
enable_flags |=
cogl_material_get_cogl_enable_flags (ctx->source_material);
cogl_enable (enable_flags);
GE( glVertexPointer (2, GL_FLOAT, sizeof (CoglPathNode),
(guchar *) path
+ G_STRUCT_OFFSET (CoglPathNode, x)) );
@ -201,8 +200,8 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( glRecti (-1, 1, 1, -1) );
GE( glRecti (-1, 1, 1, -1) );
cogl_rectangle (-1.0, -1.0, 2, 2);
cogl_rectangle (-1.0, -1.0, 2, 2);
GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
@ -226,6 +225,9 @@ _cogl_path_fill_nodes ()
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
_cogl_path_get_bounds (ctx->path_nodes_min, ctx->path_nodes_max,
&bounds_x, &bounds_y, &bounds_w, &bounds_h);
_cogl_add_path_to_stencil_buffer (ctx->path_nodes_min,
ctx->path_nodes_max,
ctx->path_nodes->len,
@ -233,9 +235,6 @@ _cogl_path_fill_nodes ()
CoglPathNode, 0),
ctx->clip.stencil_used);
_cogl_path_get_bounds (ctx->path_nodes_min, ctx->path_nodes_max,
&bounds_x, &bounds_y, &bounds_w, &bounds_h);
cogl_rectangle (bounds_x, bounds_y, bounds_w, bounds_h);
/* The stencil buffer now contains garbage so the clip area needs to

View File

@ -171,6 +171,10 @@ cogl_check_extension (const gchar *name, const gchar *ext)
void
cogl_paint_init (const CoglColor *color)
{
#if COGL_DEBUG
fprintf(stderr, "\n ============== Paint Start ================ \n");
#endif
GE( glClearColor (cogl_color_get_red_float (color),
cogl_color_get_green_float (color),
cogl_color_get_blue_float (color),
@ -199,33 +203,31 @@ cogl_paint_init (const CoglColor *color)
void
cogl_push_matrix (void)
{
glPushMatrix();
GE( glPushMatrix() );
}
void
cogl_pop_matrix (void)
{
glPopMatrix();
GE( glPopMatrix() );
}
void
cogl_scale (float x, float y)
{
glScalef ((float)(x),
(float)(y),
1.0);
GE( glScalef (x, y, 1.0) );
}
void
cogl_translate (float x, float y, float z)
{
glTranslatef (x, y, z);
GE( glTranslatef (x, y, z) );
}
void
cogl_rotate (float angle, float x, float y, float z)
{
glRotatef (angle, x, y, z);
GE( glRotatef (angle, x, y, z) );
}
static inline gboolean
@ -353,10 +355,10 @@ cogl_set_source_color (const CoglColor *color)
}
static void
apply_matrix (const GLfloat *matrix, GLfloat *vertex)
apply_matrix (const float *matrix, float *vertex)
{
int x, y;
GLfloat vertex_out[4] = { 0 };
float vertex_out[4] = { 0 };
for (y = 0; y < 4; y++)
for (x = 0; x < 4; x++)
@ -366,7 +368,9 @@ apply_matrix (const GLfloat *matrix, GLfloat *vertex)
}
static void
project_vertex (GLfloat *modelview, GLfloat *project, GLfloat *vertex)
project_vertex (float *modelview,
float *project,
float *vertex)
{
int i;
@ -381,8 +385,8 @@ project_vertex (GLfloat *modelview, GLfloat *project, GLfloat *vertex)
static void
set_clip_plane (GLint plane_num,
const GLfloat *vertex_a,
const GLfloat *vertex_b)
const float *vertex_a,
const float *vertex_b)
{
GLdouble plane[4];
GLfloat angle;
@ -390,15 +394,15 @@ set_clip_plane (GLint plane_num,
/* 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.0f / G_PI;
angle = atan2f (vertex_b[1] - vertex_a[1],
vertex_b[0] - vertex_a[0]) * (180.0/G_PI);
GE( glPushMatrix () );
/* Load the identity matrix and multiply by the reverse of the
projection matrix so we can specify the plane in screen
coordinates */
GE( glLoadIdentity () );
GE( glMultMatrixf (ctx->inverse_projection) );
GE( glMultMatrixf ((GLfloat *) ctx->inverse_projection) );
/* Rotate about point a */
GE( glTranslatef (vertex_a[0], vertex_a[1], vertex_a[2]) );
/* Rotate the plane by the calculated angle so that it will connect
@ -406,9 +410,9 @@ set_clip_plane (GLint plane_num,
GE( glRotatef (angle, 0.0f, 0.0f, 1.0f) );
GE( glTranslatef (-vertex_a[0], -vertex_a[1], -vertex_a[2]) );
plane[0] = 0.0f;
plane[1] = -1.0f;
plane[2] = 0.0f;
plane[0] = 0;
plane[1] = -1.0;
plane[2] = 0;
plane[3] = vertex_a[1];
GE( glClipPlane (plane_num, plane) );
@ -423,18 +427,11 @@ _cogl_set_clip_planes (float x_offset,
{
GLfloat modelview[16], projection[16];
GLfloat vertex_tl[4] = { (x_offset),
(y_offset),
0.0f, 1.0f };
GLfloat vertex_tr[4] = { (x_offset + width),
(y_offset),
0.0f, 1.0f };
GLfloat vertex_bl[4] = { (x_offset),
(y_offset + height),
0.0f, 1.0f };
GLfloat vertex_br[4] = { (x_offset + width),
(y_offset + height),
0.0f, 1.0f };
float vertex_tl[4] = { x_offset, y_offset, 0, 1.0 };
float vertex_tr[4] = { x_offset + width, y_offset, 0, 1.0 };
float vertex_bl[4] = { x_offset, y_offset + height, 0, 1.0 };
float vertex_br[4] = { x_offset + width, y_offset + height,
0, 1.0 };
GE( glGetFloatv (GL_MODELVIEW_MATRIX, modelview) );
GE( glGetFloatv (GL_PROJECTION_MATRIX, projection) );
@ -452,7 +449,7 @@ _cogl_set_clip_planes (float x_offset,
if ((vertex_tl[0] < vertex_tr[0] ? 1 : 0)
!= (vertex_bl[1] < vertex_tl[1] ? 1 : 0))
{
GLfloat temp[4];
float temp[4];
memcpy (temp, vertex_tl, sizeof (temp));
memcpy (vertex_tl, vertex_tr, sizeof (temp));
memcpy (vertex_tr, temp, sizeof (temp));
@ -512,7 +509,7 @@ _cogl_add_stencil_clip (float x_offset,
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( glRecti (-1, 1, 1, -1) );
GE( glRectf (-1, 1, 1, -1) );
GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
@ -526,14 +523,8 @@ _cogl_add_stencil_clip (float x_offset,
void
_cogl_set_matrix (const float *matrix)
{
float float_matrix[16];
int i;
for (i = 0; i < 16; i++)
float_matrix[i] = (matrix[i]);
GE( glLoadIdentity () );
GE( glMultMatrixf (float_matrix) );
GE( glMultMatrixf (matrix) );
}
void
@ -597,26 +588,27 @@ cogl_perspective (float fovy,
d = (-(2 * zFar) * zNear) / (zFar - zNear);
#define M(row,col) m[col*4+row]
M(0,0) = (x);
M(1,1) = (y);
M(2,2) = (c);
M(2,3) = (d);
M(3,2) = -1.0F;
M(0,0) = x;
M(1,1) = y;
M(2,2) = c;
M(2,3) = d;
M(3,2) = -1.0;
GE( glMultMatrixf (m) );
GE( glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16);
memset (ctx->inverse_projection, 0, sizeof (float) * 16);
#define m ctx->inverse_projection
M(0, 0) = 1.0f / (x);
M(1, 1) = 1.0f / (y);
M(2, 3) = -1.0f;
M(3, 2) = 1.0f / (d);
M(3, 3) = (c) / (d);
M(0, 0) = (1.0 / x);
M(1, 1) = (1.0 / y);
M(2, 3) = -1.0;
M(3, 2) = (1.0 / d);
M(3, 3) = (c / d);
#undef m
#undef M
}
@ -628,7 +620,7 @@ cogl_frustum (float left,
float z_near,
float z_far)
{
GLfloat c, d;
float c, d;
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
@ -645,24 +637,18 @@ cogl_frustum (float left,
GE( glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (GLfloat) * 16);
memset (ctx->inverse_projection, 0, sizeof (float) * 16);
c = - (z_far + z_near)
/ (z_far - z_near);
d = - (2 * (z_far * z_near))
/ (z_far - z_near);
c = - (z_far + z_near) / (z_far - z_near);
d = - (2 * (z_far * z_near)) / (z_far - z_near);
#define M(row,col) ctx->inverse_projection[col*4+row]
M(0,0) = (right - left)
/ (2 * z_near);
M(0,3) = (right + left)
/ (2 * z_near);
M(1,1) = (top - bottom)
/ (2 * z_near);
M(1,3) = (top + bottom)
/ (2 * z_near);
M(2,3) = -1.0f;
M(3,2) = 1.0f / d;
M(0,0) = (right - left) / (2 * z_near);
M(0,3) = (right + left) / (2 * z_near);
M(1,1) = (top - bottom) / (2 * z_near);
M(1,3) = (top + bottom) / (2 * z_near);
M(2,3) = -1.0;
M(3,2) = 1.0 / d;
M(3,3) = c / d;
#undef M
}
@ -675,18 +661,22 @@ cogl_viewport (guint width,
}
void
cogl_setup_viewport (guint width,
guint height,
cogl_setup_viewport (guint width,
guint height,
float fovy,
float aspect,
float z_near,
float z_far)
{
GLfloat z_camera;
GLfloat projection_matrix[16];
float z_camera;
float projection_matrix[16];
GE( glViewport (0, 0, width, height) );
/* For Ortho projection.
* glOrthof (0, width << 16, 0, height << 16, -1 << 16, 1 << 16);
*/
cogl_perspective (fovy, aspect, z_near, z_far);
/*
@ -734,9 +724,7 @@ cogl_setup_viewport (guint width,
GE( glLoadIdentity () );
GE( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glScalef ( 1.0f / width,
-1.0f / height,
1.0f / width) );
GE( glScalef (1.0f / width, -1.0f / height, 1.0f / width) );
GE( glTranslatef (0.0f, -1.0 * height, 0.0f) );
}
@ -1165,8 +1153,8 @@ cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
void
cogl_fog_set (const CoglColor *fog_color,
float density,
float start,
float stop)
float z_near,
float z_far)
{
GLfloat fogColor[4];
@ -1182,8 +1170,8 @@ cogl_fog_set (const CoglColor *fog_color,
glFogi (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST);
glFogf (GL_FOG_DENSITY, (density));
glFogf (GL_FOG_START, (start));
glFogf (GL_FOG_END, (stop));
glFogf (GL_FOG_DENSITY, (GLfloat) density);
glFogf (GL_FOG_START, (GLfloat) z_near);
glFogf (GL_FOG_END, (GLfloat) z_far);
}

View File

@ -84,7 +84,7 @@ cogl_create_context ()
#endif
/* Init OpenGL state */
GE( cogl_wrap_glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
GE( glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE) );
GE( glColorMask (TRUE, TRUE, TRUE, FALSE) );
GE( glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) );
cogl_enable (0);

View File

@ -206,29 +206,29 @@ cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
from a non-screen buffer */
GE( glGetIntegerv (GL_VIEWPORT, ctx->viewport_store) );
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
}
else
{
/* Override viewport and matrix setup if redirecting
from another offscreen buffer */
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glLoadIdentity () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glLoadIdentity () );
}
/* Setup new viewport and matrices */
GE( glViewport (0, 0, fbo->width, fbo->height) );
GE( cogl_wrap_glTranslatef (-1.0, -1.0, 0) );
GE( cogl_wrap_glScalef (((float)(2) /
GE( glTranslatef (-1.0, -1.0, 0) );
GE( glScalef (((float)(2) /
(float)(fbo->width)),
((float)(2) /
(float)(fbo->height)),
@ -265,11 +265,11 @@ cogl_draw_buffer (CoglBufferTarget target, CoglHandle offscreen)
GE( glViewport (ctx->viewport_store[0], ctx->viewport_store[1],
ctx->viewport_store[2], ctx->viewport_store[3]) );
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPopMatrix () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPopMatrix () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
}
/* Bind window framebuffer object */

View File

@ -55,8 +55,8 @@ _cogl_rectangle (float x,
cogl_enable (COGL_ENABLE_VERTEX_ARRAY
| (ctx->color_alpha < 255 ? COGL_ENABLE_BLEND : 0));
GE ( cogl_wrap_glVertexPointer (2, GL_FLOAT, 0, rect_verts ) );
GE ( cogl_wrap_glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) );
GE ( glVertexPointer (2, GL_FLOAT, 0, rect_verts ) );
GE ( glDrawArrays (GL_TRIANGLE_STRIP, 0, 4) );
}
void
@ -109,10 +109,10 @@ _cogl_path_stroke_nodes ()
CoglPathNode *path = &g_array_index (ctx->path_nodes, CoglPathNode,
path_start);
GE( cogl_wrap_glVertexPointer (2, GL_FIXED, sizeof (CoglPathNode),
GE( glVertexPointer (2, GL_FIXED, sizeof (CoglPathNode),
(guchar *) path
+ G_STRUCT_OFFSET (CoglPathNode, x)) );
GE( cogl_wrap_glDrawArrays (GL_LINE_STRIP, 0, path->path_size) );
GE( glDrawArrays (GL_LINE_STRIP, 0, path->path_size) );
path_start += path->path_size;
}
@ -167,7 +167,7 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
GE( glStencilFunc (GL_LEQUAL, 0x1, 0x3) );
}
GE( cogl_wrap_glEnable (GL_STENCIL_TEST) );
GE( glEnable (GL_STENCIL_TEST) );
GE( glStencilOp (GL_INVERT, GL_INVERT, GL_INVERT) );
GE( glColorMask (FALSE, FALSE, FALSE, FALSE) );
@ -177,10 +177,10 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
{
cogl_enable (COGL_ENABLE_VERTEX_ARRAY);
GE( cogl_wrap_glVertexPointer (2, GL_FIXED, sizeof (CoglPathNode),
GE( glVertexPointer (2, GL_FIXED, sizeof (CoglPathNode),
(guchar *) path
+ G_STRUCT_OFFSET (CoglPathNode, x)) );
GE( cogl_wrap_glDrawArrays (GL_TRIANGLE_FAN, 0, path->path_size) );
GE( glDrawArrays (GL_TRIANGLE_FAN, 0, path->path_size) );
if (sub_path_num > 0)
{
@ -209,16 +209,16 @@ _cogl_add_path_to_stencil_buffer (floatVec2 nodes_min,
GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
/* Decrement all of the bits twice so that only pixels where the
value is 3 will remain */
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
cogl_rectangle (-1.0, -1.0, 2, 2);
cogl_rectangle (-1.0, -1.0, 2, 2);
GE( cogl_wrap_glPopMatrix () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPopMatrix () );
GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
}
GE( glStencilMask (~(GLuint) 0) );
@ -392,8 +392,8 @@ _cogl_path_fill_nodes_scanlines (CoglPathNode *path,
/* render triangles */
cogl_enable (COGL_ENABLE_VERTEX_ARRAY
| (ctx->color_alpha < 255 ? COGL_ENABLE_BLEND : 0));
GE ( cogl_wrap_glVertexPointer (2, GL_FIXED, 0, coords ) );
GE ( cogl_wrap_glDrawArrays (GL_TRIANGLES, 0, spans * 2 * 3));
GE ( glVertexPointer (2, GL_FIXED, 0, coords ) );
GE ( glDrawArrays (GL_TRIANGLES, 0, spans * 2 * 3));
g_free (coords);
}
}

View File

@ -42,21 +42,6 @@
#include <stdlib.h>
#include <math.h>
#if HAVE_COGL_GLES2
#define glVertexPointer cogl_wrap_glVertexPointer
#define glTexCoordPointer cogl_wrap_glTexCoordPointer
#define glColorPointer cogl_wrap_glColorPointer
#define glDrawArrays cogl_wrap_glDrawArrays
#define glDrawElements cogl_wrap_glDrawElements
#define glTexParameteri cogl_wrap_glTexParameteri
#define glClientActiveTexture cogl_wrap_glClientActiveTexture
#define glActiveTexture cogl_wrap_glActiveTexture
#define glEnable cogl_wrap_glEnable
#define glEnableClientState cogl_wrap_glEnableClientState
#define glDisable cogl_wrap_glDisable
#define glDisableClientState cogl_wrap_glDisableClientState
#endif
/*
#define COGL_DEBUG 1
@ -534,7 +519,7 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
bpp = _cogl_get_format_bpp (COGL_PIXEL_FORMAT_RGBA_8888);
/* Viewport needs to have some size and be inside the window for this */
GE( cogl_wrap_glGetIntegerv (GL_VIEWPORT, viewport) );
GE( glGetIntegerv (GL_VIEWPORT, viewport) );
if (viewport[0] < 0 || viewport[1] < 0 ||
viewport[2] <= 0 || viewport[3] <= 0)
@ -544,18 +529,18 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
(0,0 in bottom-left corner to draw the texture
upside-down so we match the way glReadPixels works) */
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( cogl_wrap_glOrthof (0, (float)(viewport[2]),
GE( glOrthof (0, (float)(viewport[2]),
0, (float)(viewport[3]),
(float)(0),
(float)(100)) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
/* Draw to all channels */
cogl_draw_buffer (COGL_WINDOW_BUFFER | COGL_MASK_BUFFER, 0);
@ -575,10 +560,10 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
still doesn't seem to have an alpha buffer. This might be just
a PowerVR issue.
GLint r_bits, g_bits, b_bits, a_bits;
GE( cogl_wrap_glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
GE( cogl_wrap_glGetIntegerv (GL_RED_BITS, &r_bits) );
GE( cogl_wrap_glGetIntegerv (GL_GREEN_BITS, &g_bits) );
GE( cogl_wrap_glGetIntegerv (GL_BLUE_BITS, &b_bits) );
GE( glGetIntegerv (GL_ALPHA_BITS, &a_bits) );
GE( glGetIntegerv (GL_RED_BITS, &r_bits) );
GE( glGetIntegerv (GL_GREEN_BITS, &g_bits) );
GE( glGetIntegerv (GL_BLUE_BITS, &b_bits) );
printf ("R bits: %d\n", r_bits);
printf ("G bits: %d\n", g_bits);
printf ("B bits: %d\n", b_bits);
@ -624,10 +609,10 @@ _cogl_texture_download_from_gl (CoglTexture *tex,
}
/* Restore old state */
cogl_wrap_glMatrixMode (GL_PROJECTION);
cogl_wrap_glPopMatrix ();
cogl_wrap_glMatrixMode (GL_MODELVIEW);
cogl_wrap_glPopMatrix ();
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glMatrixMode (GL_MODELVIEW);
glPopMatrix ();
cogl_draw_buffer (COGL_WINDOW_BUFFER, 0);
cogl_blend_func (old_src_factor, old_dst_factor);

View File

@ -73,7 +73,6 @@ _cogl_error_string(GLenum errorCode)
}
#endif
CoglFuncPtr
cogl_get_proc_address (const gchar* name)
{
@ -99,39 +98,53 @@ cogl_paint_init (const CoglColor *color)
0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
cogl_wrap_glDisable (GL_LIGHTING);
cogl_wrap_glDisable (GL_FOG);
glDisable (GL_LIGHTING);
glDisable (GL_FOG);
/*
* Disable the depth test for now as has some strange side effects,
* mainly on x/y axis rotation with multiple layers at same depth
* (eg rotating text on a bg has very strange effect). Seems no clean
* 100% effective way to fix without other odd issues.. So for now
* move to application to handle and add cogl_enable_depth_test()
* as for custom actors (i.e groups) to enable if need be.
*
* glEnable (GL_DEPTH_TEST);
* glEnable (GL_ALPHA_TEST)
* glDepthFunc (GL_LEQUAL);
* glAlphaFunc (GL_GREATER, 0.1);
*/
}
/* FIXME: inline most of these */
void
cogl_push_matrix (void)
{
GE( cogl_wrap_glPushMatrix() );
GE( glPushMatrix() );
}
void
cogl_pop_matrix (void)
{
GE( cogl_wrap_glPopMatrix() );
GE( glPopMatrix() );
}
void
cogl_scale (float x, float y)
{
GE( cogl_wrap_glScalef (x, y, 1.0) );
GE( glScalef (x, y, 1.0) );
}
void
cogl_translate (float x, float y, float z)
{
GE( cogl_wrap_glTranslatef (x, y, z) );
GE( glTranslatef (x, y, z) );
}
void
cogl_rotate (float angle, float x, float y, float z)
{
GE( cogl_wrap_glRotatef (angle, x, y, z) );
GE( glRotatef (angle, x, y, z) );
}
static inline gboolean
@ -147,14 +160,14 @@ cogl_toggle_flag (CoglContext *ctx,
{
if (!(ctx->enable_flags & flag))
{
GE( cogl_wrap_glEnable (gl_flag) );
GE( glEnable (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( cogl_wrap_glDisable (gl_flag) );
GE( glDisable (gl_flag) );
ctx->enable_flags &= ~flag;
}
@ -174,14 +187,14 @@ cogl_toggle_client_flag (CoglContext *ctx,
{
if (!(ctx->enable_flags & flag))
{
GE( cogl_wrap_glEnableClientState (gl_flag) );
GE( glEnableClientState (gl_flag) );
ctx->enable_flags |= flag;
return TRUE;
}
}
else if (ctx->enable_flags & flag)
{
GE( cogl_wrap_glDisableClientState (gl_flag) );
GE( glDisableClientState (gl_flag) );
ctx->enable_flags &= ~flag;
}
@ -234,15 +247,15 @@ cogl_enable_depth_test (gboolean setting)
{
if (setting)
{
cogl_wrap_glEnable (GL_DEPTH_TEST);
cogl_wrap_glEnable (GL_ALPHA_TEST);
glEnable (GL_DEPTH_TEST);
glEnable (GL_ALPHA_TEST);
glDepthFunc (GL_LEQUAL);
cogl_wrap_glAlphaFunc (GL_GREATER, 0.1);
glAlphaFunc (GL_GREATER, 0.1);
}
else
{
cogl_wrap_glDisable (GL_DEPTH_TEST);
cogl_wrap_glDisable (GL_ALPHA_TEST);
glDisable (GL_DEPTH_TEST);
glDisable (GL_ALPHA_TEST);
}
}
@ -279,7 +292,7 @@ cogl_set_source_color (const CoglColor *color)
#else
/* conversion can cause issues with picking on some gles implementations */
GE( cogl_wrap_glColor4f (cogl_color_get_red (color),
GE( glColor4f (cogl_color_get_red (color),
cogl_color_get_green (color),
cogl_color_get_blue (color),
cogl_color_get_alpha (color)) );
@ -297,7 +310,7 @@ apply_matrix (const float *matrix, float *vertex)
for (y = 0; y < 4; y++)
for (x = 0; x < 4; x++)
vertex_out[y] += (vertex[x] * matrix[y + x * 4]);
vertex_out[y] += vertex[x] * matrix[y + x * 4];
memcpy (vertex, vertex_out, sizeof (vertex_out));
}
@ -315,7 +328,7 @@ project_vertex (float *modelview,
apply_matrix (project, vertex);
/* Convert from homogenized coordinates */
for (i = 0; i < 4; i++)
vertex[i] = (vertex[i] / vertex[3]);
vertex[i] /= vertex[3];
}
static void
@ -332,26 +345,26 @@ set_clip_plane (GLint plane_num,
angle = atan2f (vertex_b[1] - vertex_a[1],
vertex_b[0] - vertex_a[0]) * (180.0/G_PI);
GE( cogl_wrap_glPushMatrix () );
GE( glPushMatrix () );
/* Load the identity matrix and multiply by the reverse of the
projection matrix so we can specify the plane in screen
coordinates */
GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMultMatrixf ((GLfloat *) ctx->inverse_projection) );
GE( glLoadIdentity () );
GE( glMultMatrixf ((GLfloat *) ctx->inverse_projection) );
/* Rotate about point a */
GE( cogl_wrap_glTranslatef (vertex_a[0], vertex_a[1], vertex_a[2]) );
GE( glTranslatef (vertex_a[0], vertex_a[1], vertex_a[2]) );
/* Rotate the plane by the calculated angle so that it will connect
the two points */
GE( cogl_wrap_glRotatef (angle, 0.0f, 0.0f, 1.0f) );
GE( cogl_wrap_glTranslatef (-vertex_a[0], -vertex_a[1], -vertex_a[2]) );
GE( glRotatef (angle, 0.0f, 0.0f, 1.0f) );
GE( glTranslatef (-vertex_a[0], -vertex_a[1], -vertex_a[2]) );
plane[0] = 0;
plane[1] = -1.0;
plane[2] = 0;
plane[3] = vertex_a[1];
GE( cogl_wrap_glClipPlanef (plane_num, plane) );
GE( glClipPlanef (plane_num, plane) );
GE( cogl_wrap_glPopMatrix () );
GE( glPopMatrix () );
}
void
@ -366,21 +379,21 @@ _cogl_set_clip_planes (float x_offset,
float vertex_tr[4] = { x_offset + width, y_offset, 0, 1.0 };
float vertex_bl[4] = { x_offset, y_offset + height, 0, 1.0 };
float vertex_br[4] = { x_offset + width, y_offset + height,
0, 1.0 };
0, 1.0 };
GE( cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, modelview) );
GE( cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, projection) );
GE( glGetFloatv (GL_MODELVIEW_MATRIX, modelview) );
GE( glGetFloatv (GL_PROJECTION_MATRIX, projection) );
project_vertex (modelview, projection, vertex_tl);
project_vertex (modelview, projection, vertex_tr);
project_vertex (modelview, projection, vertex_bl);
project_vertex (modelview, projection, 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 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))
{
@ -410,7 +423,7 @@ _cogl_add_stencil_clip (float x_offset,
if (first)
{
GE( cogl_wrap_glEnable (GL_STENCIL_TEST) );
GE( glEnable (GL_STENCIL_TEST) );
/* Initially disallow everything */
GE( glClearStencil (0) );
@ -434,15 +447,15 @@ _cogl_add_stencil_clip (float x_offset,
only pixels where both the original stencil buffer and the
rectangle are set will be valid */
GE( glStencilOp (GL_DECR, GL_DECR, GL_DECR) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glPushMatrix () );
GE( cogl_wrap_glLoadIdentity () );
GE( glPushMatrix () );
GE( glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glPushMatrix () );
GE( glLoadIdentity () );
cogl_rectangle (-1.0, -1.0, 2, 2);
GE( cogl_wrap_glPopMatrix () );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( cogl_wrap_glPopMatrix () );
GE( glPopMatrix () );
GE( glMatrixMode (GL_MODELVIEW) );
GE( glPopMatrix () );
}
/* Restore the stencil mode */
@ -453,37 +466,34 @@ _cogl_add_stencil_clip (float x_offset,
void
_cogl_set_matrix (const float *matrix)
{
GE( cogl_wrap_glLoadIdentity () );
GE( cogl_wrap_glMultMatrixf (matrix) );
GE( glLoadIdentity () );
GE( glMultMatrixf (matrix) );
}
void
_cogl_disable_stencil_buffer (void)
{
GE( cogl_wrap_glDisable (GL_STENCIL_TEST) );
GE( glDisable (GL_STENCIL_TEST) );
}
void
_cogl_enable_clip_planes (void)
{
GE( cogl_wrap_glEnable (GL_CLIP_PLANE0) );
GE( cogl_wrap_glEnable (GL_CLIP_PLANE1) );
GE( cogl_wrap_glEnable (GL_CLIP_PLANE2) );
GE( cogl_wrap_glEnable (GL_CLIP_PLANE3) );
GE( glEnable (GL_CLIP_PLANE0) );
GE( glEnable (GL_CLIP_PLANE1) );
GE( glEnable (GL_CLIP_PLANE2) );
GE( glEnable (GL_CLIP_PLANE3) );
}
void
_cogl_disable_clip_planes (void)
{
GE( cogl_wrap_glDisable (GL_CLIP_PLANE3) );
GE( cogl_wrap_glDisable (GL_CLIP_PLANE2) );
GE( cogl_wrap_glDisable (GL_CLIP_PLANE1) );
GE( cogl_wrap_glDisable (GL_CLIP_PLANE0) );
GE( glDisable (GL_CLIP_PLANE3) );
GE( glDisable (GL_CLIP_PLANE2) );
GE( glDisable (GL_CLIP_PLANE1) );
GE( glDisable (GL_CLIP_PLANE0) );
}
/*
* Fixed point implementation of the perspective function
*/
void
cogl_perspective (float fovy,
float aspect,
@ -500,16 +510,16 @@ cogl_perspective (float fovy,
memset (&m[0], 0, sizeof (m));
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glLoadIdentity () );
/*
/*
* Based on the original algorithm in perspective():
*
* 1) xmin = -xmax => xmax + xmin == 0 && xmax - xmin == 2 * xmax
* same true for y, hence: a == 0 && b == 0;
*
* 2) When working with small numbers, we can are loosing significant
* 2) When working with small numbers, we are loosing significant
* precision
*/
ymax = (zNear * (sinf (fovy_rad_half) / cosf (fovy_rad_half)));
@ -527,9 +537,9 @@ cogl_perspective (float fovy,
M(2,3) = d;
M(3,2) = -1.0;
GE( cogl_wrap_glMultMatrixf (m) );
GE( glMultMatrixf (m) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (float) * 16);
@ -557,29 +567,32 @@ cogl_frustum (float left,
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( cogl_wrap_glMatrixMode (GL_PROJECTION) );
GE( cogl_wrap_glLoadIdentity () );
GE( glMatrixMode (GL_PROJECTION) );
GE( glLoadIdentity () );
GE( cogl_wrap_glFrustumf (left, right,
bottom, top,
z_near, z_far) );
GE( glFrustumf (left,
right,
bottom,
top,
z_near,
z_far) );
GE( cogl_wrap_glMatrixMode (GL_MODELVIEW) );
GE( glMatrixMode (GL_MODELVIEW) );
/* Calculate and store the inverse of the matrix */
memset (ctx->inverse_projection, 0, sizeof (float) * 16);
c = -(z_far + z_near / z_far - z_near);
d = -(2 * (z_far * z_near) / z_far - z_near);
c = - (z_far + z_near) / (z_far - z_near);
d = - (2 * (z_far * z_near)) / (z_far - z_near);
#define M(row,col) ctx->inverse_projection[col*4+row]
M(0,0) = (right - left / 2 * z_near);
M(0,3) = (right + left / 2 * z_near);
M(1,1) = (top - bottom / 2 * z_near);
M(1,3) = (top + bottom / 2 * z_near);
M(0,0) = (right - left) / (2 * z_near);
M(0,3) = (right + left) / (2 * z_near);
M(1,1) = (top - bottom) / (2 * z_near);
M(1,3) = (top + bottom) / (2 * z_near);
M(2,3) = -1.0;
M(3,2) = (1.0 / d);
M(3,3) = (c / d);
M(3,2) = 1.0 / d;
M(3,3) = c / d;
#undef M
}
@ -591,22 +604,20 @@ cogl_viewport (guint width,
}
void
cogl_setup_viewport (guint w,
guint h,
cogl_setup_viewport (guint width,
guint height,
float fovy,
float aspect,
float z_near,
float z_far)
{
gint width = (gint) w;
gint height = (gint) h;
float z_camera;
float projection_matrix[16];
GE( glViewport (0, 0, width, height) );
/* For Ortho projection.
* cogl_wrap_glOrthof (0, width << 16, 0, height << 16, -1 << 16, 1 << 16);
* glOrthof (0, width << 16, 0, height << 16, -1 << 16, 1 << 16);
*/
cogl_perspective (fovy, aspect, z_near, z_far);
@ -620,15 +631,13 @@ cogl_setup_viewport (guint w,
cogl_get_projection_matrix (projection_matrix);
z_camera = 0.5 * projection_matrix[0];
GE( cogl_wrap_glLoadIdentity () );
GE( glLoadIdentity () );
GE( cogl_wrap_glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( glTranslatef (-0.5f, -0.5f, -z_camera) );
GE( cogl_wrap_glScalef ( 1.0 / width,
-1.0 / height,
1.0 / width) );
GE( glScalef (1.0f / width, -1.0f / height, 1.0f / width) );
GE( cogl_wrap_glTranslatef (0, -1.0 * height, 0) );
GE( glTranslatef (0.0f, -1.0 * height, 0.0f) );
}
static void
@ -640,12 +649,12 @@ _cogl_features_init ()
_COGL_GET_CONTEXT (ctx, NO_RETVAL);
GE( cogl_wrap_glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
GE( glGetIntegerv (GL_STENCIL_BITS, &num_stencil_bits) );
/* We need at least three stencil bits to combine clips */
if (num_stencil_bits > 2)
flags |= COGL_FEATURE_STENCIL_BUFFER;
GE( cogl_wrap_glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
GE( glGetIntegerv (GL_MAX_CLIP_PLANES, &max_clip_planes) );
if (max_clip_planes >= 4)
flags |= COGL_FEATURE_FOUR_CLIP_PLANES;
@ -653,6 +662,7 @@ _cogl_features_init ()
flags |= COGL_FEATURE_SHADERS_GLSL | COGL_FEATURE_OFFSCREEN;
#endif
/* Cache features */
ctx->feature_flags = flags;
ctx->features_cached = TRUE;
}
@ -682,13 +692,13 @@ cogl_features_available (CoglFeatureFlags features)
void
cogl_get_modelview_matrix (float m[16])
{
cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, m);
glGetFloatv (GL_MODELVIEW_MATRIX, m);
}
void
cogl_get_projection_matrix (float m[16])
{
cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, m);
glGetFloatv (GL_PROJECTION_MATRIX, m);
}
void
@ -697,7 +707,7 @@ cogl_get_viewport (float v[4])
GLint viewport[4];
int i;
cogl_wrap_glGetIntegerv (GL_VIEWPORT, viewport);
glGetIntegerv (GL_VIEWPORT, viewport);
for (i = 0; i < 4; i++)
v[i] = (float)(viewport[i]);
@ -706,14 +716,27 @@ cogl_get_viewport (float v[4])
void
cogl_get_bitmasks (gint *red, gint *green, gint *blue, gint *alpha)
{
GLint value;
if (red)
GE( cogl_wrap_glGetIntegerv(GL_RED_BITS, red) );
{
GE( glGetIntegerv(GL_RED_BITS, &value) );
*red = value;
}
if (green)
GE( cogl_wrap_glGetIntegerv(GL_GREEN_BITS, green) );
{
GE( glGetIntegerv(GL_GREEN_BITS, &value) );
*green = value;
}
if (blue)
GE( cogl_wrap_glGetIntegerv(GL_BLUE_BITS, blue) );
{
GE( glGetIntegerv(GL_BLUE_BITS, &value) );
*blue = value;
}
if (alpha)
GE( cogl_wrap_glGetIntegerv(GL_ALPHA_BITS, alpha ) );
{
GE( glGetIntegerv(GL_ALPHA_BITS, &value ) );
*alpha = value;
}
}
void
@ -724,19 +747,20 @@ cogl_fog_set (const CoglColor *fog_color,
{
GLfloat fogColor[4];
fogColor[0] = cogl_color_get_red (fog_color);
fogColor[1] = cogl_color_get_green (fog_color);
fogColor[2] = cogl_color_get_blue (fog_color);
fogColor[3] = cogl_color_get_alpha (fog_color);
fogColor[0] = cogl_color_get_red_float (fog_color);
fogColor[1] = cogl_color_get_green_float (fog_color);
fogColor[2] = cogl_color_get_blue_float (fog_color);
fogColor[3] = cogl_color_get_alpha_float (fog_color);
cogl_wrap_glEnable (GL_FOG);
glEnable (GL_FOG);
cogl_wrap_glFogfv (GL_FOG_COLOR, fogColor);
glFogfv (GL_FOG_COLOR, fogColor);
cogl_wrap_glFogf (GL_FOG_MODE, GL_LINEAR);
glFogf (GL_FOG_MODE, GL_LINEAR);
glHint (GL_FOG_HINT, GL_NICEST);
cogl_wrap_glFogf (GL_FOG_DENSITY, (GLfloat) density);
cogl_wrap_glFogf (GL_FOG_START, (GLfloat) z_near);
cogl_wrap_glFogf (GL_FOG_END, (GLfloat) z_far);
glFogf (GL_FOG_DENSITY, (GLfloat) density);
glFogf (GL_FOG_START, (GLfloat) z_near);
glFogf (GL_FOG_END, (GLfloat) z_far);
}