Multi Texturing 4.5

Hi,

I want to use the new multi texturing features.

glBindTextures(0, textureIDs.size(), textureIDs.data());

It works !

However, I also want to bind the uniforms in a concise manner.

Like this.

uniform sampler2D textures[] ;

Works as well.

But how do I go about bining the uniforms.
The only thing that works is this:

glUniform1i(glGetUniformLocation(shader, “textures[0]”), 0);
glUniform1i(glGetUniformLocation(shader, “textures[1]”), 1);
glUniform1i(glGetUniformLocation(shader, “textures[2]”), 2);
glUniform1i(glGetUniformLocation(shader, “textures[3]”), 3);

Which I find insultingly crude.

The following works for two textures

glUniform1i(glGetUniformLocation(shader, “textures”), 0);
glUniform1i(glGetUniformLocation(shader, “textures”), 1);
glUniform1i(glGetUniformLocation(shader, “textures”), 2);
glUniform1i(glGetUniformLocation(shader, “textures”), 3);

So the question is, is there a nice way, without magic numbers and without bindless to bind textures to a combined sampler array.
Is there a Vulkan like solution im not aware of?

Why not do it in your GLSL code using layout(binding) syntax?

layout(binding = 0) uniform sampler2D texture0;
layout(binding = 1) uniform sampler2D texture1;
layout(binding = 2) uniform sampler2D texture2;
layout(binding = 3) uniform sampler2D texture3;

because I want to have a flexible number of textures.

That needn’t be a constraint.

You can bind fewer textures than you specify in your GLSL; there’s absolutely nothing to prevent that. You can also bind texture name 0 to any texture slot you don’t wish to use.

Yes, however the array solution produces much less text. And the uniform binding can be done in a loop.

I was just wondering if there is some syntactic suger which simplifies the process

Use glUniform1iv.

Binding it to “textures” ? Will try.