summaryrefslogtreecommitdiffstats
path: root/src/gui/opengl
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 /src/gui/opengl
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 'src/gui/opengl')
-rw-r--r--src/gui/opengl/qopenglshaderprogram.cpp53
1 files changed, 9 insertions, 44 deletions
diff --git a/src/gui/opengl/qopenglshaderprogram.cpp b/src/gui/opengl/qopenglshaderprogram.cpp
index 100fc0bbdb..e74d4952d0 100644
--- a/src/gui/opengl/qopenglshaderprogram.cpp
+++ b/src/gui/opengl/qopenglshaderprogram.cpp
@@ -2131,35 +2131,6 @@ void QOpenGLShaderProgram::setUniformValue(const char *name, const QSizeF& size)
setUniformValue(uniformLocation(name), size);
}
-// We have to repack matrices from qreal to GLfloat.
-#define setUniformMatrix(func,location,value,cols,rows) \
- if (location == -1) \
- return; \
- if (sizeof(qreal) == sizeof(GLfloat)) { \
- func(location, 1, GL_FALSE, \
- reinterpret_cast<const GLfloat *>(value.constData())); \
- } else { \
- GLfloat mat[cols * rows]; \
- const qreal *data = value.constData(); \
- for (int i = 0; i < cols * rows; ++i) \
- mat[i] = data[i]; \
- func(location, 1, GL_FALSE, mat); \
- }
-#define setUniformGenericMatrix(colfunc,location,value,cols,rows) \
- if (location == -1) \
- return; \
- if (sizeof(qreal) == sizeof(GLfloat)) { \
- const GLfloat *data = reinterpret_cast<const GLfloat *> \
- (value.constData()); \
- colfunc(location, cols, data); \
- } else { \
- GLfloat mat[cols * rows]; \
- const qreal *data = value.constData(); \
- for (int i = 0; i < cols * rows; ++i) \
- mat[i] = data[i]; \
- colfunc(location, cols, mat); \
- }
-
/*!
Sets the uniform variable at \a location in the current context
to a 2x2 matrix \a value.
@@ -2170,7 +2141,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix2fv, location, value, 2, 2);
+ d->glfuncs->glUniformMatrix2fv(location, 1, GL_FALSE, value.constData());
}
/*!
@@ -2196,8 +2167,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform3fv, location, value, 2, 3);
+ d->glfuncs->glUniform3fv(location, 2, value.constData());
}
/*!
@@ -2223,8 +2193,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix2x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform4fv, location, value, 2, 4);
+ d->glfuncs->glUniform4fv(location, 2, value.constData());
}
/*!
@@ -2250,8 +2219,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform2fv, location, value, 3, 2);
+ d->glfuncs->glUniform2fv(location, 3, value.constData());
}
/*!
@@ -2277,7 +2245,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix3fv, location, value, 3, 3);
+ d->glfuncs->glUniformMatrix3fv(location, 1, GL_FALSE, value.constData());
}
/*!
@@ -2303,8 +2271,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix3x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform4fv, location, value, 3, 4);
+ d->glfuncs->glUniform4fv(location, 3, value.constData());
}
/*!
@@ -2330,8 +2297,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x2& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform2fv, location, value, 4, 2);
+ d->glfuncs->glUniform2fv(location, 4, value.constData());
}
/*!
@@ -2357,8 +2323,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x3& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformGenericMatrix
- (d->glfuncs->glUniform3fv, location, value, 4, 3);
+ d->glfuncs->glUniform3fv(location, 4, value.constData());
}
/*!
@@ -2384,7 +2349,7 @@ void QOpenGLShaderProgram::setUniformValue(int location, const QMatrix4x4& value
{
Q_D(QOpenGLShaderProgram);
Q_UNUSED(d);
- setUniformMatrix(d->glfuncs->glUniformMatrix4fv, location, value, 4, 4);
+ d->glfuncs->glUniformMatrix4fv(location, 1, GL_FALSE, value.constData());
}
/*!