From de27da0e5be8a27a0743fd9b62e2da04ed91dc82 Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Thu, 8 Jan 2009 22:56:17 +0000 Subject: [PATCH] [cogl/gles] Fixes for building for GLES 1 using floats * This adds GLfixed -> GLfloat conversion * redefines cogl_wrap_glBlahx macros as glBlahf * Other misc fixes (mostly corresponding to cogl/gl equivalents) --- clutter/cogl/gles/cogl-gles2-wrapper.h | 24 ++++---- .../gles-cogl-gles2-wrapper.h.0.patch | 13 ++++ .../gles-cogl-primitives.c.0.patch | 12 ++++ .../gles-cogl-texture.c.0.patch | 30 ++++++++++ fixed-to-float-patches/gles-cogl.c.0.patch | 60 +++++++++++++++++++ fixed-to-float.sh | 6 ++ 6 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch create mode 100644 fixed-to-float-patches/gles-cogl-primitives.c.0.patch create mode 100644 fixed-to-float-patches/gles-cogl-texture.c.0.patch create mode 100644 fixed-to-float-patches/gles-cogl.c.0.patch diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.h b/clutter/cogl/gles/cogl-gles2-wrapper.h index ddf181e92..514b89cc4 100644 --- a/clutter/cogl/gles/cogl-gles2-wrapper.h +++ b/clutter/cogl/gles/cogl-gles2-wrapper.h @@ -272,34 +272,34 @@ void _cogl_gles2_clear_cache_for_program (CoglHandle program); /* If we're not using GL ES 2 then just use the GL functions directly */ -#define cogl_wrap_glClearColorx glClearColorx +#define cogl_wrap_glClearColorx glClearColor #define cogl_wrap_glDrawArrays glDrawArrays #define cogl_wrap_glPushMatrix glPushMatrix #define cogl_wrap_glPopMatrix glPopMatrix #define cogl_wrap_glMatrixMode glMatrixMode #define cogl_wrap_glLoadIdentity glLoadIdentity -#define cogl_wrap_glMultMatrixx glMultMatrixx -#define cogl_wrap_glFrustumx glFrustumx -#define cogl_wrap_glScalex glScalex -#define cogl_wrap_glTranslatex glTranslatex -#define cogl_wrap_glRotatex glRotatex -#define cogl_wrap_glOrthox glOrthox +#define cogl_wrap_glMultMatrixx glMultMatrixf +#define cogl_wrap_glFrustumx glFrustumf +#define cogl_wrap_glScalex glScalef +#define cogl_wrap_glTranslatex glTranslatef +#define cogl_wrap_glRotatex glRotatef +#define cogl_wrap_glOrthox glOrthof #define cogl_wrap_glEnable glEnable #define cogl_wrap_glDisable glDisable #define cogl_wrap_glTexCoordPointer glTexCoordPointer #define cogl_wrap_glVertexPointer glVertexPointer #define cogl_wrap_glColorPointer glColorPointer #define cogl_wrap_glNormalPointer glNormalPointer -#define cogl_wrap_glTexEnvx glTexEnvx +#define cogl_wrap_glTexEnvx glTexEnvf #define cogl_wrap_glEnableClientState glEnableClientState #define cogl_wrap_glDisableClientState glDisableClientState #define cogl_wrap_glAlphaFunc glAlphaFunc -#define cogl_wrap_glColor4x glColor4x -#define cogl_wrap_glClipPlanex glClipPlanex +#define cogl_wrap_glColor4x glColor4f +#define cogl_wrap_glClipPlanex glClipPlanef #define cogl_wrap_glGetIntegerv glGetIntegerv #define cogl_wrap_glGetFixedv glGetFixedv -#define cogl_wrap_glFogx glFogx -#define cogl_wrap_glFogxv glFogxv +#define cogl_wrap_glFogx glFogf +#define cogl_wrap_glFogxv glFogfv #define cogl_wrap_glTexParameteri glTexParameteri /* The extra third parameter of the bind texture wrapper isn't needed diff --git a/fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch b/fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch new file mode 100644 index 000000000..03deb1638 --- /dev/null +++ b/fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch @@ -0,0 +1,13 @@ +diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.h b/clutter/cogl/gles/cogl-gles2-wrapper.h +index 265da78..2e61121 100644 +--- a/clutter/cogl/gles/cogl-gles2-wrapper.h ++++ b/clutter/cogl/gles/cogl-gles2-wrapper.h +@@ -297,7 +297,7 @@ void _cogl_gles2_clear_cache_for_program (CoglHandle program); + #define cogl_wrap_glColor4x glColor4f + #define cogl_wrap_glClipPlanex glClipPlanef + #define cogl_wrap_glGetIntegerv glGetIntegerv +-#define cogl_wrap_glGetFixedv glGetFixedv ++#define cogl_wrap_glGetFixedv glGetFloatv + #define cogl_wrap_glFogx glFogf + #define cogl_wrap_glFogxv glFogfv + #define cogl_wrap_glTexParameteri glTexParameteri diff --git a/fixed-to-float-patches/gles-cogl-primitives.c.0.patch b/fixed-to-float-patches/gles-cogl-primitives.c.0.patch new file mode 100644 index 000000000..d6b35ebaa --- /dev/null +++ b/fixed-to-float-patches/gles-cogl-primitives.c.0.patch @@ -0,0 +1,12 @@ +diff --git a/clutter/cogl/gles/cogl-primitives.c b/clutter/cogl/gles/cogl-primitives.c +index 901fa5d..d8fe121 100644 +--- a/clutter/cogl/gles/cogl-primitives.c ++++ b/clutter/cogl/gles/cogl-primitives.c +@@ -34,6 +34,7 @@ + + #include + #include ++#include + + #define _COGL_MAX_BEZ_RECURSE_DEPTH 16 + diff --git a/fixed-to-float-patches/gles-cogl-texture.c.0.patch b/fixed-to-float-patches/gles-cogl-texture.c.0.patch new file mode 100644 index 000000000..d1d6b00f9 --- /dev/null +++ b/fixed-to-float-patches/gles-cogl-texture.c.0.patch @@ -0,0 +1,30 @@ +diff --git a/clutter/cogl/gles/cogl-texture.c b/clutter/cogl/gles/cogl-texture.c +index fb628b0..85bfc2b 100644 +--- a/clutter/cogl/gles/cogl-texture.c ++++ b/clutter/cogl/gles/cogl-texture.c +@@ -39,6 +39,7 @@ + + #include + #include ++#include + + #define glVertexPointer cogl_wrap_glVertexPointer + #define glTexCoordPointer cogl_wrap_glTexCoordPointer +@@ -767,7 +768,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex, + guint wx, wy; + + src = source_bmp->data +- + (src_y + (y_iter.intersect_start) ++ + (src_y + ((int)y_iter.intersect_start) + - dst_y) + * source_bmp->rowstride + + (src_x + x_span->start + x_span->size - x_span->waste +@@ -812,7 +813,7 @@ _cogl_texture_upload_subregion_to_gl (CoglTexture *tex, + guint copy_width; + + src = source_bmp->data +- + (src_x + (x_iter.intersect_start) ++ + (src_x + ((int)x_iter.intersect_start) + - dst_x) + * bpp + + (src_y + y_span->start + y_span->size - y_span->waste diff --git a/fixed-to-float-patches/gles-cogl.c.0.patch b/fixed-to-float-patches/gles-cogl.c.0.patch new file mode 100644 index 000000000..bf1daac0a --- /dev/null +++ b/fixed-to-float-patches/gles-cogl.c.0.patch @@ -0,0 +1,60 @@ +diff --git a/clutter/cogl/gles/cogl.c b/clutter/cogl/gles/cogl.c +index 422d8b6..16cf666 100644 +--- a/clutter/cogl/gles/cogl.c ++++ b/clutter/cogl/gles/cogl.c +@@ -37,6 +37,7 @@ + #include "cogl-context.h" + + #include "cogl-gles2-wrapper.h" ++#include + + /* GL error to string conversion */ + #if COGL_DEBUG +@@ -365,9 +366,8 @@ 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]), +- COGL_RADIANS_TO_DEGREES); ++ angle = atan2f (vertex_b[1] - vertex_a[1], ++ vertex_b[0] - vertex_a[0]) * (180.0/G_PI); + + GE( cogl_wrap_glPushMatrix () ); + /* Load the identity matrix and multiply by the reverse of the +@@ -558,15 +558,13 @@ cogl_perspective (float fovy, + * 2) When working with small numbers, we can are loosing significant + * precision + */ +- ymax = (zNear * +- (sinf (fovy_rad_half) / +- cosf (fovy_rad_half))); ++ ymax = (zNear * (sinf (fovy_rad_half) / cosf (fovy_rad_half))); + xmax = (ymax * aspect); + + x = (zNear / xmax); + y = (zNear / ymax); + c = (-(zFar + zNear) / ( zFar - zNear)); +- d = (-((2 * zFar * zNear)) / (zFar - zNear)); ++ d = (-(2 * zFar) * zNear) / (zFar - zNear); + + #define M(row,col) m[col*4+row] + M(0,0) = x; +@@ -671,13 +669,13 @@ cogl_setup_viewport (guint w, + if (fovy != 60.0) + { + float fovy_rad = (fovy * G_PI) / 180; +- +- z_camera = (sinf (fovy_rad) / +- cosf (fovy_rad)) >> 1; ++ ++ z_camera = (sinf (fovy_rad) / cosf (fovy_rad)) / 2; + } + + +- GE( cogl_wrap_glTranslatex (-1 << 15, -1 << 15, -z_camera) ); ++ ++ GE( cogl_wrap_glTranslatex (-0.5f, -0.5f, -z_camera) ); + + GE( cogl_wrap_glScalex ( 1.0 / width, + -1.0 / height, diff --git a/fixed-to-float.sh b/fixed-to-float.sh index 86dd0169d..4cd34f6a0 100755 --- a/fixed-to-float.sh +++ b/fixed-to-float.sh @@ -31,6 +31,8 @@ find ./clutter -iname '*.[ch]' -exec sed -i -r 's|COGL_FIXED_DIV (.*),|\1 /|g' { # A fix due to the assumptions used above sed -i 's/#define DET2X(a,b,c,d).*/#define DET2X(a,b,c,d) ((a * d) - (b * c))/g' ./clutter/clutter-actor.c +find ./clutter/cogl/gles -iname '*.[ch]' -exec sed -i 's/GLfixed/GLfloat/g' {} \; + #we get some redundant brackets like this, but C's automatic type promotion #works out fine for most cases... find ./clutter -iname '*.[ch]' -exec sed -i 's/COGL_FIXED_TO_INT//g' {} \; @@ -144,6 +146,10 @@ patch -p1