PDA

View Full Version : Multi Texturing 4.5



Christoph.LGDV
11-08-2016, 11:12 AM
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?

mhagain
11-08-2016, 11:27 AM
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;

Christoph.LGDV
11-08-2016, 11:39 PM
because I want to have a flexible number of textures.

mhagain
11-09-2016, 02:17 AM
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.

Christoph.LGDV
11-10-2016, 12:24 AM
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

Osbios
11-11-2016, 12:05 AM
Use glUniform1iv.

Christoph.LGDV
11-11-2016, 02:11 AM
Use glUniform1iv.

Binding it to "textures" ? Will try.