Results 1 to 5 of 5

Thread: a question about the sampler data type in shading language

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Posts
    9

    a question about the sampler data type in shading language

    Hi,

    I am a newbie in OpenGL Shading language. May I ask a question about the sampler data type in shading language here?

    The GLESSL spec. says sampler types can only be defined as uniform or function parameters especially in the texture functions.

    For example, in the following fragment shader code snippet.
    uniform sampler2D sampler2d;

    gl_FragColor = texture2D(sampler2d, varCoord);

    And in the c code, the Uniform varible sampler2d is being set like

    glUniform1i(glGetUniformLocation(m_uiProgramObject , "sampler2d"), 0); // Sets the sampler2D variable to the first texture unit

    What does a sampler really mean? Why setting the uniform varible sampler2d to 0 can "Sets the sampler2D variable to the first texture unit"?


    br,

    Mike

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353
    A sampler is the connection between the shader and a texture unit. The value you set using glUniform is the number of the texture unit you want to associate with that sampler variable.

    So if you want a sampler to read from a certain texture, you bind that texture to a texture unit and set the sampler to the number of that texture unit, e.g.:
    Code :
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, uiTex);
    glUniform1i(glGetUniformLocation(uiProgram, "someSampler"), 3);
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Sep 2007
    Posts
    9

    sampler type

    Thank you but what's the difference between a sampler and a normal uniform? Why GLSL texture functions need such kind of sampler type to access texels?


    Quote Originally Posted by Xmas
    A sampler is the connection between the shader and a texture unit. The value you set using glUniform is the number of the texture unit you want to associate with that sampler variable.

    So if you want a sampler to read from a certain texture, you bind that texture to a texture unit and set the sampler to the number of that texture unit, e.g.:
    Code :
    glActiveTexture(GL_TEXTURE3);
    glBindTexture(GL_TEXTURE_2D, uiTex);
    glUniform1i(glGetUniformLocation(uiProgram, "someSampler"), 3);

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: sampler type

    Quote Originally Posted by qqca
    Thank you but what's the difference between a sampler and a normal uniform? Why GLSL texture functions need such kind of sampler type to access texels?
    The GLSL texture functions need to know which texture to read. That information is given using a sampler uniform.

    Samplers are opaque handles to textures. You can't modify them nor get their "value" in some way. The internal details of how a sampler refers to a texture are hidden which allows different ways to implement it in hardware.

    When you set a sampler to 0 using glUniform, it doesn't necessarily follow that the shader hardware actually uses the value 0 anywhere to look up which texture to use.
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  5. #5
    Junior Member
    Join Date
    Sep 2007
    Posts
    9

    Re: sampler type

    "When you set a sampler to 0 using glUniform, it doesn't necessarily follow that the shader hardware actually uses the value 0 anywhere to look up which texture to use.[/quote]

    oh, that's interesting.

    Thank you for your replies.

Similar Threads

  1. Replies: 0
    Last Post: 02-14-2013, 04:23 PM
  2. OpenGL 2.0 Shading Language White Paper, Dave Baldwin
    By pion in forum Developers Coding:Beginner
    Replies: 0
    Last Post: 12-27-2010, 02:57 PM

Posting Permissions

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