summaryrefslogtreecommitdiffstats
path: root/examples/widgets/graphicsview/boxes
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2012-08-20 20:55:40 +0100
committerQt by Nokia <qt-info@nokia.com>2012-09-07 13:27:38 +0200
commit51d40d7e9bdfc63c5109aef5b732aa2ba10f985a (patch)
treeffa750956ab2e96e0cd8f02bafa820042aa9f78a /examples/widgets/graphicsview/boxes
parent56414e2498ae19d305b391678afe3a67a9069832 (diff)
Make gui/math3d classes use float rather than qreal
This corrects the mismatch between using floats for internal storage and qreal in the API of QVector*D which leads to lots of implicit casts between double and float. This change also stops users from being surprised by the loss of precision when using these classes on desktop platforms and removes the need for the private constructors taking a dummy int as the final argument. The QMatrix4x4 and QQuaternion classes have been changed to use float for their internal storage since these are meant to be used in conjunction with the QVector*D classes. This is to prevent unexpected loss of precision and to improve performance. The on-disk format has also been changed from double to float thereby reducing the storage required when streaming vectors and matrices. This is potentially a large saving when working with complex 3D meshes etc. This also has a significant performance improvement when passing matrices to QOpenGLShaderProgram (and QGLShaderProgram) as we no longer have to iterate and convert the data to floats. This is an operation that could easily be needed many times per frame. This change also opens the door for further optimisations of these classes to be implemented by using SIMD intrinsics. This needs to be applied in conjunction with https://codereview.qt-project.org/#change,33548 Task-number: QTBUG-21035 Task-number: QTBUG-20661 Change-Id: I9321b06040ffb93ae1cbd72fd2013267ac901b2e Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'examples/widgets/graphicsview/boxes')
-rw-r--r--examples/widgets/graphicsview/boxes/scene.cpp16
1 files changed, 3 insertions, 13 deletions
diff --git a/examples/widgets/graphicsview/boxes/scene.cpp b/examples/widgets/graphicsview/boxes/scene.cpp
index 5fb43d8c99..cf0b021b47 100644
--- a/examples/widgets/graphicsview/boxes/scene.cpp
+++ b/examples/widgets/graphicsview/boxes/scene.cpp
@@ -655,22 +655,12 @@ static void loadMatrix(const QMatrix4x4& m)
{
// static to prevent glLoadMatrixf to fail on certain drivers
static GLfloat mat[16];
- const qreal *data = m.constData();
+ const float *data = m.constData();
for (int index = 0; index < 16; ++index)
mat[index] = data[index];
glLoadMatrixf(mat);
}
-static void multMatrix(const QMatrix4x4& m)
-{
- // static to prevent glMultMatrixf to fail on certain drivers
- static 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)
@@ -722,7 +712,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
glPushMatrix();
QMatrix4x4 m;
m.rotate(m_trackBalls[1].rotation());
- multMatrix(m);
+ glMultMatrixf(m.constData());
glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f);
glTranslatef(2.0f, 0.0f, 0.0f);
@@ -755,7 +745,7 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox)
if (-1 != excludeBox) {
QMatrix4x4 m;
m.rotate(m_trackBalls[0].rotation());
- multMatrix(m);
+ glMultMatrixf(m.constData());
if (glActiveTexture) {
if (m_dynamicCubemap)