PDA

View Full Version : OpenGL ES glUniformMatrix bug with sending transposed data



maxest
08-20-2012, 03:55 AM
I've just spent an hour or two trying to get this code work:


float *tab = new float[16];
for (int i = 0; i < 16; i++)
tab[i] = 0.25f;
GLint uniformLocation = glGetUniformLocation(gProgram, "vvv");
glUniformMatrix4fv(uniformLocation, 1, true, tab);
delete[] tab;

The shader, instead of getting a matrix filled with 0.25, gets same zeroes. However, when I set 3rd param of glUniformMatrix to "false" (that is, the data is non-transposed), everything works fine. I guess this is a driver bug? (I'm using a Tegra2-based device with Android 2.2)

thokra
08-20-2012, 07:07 AM
Did you call glUseProgram before using glUniform*? Did you successfully link the program? Is uniformLocation > -1 after glGetUniformLocation?

If all the above are true in your case I guess it's simply a bug in the Tegra drivers. Can't confirm it myself here on account of not possessing a smartphone.

maxest
10-01-2012, 08:46 AM
glGetUniformLocation returns a valid value. However, I noticed that when I want the matrix to be tranposed (and thus set the third arg. of glUniformMatrix to true) I get erros with glGetError, namely, GL_INVALID_VALUE error.

Alfonse Reinheart
10-01-2012, 08:49 AM
GL_TRUE is an invalid value. OpenGL ES doesn't allow you to pass transposed matrices. They must be column-major, and the spec is clear that passing anything other than GL_FALSE is an error.

The only reason ES 2.0 even has that parameter is because desktop GL had it.

maxest
10-20-2012, 07:53 AM
I probably should have checked the docs earlier but honestly this is very surprising it works this way. It is here if anyone is interested http://www.khronos.org/opengles/sdk/docs/man/xhtml/glUniform.xml
Thanks Alfonse for pointing this out.