I have a sampler variable in a shader:
uniform sampler2DArray tiles;
Which I am trying to bind to a texture unit in GL:
int tilesUniformIndex = glGetUniformLocation(shaderProgramId,"tiles");
System.out.println("tiles: "+tilesUniformIndex);
glUseProgram(shaderProgramId);
glok(); // <- This calls glGetError() and throws exception if not-ok
glUniform1i(tilesUniformIndex, GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX);
glok();
TILE_TEXTURE_UNIT_INDEX
is a constant defined to be zero.
The location is being correctly introspected, output is:
tiles: 7
which is the correct binding location I expect in context of the shader source.
The /second/ glok() is throwing an exception, with 0x501 GL_INVALID_VALUE.
According to the documentation, this can only happen if the count
parameter is less than zero. But glUniform1i
/doesn't have a count parameter/!
I've tried:
glUniform1iv(tilesUniformIndex, 1, new int[]{GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX});
as well, and the implementation of that does what it looks like (passes a memory pointer to the array data as output value
).
So, what gives? Anyone know how this function can possibly behave like this? This is a simple, correct use case, right?
GL_TEXTURE0 + TILE_TEXTURE_UNIT_INDEX
You don't set sampler uniforms to OpenGL enumerators. You set them to the actual texture unit index. This isn't your actual problem, but it's non-functional never-the-less. $\endgroup$