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 7 of 7

Thread: Multi Texturing 4.5

  1. #1

    Multi Texturing 4.5

    Hi,

    I want to use the new multi texturing features.


    glBindTextures(0, textureIDs.size(), textureIDs.data());

    It works !

    However, I also want to bind the uniforms in a concise manner.

    Like this.


    uniform sampler2D textures[] ;

    Works as well.

    But how do I go about bining the uniforms.
    The only thing that works is this:


    glUniform1i(glGetUniformLocation(shader, "textures[0]"), 0);
    glUniform1i(glGetUniformLocation(shader, "textures[1]"), 1);
    glUniform1i(glGetUniformLocation(shader, "textures[2]"), 2);
    glUniform1i(glGetUniformLocation(shader, "textures[3]"), 3);

    Which I find insultingly crude.

    The following works for two textures

    glUniform1i(glGetUniformLocation(shader, "textures"), 0);
    glUniform1i(glGetUniformLocation(shader, "textures"), 1);
    glUniform1i(glGetUniformLocation(shader, "textures"), 2);
    glUniform1i(glGetUniformLocation(shader, "textures"), 3);


    So the question is, is there a nice way, without magic numbers and without bindless to bind textures to a combined sampler array.
    Is there a Vulkan like solution im not aware of?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Why not do it in your GLSL code using layout(binding) syntax?
    Code :
    layout(binding = 0) uniform sampler2D texture0;
    layout(binding = 1) uniform sampler2D texture1;
    layout(binding = 2) uniform sampler2D texture2;
    layout(binding = 3) uniform sampler2D texture3;
    Last edited by mhagain; 11-09-2016 at 01:14 AM.

  3. #3
    because I want to have a flexible number of textures.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Quote Originally Posted by Christoph.LGDV View Post
    because I want to have a flexible number of textures.
    That needn't be a constraint.

    You can bind fewer textures than you specify in your GLSL; there's absolutely nothing to prevent that. You can also bind texture name 0 to any texture slot you don't wish to use.

  5. #5
    Yes, however the array solution produces much less text. And the uniform binding can be done in a loop.

    I was just wondering if there is some syntactic suger which simplifies the process

  6. #6
    Junior Member Regular Contributor
    Join Date
    May 2013
    Posts
    138
    Use glUniform1iv.

  7. #7
    Quote Originally Posted by Osbios View Post
    Use glUniform1iv.
    Binding it to "textures" ? Will try.

Posting Permissions

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