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

Thread: using an integer texture

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2012
    Posts
    26

    using an integer texture

    I need to use a texture(rgba) where each channel can store unsigned integer value from a range <0,7> I set a texture this way:
    Code :
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32UI, screenWidth, screenHeight, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, NULL);
    First I fill a texture with some data. Then when I read a texture I use sampler2D and vec2 as a texture coordinate (<0,1>, <0,1>).
    The following texture function with sampler2D returns float:
    Code :
    float data = texture(mySampler, texCoord).x;
    but I can use that value this way:
    Code :
    if(data == 0)
    {
      //do something
    }
    and it works. I realize that I can improve my code. I try to change GL_RGBA32UI to GL_RGBA16UI but then the program doesn't work
    (RGBA12UI seems to be minimum internal format to store value from a range <0,7> in each channel). Can I use a usampler2D with vec2 as a
    texture coordinate ? What should I change in the above code ?

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Can I use a usampler2D with vec2
    You should be using a usampler2D to read your texture or you will confuse things. To get the data into float format try
    Code :
    ivec4 int_val = texture2D(Texture0, TexCoord0);
    vec4 float_val = vec4(int_val);

    see
    http://www.opengl.org/wiki/GL_EXT_texture_integer

  3. #3
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,031
    You can't use a usampler2D with `texture2D`. That's a pre-GL 3.0 texture accessing function.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    Sorry needed "texture" not "textue2D"

  5. #5
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    887
    Quote Originally Posted by Alfonse Reinheart View Post
    You can't use a usampler2D with `texture2D`.
    Pedantically, yes you can, with EXT_gpu_shader4.

Posting Permissions

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