1
\$\begingroup\$

This OpenGL documentation article says you can bind 4 (=several) textures to texture units 0, 1, etc. This OpenGL documentation article too.
I found in this Stack Overflow answer an example of why it could be useful to use several texture units (each bound to a different texture).
However I do not understand in which case one would need to bind several textures to the same texture unit, and how one could use them then.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ That doesn't say what you think it says. From what you quoted: textures to texture units 0, 1,. That is saying that you can bind up to four textures using the texture units 0-3 (at a minimum; more may be supported by a specific implementation). Each texture unit can have only a single texture bound to it at a time. \$\endgroup\$ – Sean Middleditch Sep 20 '13 at 2:11
  • \$\begingroup\$ The article on the second link says: You can bind multiple textures to the same texture image unit. \$\endgroup\$ – wip Sep 20 '13 at 5:58
  • \$\begingroup\$ You aren't really, though. Notice that article is binding different kinds of textures. The GL specification has a separate value for a 2D and a 3D texture bound to its abstract texture unit slot concept. At a hardware level, there's only one or the other at a time. The second article you linked explains all if you read it. \$\endgroup\$ – Sean Middleditch Sep 20 '13 at 6:08
3
\$\begingroup\$

Binding multiple textures to the same texture unit doesn't mean using them at the same time, you can only have one texture image active at time for each unit ( and in your second link, it clearly states that his is where the spec clearly states that you can only sample 1 of those textures.), so why would anyone bind multiple textures?

The answer lies when you really want to render multiple objects with different shaders and/or textures, a simple scenario would be you have basic diffuse shader that will use use with to multiple objects, the shader needs the diffuse map to be bound at texture unit0.

  1. Activate your shader.
  2. for each object bind the needed texture using glBindTexture with TextureUnit0 still active.
  3. Render your actual object.

Please note that might not be the best way for rendering multiple shaders and multiple objects, but it's a valid simple scenario when you need to bind more than one image to the same texture unit, also note that binding different textures with different dimensions to the same unit will result in the higher dimension taking the priority to be sampled (3D > 2D > 1D).

\$\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.