Sign in to follow this  

TEXTURE_1D as Integer lookup table in shader?

This topic is 2790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I have two integer arrays (one 256 vales, the other 256*3 values) and instead of hardcoding them in the shader I want to use an isampler1D for each to do some lookups. My idea was to use an 8bit (1 channel, r) texture for the first and a 24bit (3 channel, rgb) for the second array. creating and attaching the textures to the sampler location seems to work fine
  int lookupA_length = 256;
  int lookupA[lookupA_length] = {.....};
  glBindTexture(GL_TEXTURE_1D, texId);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexImage1D(GL_TEXTURE_1D, 0, GL_R, lookupA_length, 0, GL_R, GL_INT, lookupA);

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_1D, texId);
  int texUniform = glGetUniformLocation(programId, "lookupA");
  glUniform1i(texUniform, 0);

In the shader the sampler is declared as isampler1D and in my understanding I can use texelFetch(lookupA, i, 0).r to get the direct integer value of the lookupA sampler at position i (single channel texture, return value is an ivec4 so the .r to get the right channel). But it doesn't work ... texelFetch always returns 0 ... Any ideas or suggestions? (GLSL 1.5, GL 3.2 forward compatible context, ATI HD4850, Linux 32bit)

Share this post


Link to post
Share on other sites
If you use a isampler1D, your texture must have a compatible internal format, such as GL_R8I, GL_RG8I, etc. Change GL_R to GL_R8I and it should work.

Share this post


Link to post
Share on other sites
I dug into the 3.2 core spec and the 3.2 quick reference card and changed (according to the case) both format and internalformat.

for the single channel array:
internal = GL_R8I, format = GL_RED_INTEGER

for the 3 channel array:
internal = GL_RGB24I, format = GL_RGB_INTEGER

but that changed nothing, outputs from texelFetch still 0 no matter what.

maybe my usage of texelFetch is wrong here ...

Share this post


Link to post
Share on other sites

This topic is 2790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this