title: GLSL UV (vec2) coords Optimised-out
body: <p>I'm writing an application using OpenGL 4.3 and GLSL and I need the shader to do basic UV mapping. The problem is that GLSL compiler seems to be optimising-out  the UV coordinates. I cannot access them from the application side of things.</p>
  
  <p>Vertex shader:</p>
  
  <pre><code>#version 330 core
  
  uniform mat4 projection;
  
  layout (location = 0) in vec4 position;
  layout (location = 1) in vec2 uvCoord;
  
  out vec2 texCoord;
  
  void main(void)
  {
      texCoord = uvCoord;
      gl_Position = position;
  }
  </code></pre>
  
  <p>Vertex shader:</p>
  
  <pre><code>#version 330 core
  
  in vec2 texCoord;
  
  out vec4 color;
  
  uniform sampler2D tex;
  
  void main(void)
  {
      color = texture2D(tex, texCoord);
  }
  </code></pre>
  
  <p>Both the vertex and fragment shader compile and link without errors, but when I call the attributes using the following code:</p>
  
  <pre><code>GLint effectPositionLocation = glGetAttribLocation(effect-&gt;getEffect(), "position");
  GLint effectUVLocation = glGetAttribLocation(effect-&gt;getEffect(), "uvCoord");
  </code></pre>
  
  <p>I get the 0 for the <code>position</code> and -1 for the <code>uvCoord</code>, so I can only assume that the <code>uvCoord</code> has been optimised out even though I am using it to pass it from the vertex shader to the fragment shader. </p>
  
  <p>The result is that the geometry is displayed but only in black, no texture mapping.</p>
  
  <p>I have Written similar applications in Direct3D and HLSL with no problem of attributes being optimised out. I'm thinking that it is something simple that I am forgetting or not doing but have not found out what.</p>