title: Why is texelFetch always returning 0 for a 1D single channel texture?
body: <p>I'm using a 1D texture to store single-channel integer data which needs to be accessed by the fragment shader. Coming from the application, the integer data type is GLubyte and needs to be accessed as an unsigned integer in the shader. Here is how the texture is created (note that there are other texture units being bound after, which I'm hoping are unrelated to the problem):</p>
  
  <pre><code>GLuint mTexture[2];
  std::vector&lt;GLubyte&gt; data;
  ///... populate with 289 elements, all with value of 1
  
  glActiveTexture(GL_TEXTURE0);
  {
      glGenTextures(1, &amp;mTexture[0]);
      glBindTexture(GL_TEXTURE_1D, mTexture[0]);
      {
          glTexImage1D(GL_TEXTURE_1D, 0, GL_R8UI, data.size(), 0,
                       GL_RED_INTEGER, GL_UNSIGNED_BYTE, &amp;data[0]);
      }
      glBindTexture(GL_TEXTURE_1D, 0);
  }
  
  glActiveTexture(GL_TEXTURE1);
  {
      //Setup the other texture using mTexture[1]
  }
  </code></pre>
  
  <p>The fragment shader looks like this:</p>
  
  <pre><code>#version 420 core
  
  smooth in vec2 tc;
  out vec4 color;
  
  layout (binding = 0) uniform usampler1D buffer;
  layout (binding = 1) uniform sampler2DArray sampler;
  uniform float spacing;
  
  void main()
  {
      vec3 pos;
      pos.x = tc.x;
      pos.y = tc.y;
  
      if (texelFetch(buffer, 0, 0).r == 1)
          pos.z = 3.0;
      else
          pos.z = 0.0;
  
  
      color = texture(sampler, pos);
  }
  </code></pre>
  
  <p>The value returned from texelFetch in this example basicaly dictates which texture layer to use from the 2D array for the final output color. I want it to return the value 1, but it always returns 0 and hits the else clause in the fragment shader. Using NVIDIA's Nsight tool, I can see the texture does contain the value 1, 289 times:</p>