title: in/out variables among shaders in a Pipeline Program
body: <p>I am currently using 3 different shaders (Vertex, Geometry and Fragment), each belonging to a different program, all collected in a single Program Pipeline.</p>
  
  <p>The problem is that the Geometry and Fragment have their in varyings zeroed, that is, they do not contain the value previously written by the preceeding shader in the pipeline.</p>
  
  <p>for each shader:</p>
  
  <pre><code>glCreateShader(...)
  glShadersource(...)
  glCompileShader(...)
  glGetShaderiv(*shd,GL_COMPILE_STATUS,&amp;status)
  </code></pre>
  
  <p>for each program:</p>
  
  <pre><code>program[index] = glCreateProgram()
  glAttachShader(program[index],s[...])
  glProgramParameteri(program[index],GL_PROGRAM_SEPARABLE,GL_TRUE)
  glLinkProgram(program[index])
  glGetProgramiv(program[index],GL_LINK_STATUS,&amp;status)
  </code></pre>
  
  <p>then:</p>
  
  <pre><code>glGenProgramPipelines(1,&amp;pipeline_object)
  </code></pre>
  
  <p>in gl draw:</p>
  
  <pre><code>glBindProgramPipeline(pipeline_object)
  glUseProgramStages(pipeline_object,GL_VERTEX_SHADER_BIT,program[MY_VERTEX_PROGRAM])
  and again for the geometry and fragment programs
  </code></pre>
  
  <p>vertex shader:</p>
  
  <pre><code>#version 330
  
  //modelview and projection mat(s) skipped
  ...
  
  //interface to geometry shader
  out vec3 my_vec;
  out float my_float;
  
  void main() {
      my_vec = vec3(1,2,3);
      my_float = 12.3;
      gl_Position = &lt;whatever&gt;
  }
  </code></pre>
  
  <p>geometry shader:</p>
  
  <pre><code>#version 330
  
  //input/output layouts skipped
  ...
  
  //interface from vertex shader
  in vec3 my_vec[];
  in float my_float[];
  //interface to fragment shader
  out vec3 my_vec_fs;
  out float my_float_fs;
  
  void main() {
      int i;
      for(i=0;i&lt;3;i++) {
          my_vec_fs = my_vec[i];
          my_float_fs = my_float[i];
          EmitVertex();
      }
      EndPrimitive();
  }
  </code></pre>
  
  <p>fragment shader:</p>
  
  <pre><code>#version 330
  
  //interface from geometry
  in vec3 my_vec_fs;
  in float my_float_fs;
  
  void main() {
      here my_vec_fs and my_float_fs come all zeroed
  }
  </code></pre>
  
  <p>Am I missing some crucial step in writing/reading varying between different stages in a program pipeline?</p>
  
  <p><em><strong>UPDATE:</em></strong></p>
  
  <p>I tried with the layout location qualifier just to be sure everyone was 'talking' on the same vector, since the GLSL specs states:</p>
  
  <blockquote>
    <p>layout-qualifier-id location = integer-constant
    Only one argument is accepted. For example, layout(location = 3) in vec4 normal; will establish that the shader input normal is assigned to vector location number 3. For vertex shader inputs, the location specifies the number of the generic vertex attribute from which input values are taken. For inputs of all other shader types, the location specifies a vector number that can be used to match against outputs from a previous shader stage, even if that shader is in a different program object.</p>
  </blockquote>
  
  <p>but adding</p>
  
  <pre><code>layout(location = 3) out vec3 my_vec;
  </code></pre>
  
  <p>does not compile</p>
  
  <p>So I tried to do the same via glBindAttribLocation(), I get <em>no</em> errors, but the behaviour is still unchanged</p>
  
  <p><em><strong>UPDATE 2</em></strong></p>
  
  <p>If I add
     "#extension GL_ARB_separate_shader_objects: enable"</p>
  
  <p>then I can use layout(location = n) in/out var; <strong>and then it works.</strong></p>
  
  <p>found:</p>
  
  <pre><code>GLSL 330: Vertex shaders cannot have output layout qualifiers
  GLSL 420: All shaders allow location output layout qualifiers on output variable declarations
  </code></pre>
  
  <p>This is interesting.. If you declare #version 330 you shouldnt be able to use a layout out qualifier, even if you enable an extension..
  ..but again the extension states:</p>
  
  <blockquote>
    <p>This ARB extension extends the GLSL language's use of layout qualifiers to provide cross-stage interfacing.</p>
  </blockquote>
  
  <p>Now Idlike to know why it does not work using glBindAttribLocation() or just with plain name matches + ARB extension enabled!</p>