Multiple question about texture image units

Hi there.

Until now I have only ever bound my textures to the texture image unit 0.
Now I want to broaden my horizon; but there are still a few questions which neither the reference pages nor google searches have answered yet.
Furthermore, there are a few things I am not 100% sure I understood correctly.

Can I bind the same texture to several texture image units at the same time?
(And if I can, does that make any sense at all?)

If I bind each texture to different image units, can I then draw geometry using all those textures without having to switch them out?
That is, would it work just like using Array Textures?

If I am still working with the fixed-functionality pipeline, without any shaders of my own, can I still render using textures from any other texture image unit then 0?
(And if yes, what function do I need to use?)

Thats it for now,
I would appreciate your help on this. Thank you very much.

1 - Yes, you can. It would make sense if you wanted to sample them differently, e.g wrap mode on unit 0 but repeat mode on unit 1. Also with different LODs, filter modes, etc. Fixed pipeline OpenGL doesn’t really allow this however as you need sampler objects also bound to the units (some implementations may work).

2 - I’m not entirely sure what you mean by this. Do you mean binding all textures you’re going to use to different units once-only then drawing without using any glBindTexture calls at runtime? Or something else?

3 - Yes, you can, but you need to set up your texture environment (via glTexEnv calls) correctly so that they’ll blend between the different units as you desire. It also depends on what calls you’re using to draw - it can be glMultiTexCoord if you’re using glBegin/glEnd, or glClientActiveTexture/glTexCoordPointer if using vertex arrays/buffer objects.

  1. Okay, that makes sense. Completely understood.

  2. Yes, exactly. I bind each texture to a different texture unit once. Then, I never have to unbind/bind a texture again as long as I am not having too many textures in my application.
    Is that possible?

  3. Ah, thank you. I should have noticed those 2 functions, but for some reason, I just didnt see them.

Thank you very much.

I have another question:
What is the difference between:

Thank you very much.

  1. In an OpenGL 3.3+ environment you can use SamplerObjects and bind one or many of these to a single Texture. In this way you upload just one Texture and you can decide how to sample (in other words set usual filters like WRAP_S, MAX_LOD, etc…) it with one SamplerObject whenever you want.

Pseudo code:

uint samplerObj[2];

  //creation and initialization
glGenSamplers(1, &samplerObj);
  //first sampler
glSamplerParameteri(samplerObj[0], GL_TEXTURE_WRAP_S, GL_REPEAT);
glSamplerParameterf(samplerObj[0], GL_TEXTURE_MIN_LOD, 0.0);
...and so on...
  //second sampler
glSamplerParameteri(samplerObj[1], GL_TEXTURE_WRAP_S, GL_CLAMP);
glSamplerParameterf(samplerObj[1], GL_TEXTURE_MIN_LOD, 9.0);
...and so on...

  //during rendering object 1
glBindTexture(GL_TEXTURE_2D, texture0);
glBindSampler(0, samplerObj[1]);
  //during rendering object 2
glBindTexture(GL_TEXTURE_2D, texture0);
glBindSampler(0, samplerObj[0]);

  1. You need to let OpenGL knows what textures to “call”/use for each Channel, so you need to BindTexture() during rendering. In OpenGL 4.4 there is a new function “glBindTextures()” to bind all textures at once, but I think it not works as expected: