gl: always check QMatrix4x4 type and GLfloat

This commit is contained in:
wang-bin
2014-03-06 22:10:09 +08:00
parent 85e3dc16f0
commit 1b5d40e840
2 changed files with 15 additions and 10 deletions
+11 -6
View File
@@ -672,16 +672,21 @@ void GLWidgetRenderer::drawFrame()
/*
* in Qt4 QMatrix4x4 stores qreal (double), while GLfloat may be float
* Use glm?
* QShaderProgram deal with this case. But compares sizeof(QMatrix4x4) and (GLfloat)*16
* which seems not correct because QMatrix4x4 has a flag var
*/
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
GLfloat *mat = (GLfloat*)d.colorTransform.matrixRef().data();
GLfloat glm[16];
d.colorTransform.matrixData(glm);
glUniformMatrix4fv(d.u_colorMatrix, 1, GL_TRUE, glm);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
if (sizeof(qreal) != sizeof(GLfloat)) {
#else
//QMatrix4x4 stores value in Column-major order to match OpenGL. so transpose is not required in glUniformMatrix4fv
glUniformMatrix4fv(d.u_colorMatrix, 1, GL_FALSE, (GLfloat*)d.colorTransform.matrix().constData());
if (sizeof(float) != sizeof(GLfloat)) {
#endif
d.colorTransform.matrixData(glm);
mat = glm;
}
//QMatrix4x4 stores value in Column-major order to match OpenGL. so transpose is not required in glUniformMatrix4fv
glUniformMatrix4fv(d.u_colorMatrix, 1, GL_FALSE, mat);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+4 -4
View File
@@ -48,10 +48,10 @@ public:
const QMatrix4x4& matrixRef() const;
template<typename T> void matrixData(T* M) {
const QMatrix4x4 &m = matrixRef();
M[0] = m(0,0), M[1] = m(0,1), M[2] = m(0,2), M[3] = m(0,3),
M[4] = m(1,0), M[5] = m(1,1), M[6] = m(1,2), M[7] = m(1,3),
M[8] = m(2,0), M[9] = m(2,1), M[10] = m(2,2), M[11] = m(2,3),
M[12] = m(3,0), M[13] = m(3,1), M[14] = m(3,2), M[15] = m(3,3);
M[0] = m(0,0), M[4] = m(0,1), M[8] = m(0,2), M[12] = m(0,3),
M[1] = m(1,0), M[5] = m(1,1), M[9] = m(1,2), M[13] = m(1,3),
M[2] = m(2,0), M[6] = m(2,1), M[10] = m(2,2), M[14] = m(2,3),
M[3] = m(3,0), M[7] = m(3,1), M[11] = m(3,2), M[15] = m(3,3);
}
/*!