Question

I already learned that uniform values are stored in the state of the shader program.

// GLSL code
uniform mat4 projection;

// C++ code
GLuint location = glGetUniformLocation(program, "projection");
glUniformMatrix4fv(location, 1, GL_FALSE, pointer);

But that seems to not apply for texture uniforms since they are bound by the number of a texture slot instead of their id.

// GLSL code
uniform sampler2D albedo;

// C++ code
int slot = 3;
glActiveTexture(GL_TEXTURE0 + slot);
glBindTexture(GL_TEXTURE_2D, id);
GLuint location = glGetUniformLocation(program, "albedo");
glUniform1i(location, slot);

Is there a way to bind a texture id to a sampler2D uniform of a shader? This way I would not have to bind all textures manually for each pass.

Was it helpful?

Solution

Is there a way to bind a texture id to a sampler2D uniform of a shader?

No, not really, because samplers access texture units, not texture objects. However NVidia's Kepler GPUs can use bindless textures, available to OpenGL as a vendor specific extension, which practically implement what you ask for.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top