First cut at a fixed point to floating point conversion script + patches
This commit doesn't actually include any direct changes to source; you
have to run ./fixed-to-float.sh. Note: the script will make a number of
commits itself to your git repository a various stages of the script.
You will need to reset these if you want to re-run the script.
* NB: Be carefull about how you reset your tree, if you are making changes
to the script and patches, so you don't loose your changes *
This aims to remove all use of fixed point within Clutter and Cogl. It aims to
not break the Clutter API, including maintaining the CLUTTER_FIXED macros,
(though they now handle floats not 16.16 fixed)
It maintains cogl-fixed.[ch] as a utility API that can be used by applications
(and potentially for focused internal optimisations), but all Cogl interfaces
now accept floats in place of CoglFixed.
Note: the choice to to use single precision floats, not doubles is very
intentional. GPUs are basically all single precision; only this year have high
end cards started adding double precision - aimed mostly at the GPGPU market.
This means if you pass doubles into any GL[ES] driver, you can expect those
numbers to be cast to a float. (Certainly this is true of Mesa wich casts
most things to floats internally) It can be a noteable performance issue to
cast from double->float frequently, and if we were to have an api defined in
terms of doubles, that would imply a *lot* of unneeded casting. One of the
noteable issues with fixed point was the amount of casting required, so I
don't want to overshoot the mark and require just as much casting still. Double
precision arithmatic is also slower, so it usually makes sense to minimize its
use if the extra precision isn't needed. In the same way that the fast/low
precision fixed API can be used sparingly for optimisations; if needs be in
certain situations we can promote to doubles internally for higher precision.
E.g.
quoting Brian Paul (talking about performance optimisations for GL programmers):
"Avoid double precision valued functions
Mesa does all internal floating point computations in single precision
floating point. API functions which take double precision floating point
values must convert them to single precision. This can be expensive in the
case of glVertex, glNormal, etc. "
2008-12-19 21:55:35 +00:00
|
|
|
diff --git a/clutter/cogl/gl/cogl.c b/clutter/cogl/gl/cogl.c
|
2009-01-15 15:24:05 +00:00
|
|
|
index 7b61b63..d815e3b 100644
|
First cut at a fixed point to floating point conversion script + patches
This commit doesn't actually include any direct changes to source; you
have to run ./fixed-to-float.sh. Note: the script will make a number of
commits itself to your git repository a various stages of the script.
You will need to reset these if you want to re-run the script.
* NB: Be carefull about how you reset your tree, if you are making changes
to the script and patches, so you don't loose your changes *
This aims to remove all use of fixed point within Clutter and Cogl. It aims to
not break the Clutter API, including maintaining the CLUTTER_FIXED macros,
(though they now handle floats not 16.16 fixed)
It maintains cogl-fixed.[ch] as a utility API that can be used by applications
(and potentially for focused internal optimisations), but all Cogl interfaces
now accept floats in place of CoglFixed.
Note: the choice to to use single precision floats, not doubles is very
intentional. GPUs are basically all single precision; only this year have high
end cards started adding double precision - aimed mostly at the GPGPU market.
This means if you pass doubles into any GL[ES] driver, you can expect those
numbers to be cast to a float. (Certainly this is true of Mesa wich casts
most things to floats internally) It can be a noteable performance issue to
cast from double->float frequently, and if we were to have an api defined in
terms of doubles, that would imply a *lot* of unneeded casting. One of the
noteable issues with fixed point was the amount of casting required, so I
don't want to overshoot the mark and require just as much casting still. Double
precision arithmatic is also slower, so it usually makes sense to minimize its
use if the extra precision isn't needed. In the same way that the fast/low
precision fixed API can be used sparingly for optimisations; if needs be in
certain situations we can promote to doubles internally for higher precision.
E.g.
quoting Brian Paul (talking about performance optimisations for GL programmers):
"Avoid double precision valued functions
Mesa does all internal floating point computations in single precision
floating point. API functions which take double precision floating point
values must convert them to single precision. This can be expensive in the
case of glVertex, glNormal, etc. "
2008-12-19 21:55:35 +00:00
|
|
|
--- a/clutter/cogl/gl/cogl.c
|
|
|
|
+++ b/clutter/cogl/gl/cogl.c
|
|
|
|
@@ -211,17 +211,17 @@ cogl_pop_matrix (void)
|
|
|
|
void
|
|
|
|
cogl_scale (float x, float y)
|
|
|
|
{
|
|
|
|
- glScaled ((double)(x),
|
|
|
|
- (double)(y),
|
|
|
|
+ glScalef ((float)(x),
|
|
|
|
+ (float)(y),
|
|
|
|
1.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_translatex (float x, float y, float z)
|
|
|
|
{
|
|
|
|
- glTranslated ((double)(x),
|
|
|
|
- (double)(y),
|
|
|
|
- (double)(z));
|
|
|
|
+ glTranslatef ((float)(x),
|
|
|
|
+ (float)(y),
|
|
|
|
+ (float)(z));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-01-12 18:15:40 +00:00
|
|
|
@@ -231,12 +231,12 @@ cogl_translate (gint x, gint y, gint z)
|
|
|
|
}
|
|
|
|
|
First cut at a fixed point to floating point conversion script + patches
This commit doesn't actually include any direct changes to source; you
have to run ./fixed-to-float.sh. Note: the script will make a number of
commits itself to your git repository a various stages of the script.
You will need to reset these if you want to re-run the script.
* NB: Be carefull about how you reset your tree, if you are making changes
to the script and patches, so you don't loose your changes *
This aims to remove all use of fixed point within Clutter and Cogl. It aims to
not break the Clutter API, including maintaining the CLUTTER_FIXED macros,
(though they now handle floats not 16.16 fixed)
It maintains cogl-fixed.[ch] as a utility API that can be used by applications
(and potentially for focused internal optimisations), but all Cogl interfaces
now accept floats in place of CoglFixed.
Note: the choice to to use single precision floats, not doubles is very
intentional. GPUs are basically all single precision; only this year have high
end cards started adding double precision - aimed mostly at the GPGPU market.
This means if you pass doubles into any GL[ES] driver, you can expect those
numbers to be cast to a float. (Certainly this is true of Mesa wich casts
most things to floats internally) It can be a noteable performance issue to
cast from double->float frequently, and if we were to have an api defined in
terms of doubles, that would imply a *lot* of unneeded casting. One of the
noteable issues with fixed point was the amount of casting required, so I
don't want to overshoot the mark and require just as much casting still. Double
precision arithmatic is also slower, so it usually makes sense to minimize its
use if the extra precision isn't needed. In the same way that the fast/low
precision fixed API can be used sparingly for optimisations; if needs be in
certain situations we can promote to doubles internally for higher precision.
E.g.
quoting Brian Paul (talking about performance optimisations for GL programmers):
"Avoid double precision valued functions
Mesa does all internal floating point computations in single precision
floating point. API functions which take double precision floating point
values must convert them to single precision. This can be expensive in the
case of glVertex, glNormal, etc. "
2008-12-19 21:55:35 +00:00
|
|
|
void
|
2009-01-12 18:15:40 +00:00
|
|
|
-cogl_rotatex (float angle, gint x, gint y, gint z)
|
|
|
|
+cogl_rotatex (float angle, float x, float y, float z)
|
First cut at a fixed point to floating point conversion script + patches
This commit doesn't actually include any direct changes to source; you
have to run ./fixed-to-float.sh. Note: the script will make a number of
commits itself to your git repository a various stages of the script.
You will need to reset these if you want to re-run the script.
* NB: Be carefull about how you reset your tree, if you are making changes
to the script and patches, so you don't loose your changes *
This aims to remove all use of fixed point within Clutter and Cogl. It aims to
not break the Clutter API, including maintaining the CLUTTER_FIXED macros,
(though they now handle floats not 16.16 fixed)
It maintains cogl-fixed.[ch] as a utility API that can be used by applications
(and potentially for focused internal optimisations), but all Cogl interfaces
now accept floats in place of CoglFixed.
Note: the choice to to use single precision floats, not doubles is very
intentional. GPUs are basically all single precision; only this year have high
end cards started adding double precision - aimed mostly at the GPGPU market.
This means if you pass doubles into any GL[ES] driver, you can expect those
numbers to be cast to a float. (Certainly this is true of Mesa wich casts
most things to floats internally) It can be a noteable performance issue to
cast from double->float frequently, and if we were to have an api defined in
terms of doubles, that would imply a *lot* of unneeded casting. One of the
noteable issues with fixed point was the amount of casting required, so I
don't want to overshoot the mark and require just as much casting still. Double
precision arithmatic is also slower, so it usually makes sense to minimize its
use if the extra precision isn't needed. In the same way that the fast/low
precision fixed API can be used sparingly for optimisations; if needs be in
certain situations we can promote to doubles internally for higher precision.
E.g.
quoting Brian Paul (talking about performance optimisations for GL programmers):
"Avoid double precision valued functions
Mesa does all internal floating point computations in single precision
floating point. API functions which take double precision floating point
values must convert them to single precision. This can be expensive in the
case of glVertex, glNormal, etc. "
2008-12-19 21:55:35 +00:00
|
|
|
{
|
|
|
|
- glRotated ((double)(angle),
|
|
|
|
- (double)(x),
|
|
|
|
- (double)(y),
|
|
|
|
- (double)(z));
|
|
|
|
+ glRotatef ((float)(angle),
|
|
|
|
+ (float)(x),
|
|
|
|
+ (float)(y),
|
|
|
|
+ (float)(z));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
@@ -645,17 +645,13 @@ cogl_perspective (float fovy,
|
|
|
|
* 2) When working with small numbers, we 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 = cogl_fixed_mul_div (-(2 * zFar), zNear, (zFar - zNear));
|
|
|
|
+ d = (-(2 * zFar) * zNear) / (zFar - zNear);
|
|
|
|
|
|
|
|
#define M(row,col) m[col*4+row]
|
|
|
|
M(0,0) = (x);
|
|
|
|
@@ -696,12 +692,12 @@ cogl_frustum (float left,
|
|
|
|
GE( glMatrixMode (GL_PROJECTION) );
|
|
|
|
GE( glLoadIdentity () );
|
|
|
|
|
|
|
|
- GE( glFrustum ((double)(left),
|
|
|
|
- (double)(right),
|
|
|
|
- (double)(bottom),
|
|
|
|
- (double)(top),
|
|
|
|
- (double)(z_near),
|
|
|
|
- (double)(z_far)) );
|
|
|
|
+ GE( glFrustum ((GLdouble)(left),
|
|
|
|
+ (GLdouble)(right),
|
|
|
|
+ (GLdouble)(bottom),
|
|
|
|
+ (GLdouble)(top),
|
|
|
|
+ (GLdouble)(z_near),
|
|
|
|
+ (GLdouble)(z_far)) );
|
|
|
|
|
|
|
|
GE( glMatrixMode (GL_MODELVIEW) );
|
|
|
|
|
|
|
|
@@ -773,9 +769,7 @@ cogl_setup_viewport (guint width,
|
|
|
|
{
|
|
|
|
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( glTranslatef (-0.5f, -0.5f, -z_camera) );
|
2009-01-15 15:24:05 +00:00
|
|
|
@@ -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
|