0
\$\begingroup\$

I can't find information if it is posiible, to bind few texture array objects into shader. Any searches for "array of texture arrays" or "multiple texture arrays" end with how to use texture array object. I'm creating a texture array object in this way:

glGenTextures(1, &array_texture_object_A);
glBindTexture(GL_TEXTURE_2D_ARRAY, array_texture_object_A);
...
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);  //unbind

Texture array object is distinguishable by texture width, height and bits per pixel. When I want to load texture with different size I create anoter texture array object:

glGenTextures(1, &array_texture_object_B);
glBindTexture(GL_TEXTURE_2D_ARRAY, array_texture_object_B);
...
glBindTexture(GL_TEXTURE_2D_ARRAY, 0);  //unbind

And my question is how to bind array_texture_object_A and array_texture_object_B into shader. (For example I have diffuse map in array_texture_object_A and specular map in array_texture_object_B).

For binding function (glBindTexture) first argument - target, has only GL_TEXTURE_2D_ARRAY enum, there is no something like GL_TEXTURE_2D_ARRAY_0, GL_TEXTURE_2D_ARRAY_1 etc. End now I'm stuck at this point.

Many thanks for any help.

\$\endgroup\$
2
\$\begingroup\$

You can use OpenGL's glActiveTexture before binding the texture, which expects one of GL_TEXTURE0, GL_TEXTURE1, etc. values (these are sequential, GL_TEXTURE0 + i is the i-th texture slot)

After you bind a texture, load an integer into the sampler object in the shader. The integer should be equal to the index of the texture slot the textures are in (e.g. with GL_TEXTURE3 you'll need to load in 3)

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thanks a lot! It works, and Your answer was very helpful. \$\endgroup\$ – pio Nov 21 '17 at 22:48

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.