Reputation: 22542
I am having some problems uploading a small vector of vec4
s to the GPU. I have boiled this problem down to the bare minimum code to throw an error.
Here is my Fragment shader:
precision mediump float;
uniform vec4 test[5];
void main() {
gl_FragColor = test[0]+test[1]+test[2]+test[3]+test[4];
}
And the vertex shader is trivial:
attribute vec4 vPosition;
void main(){
gl_Position = vPosition;
}
Here is the code that tries to upload the vec4
vector:
float[] testBuffer = new float[4*5];
// Fill with 1/5s for now
Arrays.fill(testBuffer, 0.2f);
// Get the location
int testLoc = GLES20.glGetUniformLocation(mProgram, "test");
checkGlError("glGetUniformLocation test");
// Upload the buffer
GLES20.glUniform4fv(testLoc, 5, testBuffer, 0);
checkGlError("glUniform4fv testBuffer");
The error is found on the second call to checkGlError()
, and the error code is GL_INVALID_OPERATION.
I've read the documentation on glUniform and all of the sizes and types appear to be correct. testLoc
is a valid location handle, and I have no errors when uploading the fragment and vertex shader code.
I just can't see what I'm doing wrong! Any ideas?
--UPDATED
Upvotes: 3
Views: 5668
Reputation: 45948
See glUniform
documentation:
GL_INVALID_OPERATION is generated if there is no current program object
Make sure your shader is currently bound/used when calling glUniform
(glUseProgram
has been called with the corresponding shader program handle). The uniform keeps its value when unbinding the shader (e.g. glUseProgram(0)
), but the program has to be active when setting the uniform value.
Upvotes: 8