summaryrefslogtreecommitdiffstats
path: root/demos/boxes
diff options
context:
space:
mode:
authorRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 04:12:08 (GMT)
committerRhys Weatherley <rhys.weatherley@nokia.com>2009-09-04 07:00:23 (GMT)
commit974aec137dfdbb1dd68c41113b22eb25131965b8 (patch)
treeadbf042502fd35d1bce5a2aea811d41633ecd495 /demos/boxes
parent4c501d7fce503a610edabfba5d6efc3ef2778bef (diff)
downloadQt-974aec137dfdbb1dd68c41113b22eb25131965b8.zip
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.gz
Qt-974aec137dfdbb1dd68c41113b22eb25131965b8.tar.bz2
Modify QMatrix4x4 and QQuaternion to use qreal internally
Some concerns were expressed about the float precision of QMatrix4x4, which this change addresses by using qreal instead. The QVector2D/3D/4D classes still use float internally, so that they can be used directly in large arrays of vertex values to be uploaded to an OpenGL server. QQuaternion is a client-side class, and it should produce rotations that are consistent with QMatrix4x4. So its precision was changed too. A consequence of this change is that the following no longer works in a portable fashion: QMatrix4x4 mat; ... glLoadMatrixf(mat.constData()); The caller must now repack the argument to convert from qreal to GLfloat. Reviewed-by: Michael Goddard Reviewed-by: Andreas
Diffstat (limited to 'demos/boxes')
-rw-r--r--demos/boxes/scene.cpp28
1 files changed, 23 insertions, 5 deletions
diff --git a/demos/boxes/scene.cpp b/demos/boxes/scene.cpp
index 2a7ca0e..7c0d4d8 100644
--- a/demos/boxes/scene.cpp
+++ b/demos/boxes/scene.cpp
@@ -649,6 +649,24 @@ void Scene::initGL()
m_renderOptions->emitParameterChanged();
}
+static void loadMatrix(const QMatrix4x4& m)
+{
+ GLfloat mat[16];
+ const qreal *data = m.constData();
+ for (int index = 0; index < 16; ++index)
+ mat[index] = data[index];
+ glLoadMatrixf(mat);
+}
+
+static void multMatrix(const QMatrix4x4& m)
+{
+ GLfloat mat[16];
+ const qreal *data = m.constData();
+ for (int index = 0; index < 16; ++index)
+ mat[index] = data[index];
+ glMultMatrixf(mat);
+}
+
// If one of the boxes should not be rendered, set excludeBox to its index.
// If the main box should not be rendered, set excludeBox to -1.
void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
@@ -673,7 +691,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
viewRotation(3, 0) = viewRotation(3, 1) = viewRotation(3, 2) = 0.0f;
viewRotation(0, 3) = viewRotation(1, 3) = viewRotation(2, 3) = 0.0f;
viewRotation(3, 3) = 1.0f;
- glLoadMatrixf(viewRotation.data());
+ loadMatrix(viewRotation);
glScalef(20.0f, 20.0f, 20.0f);
// Don't render the environment if the environment texture can't be set for the correct sampler.
@@ -688,7 +706,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
m_environment->unbind();
}
- glLoadMatrixf(view.data());
+ loadMatrix(view);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
@@ -702,7 +720,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
m.rotate(m_trackBalls[1].rotation());
m = m.transposed();
- glMultMatrixf(m.data());
+ multMatrix(m);
glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f);
glTranslatef(2.0f, 0.0f, 0.0f);
@@ -736,7 +754,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
QMatrix4x4 m;
m.rotate(m_trackBalls[0].rotation());
m = m.transposed();
- glMultMatrixf(m.data());
+ multMatrix(m);
if (glActiveTexture) {
if (m_dynamicCubemap)
@@ -842,7 +860,7 @@ void Scene::renderCubemaps()
glMatrixMode(GL_PROJECTION);
glPushMatrix();
- glLoadMatrixf(mat.data());
+ loadMatrix(mat);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();