I am using a uniform variable to pass a floating point value into a GLES shader, but my code keeps generating a 1282 error. I've followed a couple of examples on here and am pretty sure I am doing everything correctly. Can you spot anything wrong with my code? I am testing this on Android 4.4.2 on a Nexus 7
I use this in onDrawFrame:
GLES20.glUseProgram(mProgram);
int aMyUniform = GLES20.glGetUniformLocation(mProgram, "myUniform");
glVar = frameNumber/100f;
GLES20.glUniform1f(aMyUniform, glVar);
System.out.println("aMyUniform = " + aMyUniform); //diagnostic check
This is in the top of the fragment shader:
"uniform float myUniform;\n" +
And this in the main routine of the fragment shader:
"gl_FragColor[2] = myUniform;\n" +
The variable myUniform does not appear in the vertex shader.
The value reported for aMyUniform is 0, which suggests the uniform has been found correctly. If I change the fragment shader to remove the reference to myUniform and replace it with a hard-coded value everything works as expected; aMyUniform returns a value of -1 but scene draws correctly.
If you can't spot anything wrong with the code any hints on how to debug it would be appreciated.
After a lot of head scratching this turns out to have the same cause as this fault: GLSL Shader will not render color from uniform variable I was reusing the mvpMatrix uniform across additional shaders. This did not produce an error until this additional uniform was introduced. I only clue I found to this was that the error did not occur until the next shader was called, I didn't pay much attention to this at the time but it should have been a clue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.