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

Thread: Understanding of textures

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2017
    Posts
    6

    Understanding of textures

    Let's say I've three different texture objects with different image data on them. These three texture objects are all bound to texture unit 0.

    I've three models in my scene and each uses one of these textures.

    In my fragment shader I've a sampler2D variable. And all models use the same shader program for rendering.

    Now I do the following operations in sequence

    1. Bind texture object 1
    2. Render model 1

    3. Bind texture object 2
    4. Render model 2

    5. Bind texture object 3
    6. Render model 3

    What is want to ask is this the way you texture different models with different textures and does the sampler in fragment shader reads data from currently bound texture. What happens if a texture is bound to a different texture unit, do I need a different sampler for that.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,409
    Quote Originally Posted by jitendra2896 View Post
    What is want to ask is this the way you texture different models with different textures and does the sampler in fragment shader reads data from currently bound texture. What happens if a texture is bound to a different texture unit, do I need a different sampler for that.
    Sampler uniforms are associated with texture units by using glUniform1i() to assign the texture unit number to the uniform.

    You can either bind each texture to a different texture unit, and modify the uniform to refer to the appropriate texture unit before each draw call, or use a single texture unit, binding the appropriate texture to it.

    If you need to use multiple textures within a single draw call, you can use an array of samplers; however, expressions used to index the array must be dynamically-uniform, i.e. involving only uniform variables or (in the the fragment shader) flat-qualified inputs, and all samplers in the array must be of the same basic type (e.g. sampler2D, usampler2D, samplerCube, etc).

    Alternatively, you can use array textures (sampler2DArray etc); these don't have the dynamically-uniform restriction, but the layers of an array must have the same type and dimensions, and sampling parameters (filters, wrap mode) are set the entire texture rather than individual layers.

Tags for this Thread

Posting Permissions

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