Fix passing matrixes to the shaders
QMatrix4x4 accepts data in row-major order, but returns them in column-major order, which is not documented and because of that I expected them to be in row-major order. This commit fixes it and rewrites the shaders to apply the matrix multiplications in the right order. REVIEW: 100759
This commit is contained in:
parent
13e6ead66e
commit
a728823fbe
8 changed files with 14 additions and 16 deletions
|
@ -229,7 +229,7 @@ void GLSLBlurShader::init()
|
|||
stream << "\n";
|
||||
stream << "void main(void)\n";
|
||||
stream << "{\n";
|
||||
stream << " vec2 center = vec4(texCoord * u_textureMatrix).st;\n\n";
|
||||
stream << " vec2 center = vec4(u_textureMatrix*texCoord).st;\n\n";
|
||||
|
||||
for (int i = 0; i < center; i++)
|
||||
stream << " samplePos" << i << " = center + pixelSize * vec2("
|
||||
|
@ -239,7 +239,7 @@ void GLSLBlurShader::init()
|
|||
stream << " samplePos" << i << " = center + pixelSize * vec2("
|
||||
<< 1.5 + (i - center - 1) * 2.0 << ");\n";
|
||||
stream << "\n";
|
||||
stream << " gl_Position = vertex * u_modelViewProjectionMatrix;\n";
|
||||
stream << " gl_Position = u_modelViewProjectionMatrix*vertex;\n";
|
||||
stream << "}\n";
|
||||
stream.flush();
|
||||
|
||||
|
|
|
@ -1438,7 +1438,7 @@ void CubeEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPa
|
|||
if (reflectionPainting) {
|
||||
shader->setUniform("screenTransformation", m_reflectionMatrix * m_rotationMatrix * origMatrix);
|
||||
} else {
|
||||
shader->setUniform("screenTransformation", m_rotationMatrix * origMatrix);
|
||||
shader->setUniform("screenTransformation", origMatrix*m_rotationMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,5 +47,5 @@ void main()
|
|||
vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine;
|
||||
transformedVertex.xyz += diff;
|
||||
|
||||
gl_Position = transformedVertex*(windowTransformation*screenTransformation*modelview)*projection;
|
||||
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
|
||||
}
|
||||
|
|
|
@ -51,5 +51,5 @@ void main()
|
|||
vec3 diff = (vertex.xyz - transformedVertex.xyz)*timeLine;
|
||||
transformedVertex.xyz += diff;
|
||||
|
||||
gl_Position = transformedVertex*(windowTransformation*screenTransformation*modelview)*projection;
|
||||
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*transformedVertex;
|
||||
}
|
||||
|
|
|
@ -989,10 +989,8 @@ bool GLShader::setUniform(int location, const QMatrix4x4 &value)
|
|||
GLfloat m[16];
|
||||
const qreal *data = value.constData();
|
||||
// i is column, j is row for m
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
m[i*4+j] = data[j*4+i];
|
||||
}
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
m[i] = data[i];
|
||||
}
|
||||
glUniformMatrix4fv(location, 1, GL_FALSE, m);
|
||||
}
|
||||
|
@ -1048,10 +1046,10 @@ QMatrix4x4 GLShader::getUniformMatrix4x4(const char* name)
|
|||
if (location >= 0) {
|
||||
GLfloat m[16];
|
||||
glGetUniformfv(mProgram, location, m);
|
||||
QMatrix4x4 matrix(m[0], m[1], m[2], m[3],
|
||||
m[4], m[5], m[6], m[7],
|
||||
m[8], m[9], m[10], m[11],
|
||||
m[12], m[13], m[14], m[15]);
|
||||
QMatrix4x4 matrix(m[0], m[4], m[8], m[12],
|
||||
m[1], m[5], m[9], m[13],
|
||||
m[2], m[6], m[10], m[14],
|
||||
m[3], m[7], m[11], m[15]);
|
||||
matrix.optimize();
|
||||
return matrix;
|
||||
} else {
|
||||
|
|
|
@ -6,5 +6,5 @@ uniform vec2 offset;
|
|||
attribute vec4 vertex;
|
||||
|
||||
void main() {
|
||||
gl_Position = vec4(vertex.xy + offset, vertex.zw) * projection;
|
||||
gl_Position = projection*vec4(vertex.xy + offset, vertex.zw);
|
||||
}
|
||||
|
|
|
@ -16,5 +16,5 @@ varying vec2 varyingTexCoords;
|
|||
|
||||
void main() {
|
||||
varyingTexCoords = texCoord / vec2(textureWidth, textureHeight);
|
||||
gl_Position = vertex*(windowTransformation*screenTransformation*modelview)*projection;
|
||||
gl_Position = projection*(modelview*screenTransformation*windowTransformation)*vertex;
|
||||
}
|
||||
|
|
|
@ -15,5 +15,5 @@ varying vec2 varyingTexCoords;
|
|||
|
||||
void main() {
|
||||
varyingTexCoords = texCoord / vec2(textureWidth, textureHeight);
|
||||
gl_Position = vec4(vertex.xy + offset, vertex.zw) * projection;
|
||||
gl_Position = projection*vec4(vertex.xy + offset, vertex.zw);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue