From ea1d9f55227fc2e291fc600accef5ba3abbdd58f Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Thu, 15 Jan 2009 15:24:05 +0000 Subject: [PATCH] [fixed-to-float-patches] Fix some of the matrix getters and setters The GL versions of get_modelview_matrix, get_projection_matrix and get_viewport were using glGetDoublev and then converting them to floats, but it might as well just call glGetFloatv directly. The GL ES versions were using glGetFixedv but this was being replaced with glGetFloatv by the #define in the GLES 2 wrappers. The patch also replaces the glGetFixedv wrapper with glGetFloatv. Previously this was calling cogl_gles2_float_array_to_fixed which actually converted to float. That function has been removed and memcpy is used instead. --- fixed-to-float-patches/gl-cogl.c.0.patch | 79 ++++++++++++++++++- .../gles-cogl-gles2-wrapper.c.0.patch | 58 ++++++++++++++ .../gles-cogl-gles2-wrapper.h.0.patch | 13 ++- fixed-to-float-patches/gles-cogl.c.0.patch | 29 ++++++- fixed-to-float.sh | 1 + 5 files changed, 176 insertions(+), 4 deletions(-) create mode 100644 fixed-to-float-patches/gles-cogl-gles2-wrapper.c.0.patch diff --git a/fixed-to-float-patches/gl-cogl.c.0.patch b/fixed-to-float-patches/gl-cogl.c.0.patch index 898f94d48..6db7cee11 100644 --- a/fixed-to-float-patches/gl-cogl.c.0.patch +++ b/fixed-to-float-patches/gl-cogl.c.0.patch @@ -1,5 +1,5 @@ diff --git a/clutter/cogl/gl/cogl.c b/clutter/cogl/gl/cogl.c -index 7b61b63..5100a08 100644 +index 7b61b63..d815e3b 100644 --- a/clutter/cogl/gl/cogl.c +++ b/clutter/cogl/gl/cogl.c @@ -211,17 +211,17 @@ cogl_pop_matrix (void) @@ -93,3 +93,80 @@ index 7b61b63..5100a08 100644 } GE( glTranslatef (-0.5f, -0.5f, -z_camera) ); +@@ -1166,73 +1160,19 @@ cogl_features_available (CoglFeatureFlags features) + void + cogl_get_modelview_matrix (float m[16]) + { +- GLdouble md[16]; +- +- glGetDoublev(GL_MODELVIEW_MATRIX, &md[0]); +- +-#define M(m,row,col) m[col*4+row] +- M(m,0,0) = (M(md,0,0)); +- M(m,0,1) = (M(md,0,1)); +- M(m,0,2) = (M(md,0,2)); +- M(m,0,3) = (M(md,0,3)); +- +- M(m,1,0) = (M(md,1,0)); +- M(m,1,1) = (M(md,1,1)); +- M(m,1,2) = (M(md,1,2)); +- M(m,1,3) = (M(md,1,3)); +- +- M(m,2,0) = (M(md,2,0)); +- M(m,2,1) = (M(md,2,1)); +- M(m,2,2) = (M(md,2,2)); +- M(m,2,3) = (M(md,2,3)); +- +- M(m,3,0) = (M(md,3,0)); +- M(m,3,1) = (M(md,3,1)); +- M(m,3,2) = (M(md,3,2)); +- M(m,3,3) = (M(md,3,3)); +-#undef M ++ glGetFloatv (GL_MODELVIEW_MATRIX, m); + } + + void + cogl_get_projection_matrix (float m[16]) + { +- GLdouble md[16]; +- +- glGetDoublev(GL_PROJECTION_MATRIX, &md[0]); +- +-#define M(m,row,col) m[col*4+row] +- M(m,0,0) = (M(md,0,0)); +- M(m,0,1) = (M(md,0,1)); +- M(m,0,2) = (M(md,0,2)); +- M(m,0,3) = (M(md,0,3)); +- +- M(m,1,0) = (M(md,1,0)); +- M(m,1,1) = (M(md,1,1)); +- M(m,1,2) = (M(md,1,2)); +- M(m,1,3) = (M(md,1,3)); +- +- M(m,2,0) = (M(md,2,0)); +- M(m,2,1) = (M(md,2,1)); +- M(m,2,2) = (M(md,2,2)); +- M(m,2,3) = (M(md,2,3)); +- +- M(m,3,0) = (M(md,3,0)); +- M(m,3,1) = (M(md,3,1)); +- M(m,3,2) = (M(md,3,2)); +- M(m,3,3) = (M(md,3,3)); +-#undef M ++ glGetFloatv (GL_PROJECTION_MATRIX, m); + } + + void + cogl_get_viewport (float v[4]) + { +- GLdouble vd[4]; +- glGetDoublev(GL_VIEWPORT, &vd[0]); +- +- v[0] = (vd[0]); +- v[1] = (vd[1]); +- v[2] = (vd[2]); +- v[3] = (vd[3]); ++ glGetFloatv (GL_VIEWPORT, v); + } + + void diff --git a/fixed-to-float-patches/gles-cogl-gles2-wrapper.c.0.patch b/fixed-to-float-patches/gles-cogl-gles2-wrapper.c.0.patch new file mode 100644 index 000000000..9cebe5b34 --- /dev/null +++ b/fixed-to-float-patches/gles-cogl-gles2-wrapper.c.0.patch @@ -0,0 +1,58 @@ +diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.c b/clutter/cogl/gles/cogl-gles2-wrapper.c +index 859c895..8a2fd24 100644 +--- a/clutter/cogl/gles/cogl-gles2-wrapper.c ++++ b/clutter/cogl/gles/cogl-gles2-wrapper.c +@@ -1142,15 +1142,6 @@ cogl_wrap_glClipPlanex (GLenum plane, GLfloat *equation) + /* FIXME */ + } + +-static void +-cogl_gles2_float_array_to_fixed (int size, +- const GLfloat *floats, +- GLfloat *fixeds) +-{ +- while (size-- > 0) +- *(fixeds++) = (*(floats++)); +-} +- + void + cogl_wrap_glGetIntegerv (GLenum pname, GLint *params) + { +@@ -1169,31 +1160,24 @@ cogl_wrap_glGetIntegerv (GLenum pname, GLint *params) + } + + void +-cogl_wrap_glGetFixedv (GLenum pname, GLfloat *params) ++cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params) + { + _COGL_GET_GLES2_WRAPPER (w, NO_RETVAL); + + switch (pname) + { + case GL_MODELVIEW_MATRIX: +- cogl_gles2_float_array_to_fixed (16, w->modelview_stack +- + w->modelview_stack_pos * 16, +- params); ++ memcpy (params, w->modelview_stack + w->modelview_stack_pos * 16, ++ sizeof (GLfloat) * 16); + break; + + case GL_PROJECTION_MATRIX: +- cogl_gles2_float_array_to_fixed (16, w->projection_stack +- + w->projection_stack_pos * 16, +- params); ++ memcpy (params, w->projection_stack + w->projection_stack_pos * 16, ++ sizeof (GLfloat) * 16); + break; + + case GL_VIEWPORT: +- { +- GLfloat v[4]; +- +- glGetFloatv (GL_VIEWPORT, v); +- cogl_gles2_float_array_to_fixed (4, v, params); +- } ++ glGetFloatv (GL_VIEWPORT, params); + break; + } + } 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 index 03deb1638..f67d98c15 100644 --- a/fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch +++ b/fixed-to-float-patches/gles-cogl-gles2-wrapper.h.0.patch @@ -1,13 +1,22 @@ diff --git a/clutter/cogl/gles/cogl-gles2-wrapper.h b/clutter/cogl/gles/cogl-gles2-wrapper.h -index 265da78..2e61121 100644 +index 265da78..2493b81 100644 --- a/clutter/cogl/gles/cogl-gles2-wrapper.h +++ b/clutter/cogl/gles/cogl-gles2-wrapper.h +@@ -244,7 +244,7 @@ void cogl_wrap_glColor4x (GLclampx r, GLclampx g, GLclampx b, GLclampx a); + void cogl_wrap_glClipPlanex (GLenum plane, GLfloat *equation); + + void cogl_wrap_glGetIntegerv (GLenum pname, GLint *params); +-void cogl_wrap_glGetFixedv (GLenum pname, GLfloat *params); ++void cogl_wrap_glGetFloatv (GLenum pname, GLfloat *params); + + void cogl_wrap_glFogx (GLenum pname, GLfloat param); + void cogl_wrap_glFogxv (GLenum pname, const GLfloat *params); @@ -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_glGetFloatv 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.c.0.patch b/fixed-to-float-patches/gles-cogl.c.0.patch index bf1daac0a..291b7eff2 100644 --- a/fixed-to-float-patches/gles-cogl.c.0.patch +++ b/fixed-to-float-patches/gles-cogl.c.0.patch @@ -1,5 +1,5 @@ diff --git a/clutter/cogl/gles/cogl.c b/clutter/cogl/gles/cogl.c -index 422d8b6..16cf666 100644 +index 422d8b6..aa4e4fc 100644 --- a/clutter/cogl/gles/cogl.c +++ b/clutter/cogl/gles/cogl.c @@ -37,6 +37,7 @@ @@ -22,6 +22,17 @@ index 422d8b6..16cf666 100644 GE( cogl_wrap_glPushMatrix () ); /* Load the identity matrix and multiply by the reverse of the +@@ -405,8 +405,8 @@ _cogl_set_clip_planes (float x_offset, + float vertex_br[4] = { x_offset + width, y_offset + height, + 0, 1.0 }; + +- GE( cogl_wrap_glGetFixedv (GL_MODELVIEW_MATRIX, modelview) ); +- GE( cogl_wrap_glGetFixedv (GL_PROJECTION_MATRIX, projection) ); ++ GE( cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, modelview) ); ++ GE( cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, projection) ); + + project_vertex (modelview, projection, vertex_tl); + project_vertex (modelview, projection, vertex_tr); @@ -558,15 +558,13 @@ cogl_perspective (float fovy, * 2) When working with small numbers, we can are loosing significant * precision @@ -58,3 +69,19 @@ index 422d8b6..16cf666 100644 GE( cogl_wrap_glScalex ( 1.0 / width, -1.0 / height, +@@ -737,13 +735,13 @@ cogl_features_available (CoglFeatureFlags features) + void + cogl_get_modelview_matrix (float m[16]) + { +- cogl_wrap_glGetFixedv(GL_MODELVIEW_MATRIX, &m[0]); ++ cogl_wrap_glGetFloatv (GL_MODELVIEW_MATRIX, m); + } + + void + cogl_get_projection_matrix (float m[16]) + { +- cogl_wrap_glGetFixedv(GL_PROJECTION_MATRIX, &m[0]); ++ cogl_wrap_glGetFloatv (GL_PROJECTION_MATRIX, m); + } + + void diff --git a/fixed-to-float.sh b/fixed-to-float.sh index d362344e1..cd967843d 100755 --- a/fixed-to-float.sh +++ b/fixed-to-float.sh @@ -148,6 +148,7 @@ patch -p1