Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Multiple question about texture image units

  1. #1
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    70

    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.

    1)
    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?)

    2)
    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?

    3)
    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.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,135
    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.

  3. #3
    Intern Contributor
    Join Date
    Sep 2013
    Posts
    70
    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.

  4. #4
    Intern Contributor
    Join Date
    Nov 2011
    Posts
    50
    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:
    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
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture0);
    glBindSampler(0, samplerObj[1]);
      //during rendering object 2
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, texture0);
    glBindSampler(0, samplerObj[0]);

    2) 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: http://www.opengl.org/discussion_boa...43#post1257143

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •