title: Shader doesn't write anything for picking by id
body: <p>I am trying to implement picking by an int id, but it looks like my shader doesn't write anything, althought I can read the clear color properly.</p>
  
  <p>vs, I skipped completely any matrix for debugging:</p>
  
  <pre><code>#version 330
  
  #include semantic.glsl
  
  layout (location = POSITION) in vec3 position;
  
  uniform Transform0
  {
      mat4 view;
      mat4 proj;
      mat4 viewProj;
  };
  
  uniform Transform1
  {
      mat4[TRANSFORM1_SIZE] models;
  };
  
  uniform Parameters
  {
      // x = mesh baseVertex
      // y = selected
      // z = active
      // w = id
      ivec4[INDICES_SIZE] params;
  };
  
  out Block
  {
      flat int id;
  } outBlock;
  
  int getIndex()
  {
      int iBegin = 0;
      int iEnd = params.length() - 1;
  
      int l = iBegin;
      int r = iEnd;
  
      int i = 0; 
  
      if(params.length &gt; 1)
      {
          do 
          {
              i = int(((l + r) / 2.0f));
  
              if (l == (r - 1)) 
                  if (l == 0 &amp;&amp; gl_VertexID &lt;= params[l].x || gl_VertexID &lt;= params[l].x &amp;&amp; gl_VertexID &gt; params[l - 1].x)
                      return l;
                  else if(gl_VertexID &gt; params[l].x &amp;&amp; gl_VertexID &lt;= params[r].x)
                      return r;
                  else 
                      return 0;
              else if (gl_VertexID == params[i].x) 
                  return i;
              else if (gl_VertexID &lt; params[i].x) 
                  r = i;
              else if (gl_VertexID &gt; params[i].x)
                  l = i;
          } while (l &lt; r);
      }    
      return 0;    
  }
  
  void main() 
  {
      int index = getIndex();
  
      mat4 model = models[index];
  
      //gl_Position = proj * (view * (model * vec4(position, 1)));
  
      gl_Position = vec4(4.0 * float(gl_VertexID % 2) - 1.0, 4.0 * float(gl_VertexID / 2) - 1.0, 0.0, 1.0);
  
      outBlock.id = params[index].w;
  }
  </code></pre>
  
  <p>fs, hardcoded value for the moment, output is 0 (<code>FRAG_COLOR</code>), tried also 1 but nothing:</p>
  
  <pre><code>#version 330
  
  #include semantic.glsl
  
  // Outgoing final color.
  layout (location = FRAG_COLOR) out int outputColor;
  
  in Block
  {
      flat int id;
  } inBlock;
  
  void main() 
  {    
      //outputColor = inBlock.id;
      outputColor = 9;
  }
  </code></pre>
  
  <p>Init phase, I have one fbo, called <code>RESOLVE</code>, with 3 attachements, one depth, one float color on 0 and one integer for picking on 1. Fbo is complete:</p>
  
  <pre><code>gl3.glBindTexture(GL_TEXTURE_2D, textureName.get(Texture.RESOLVE_ID));
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  gl3.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  gl3.glTexImage2D(GL_TEXTURE_2D, 0, GL_R32I, EC.viewer.size.x, EC.viewer.size.y, 0, GL_RED_INTEGER, GL_INT, null);
  
  gl3.glGenFramebuffers(Framebuffer.MAX - (samples == 1 ? 1 : 0), framebufferName);
  
  gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
  gl3.glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureName.get(Texture.RESOLVE_DEPTH), 0);
  gl3.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureName.get(Texture.RESOLVE_COLOR), 0);
  gl3.glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, textureName.get(Texture.RESOLVE_ID), 0);
  
  if (gl3.glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
      System.err.println("incomplete");
      return false;
  }
  </code></pre>
  
  <p>and render &amp; reading, added also <code>glFlush</code>, <code>glFinish</code> and <code>glPixelStorei</code> but nothing:</p>
  
  <pre><code>gl3.glBindFramebuffer(GL_FRAMEBUFFER, framebufferName.get(Framebuffer.RESOLVE));
  gl3.glDrawBuffer(GL_COLOR_ATTACHMENT1);
  gl3.glClearBufferiv(GL_COLOR, 0, clearId.put(0, 0)); // we care clearing only red
  
  gl3.glBindVertexArray(EC.meshManager.vertexArrayName.get(0));
  
  gl3.glEnable(GL_DEPTH_TEST);
  
  gl3.glUseProgram(program.name);
  
  gl3.glDrawElements(GL_TRIANGLES, EC_Gl3MeshManager.ELEMENT_OPAQUE_COUNT, GL_UNSIGNED_INT, 0);
  
  gl3.glDisable(GL_DEPTH_TEST);
  
  gl3.glReadBuffer(GL_COLOR_ATTACHMENT1);
  
  glm.vec._2.i.Vec2i window = new glm.vec._2.i.Vec2i(
              EC.inputListener.mousePressed.getX(),
              EC.viewer.size.y - EC.inputListener.mousePressed.getY() - 1);
  System.out.println("window (" + window.x + ", " + window.y + ")");
  
  gl3.glFlush();
  gl3.glFinish();
  gl3.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  
  //  Get the red coordinate reading the pixel click from the color 1 buffer, we can use the clearId buffer        
  gl3.glReadPixels(window.x, window.y, 1, 1, GL_RED_INTEGER, GL_INT, clearId);
  gl3.glReadBuffer(GL_COLOR_ATTACHMENT0);
  </code></pre>
  
  <p>As I said, if I clear with 10, I read 10, so that is working, the <em>only</em> problematic thing is my shader..</p>
  
  <p>Can you spot the error, guys?</p>
  
  <p>Edit: trying to debug, I am checking the attachment type on color 1</p>
  
  <pre><code>gl3.glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
          GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, clearId);
  System.out.println("GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: " + clearId.get(0));
  gl3.glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1,
          GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, clearId);
  System.out.println("GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: " + clearId.get(0)+", tex: "+textureName.get(Texture.RESOLVE_ID));
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: 5890
  GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: 14, tex: 14
  </code></pre>
  
  <p>5890 is <code>GL_TEXTURE</code>, name looks correct</p>
  
  <p>tried to use <code>glFramebufferTexture2D</code>, but I still get <code>GL_TEXTURE</code> type instead <code>GL_TEXTURE_2D</code></p>
  
  <p>Edit 2: trying to read the depth component, is always 0</p>