1
$\begingroup$

The way I learnt to send a texture to a shader is more or less

//Use program
//Bind texture to the texture unit to its appropriate target
glActiveTexture(GL_TEXTURE0 + texture_unit);
glBindTexture(target, textureID);
//Get the uniform location in the program and attach the texture unit
GLuint location = /*get the location somewhow*/;
glUniform1i(location,texture_unit);

However when dealing with buffers and SSBOS rather than trying to find a location through a string name, the object is declared as:

layout(std430, binding = 2) buffer texture_meta_data

For example. This means that the SSBO is to be bound at binding point 2

And then on the C++ side one does something like

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, SSBOID);

To bind the object to the binding point.

How can you do the same with textures?

$\endgroup$
2
$\begingroup$

By using the exact same syntax as you did for SSBOs:

layout(binding = 0) uniform sampler2D texture_name;

This is a GL 4.2 feature, so if you can use SSBOs, you can use this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.