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.


1 Answer 1


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)

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .