To use a texture in an OpenGL shader, I have to write the Texture Unit to be used into a uniform variable:
source.c:
// Write 0 to uniform variable GLuint texSampler = glGetUniformLocation(program, "texSampler"); glUniform1i(texSampler, 0); shader.glsl
uniform sampler2D texSampler; void SomeFunction(vec2 coord) { vec4 data = texture(texSampler, coord); // do something } Why can't I just select the texture unit directly into the shader source, like this?
shader.glsl
void SomeFunction(vec2 coord) { vec4 data = texture(0, coord); // do something } What is the architecturial reason, that I have to use a uniform variable to pass the texture unit into the shader?