0

When using layout(points) in in geometry shader, I can simply forward the data through the vertex shader by suppling gl_Position with a vec4:

// Vertex Shader
in vec2 position;

void main()
{
    gl_Position = vec4(position, 0.0, 1.0);
}

// cpp file
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW);

GLint posAttrib = glGetAttribLocation(shaderProgram, "position");
glEnableVertexAttribArray(posAttrib);
glVertexAttribPointer(posAttrib, 2, GL_FLOAT, GL_FALSE, 0, 0);

And then I can access it with gl_in[0].gl_Position in geometry shader.

But what if I wanted to instead take input into the geometry shader using layout(lines) in? Could this be done by forwarding values through vertex shader or is there another way?

In short: How would one provide line data to the geometry shader so that it can be accessed using gl_in[0].gl_Position and gl_in[1].gl_Position?

Scraph
  • 175
  • 6
  • 1
    I'm not sure you understand how the Geometry Shader works. It gets an input array of vertices from vertex shader invocation(s) and can access up to n-many vertices at a time depending on the primitive type. For a line, n would be 2, for line-adjacencey n would be 4. The vertex shader is evaluated at least once for each of those vertices before the GS runs. – Andon M. Coleman Oct 09 '14 at 04:10
  • @AndonM.Coleman So the geometry shader will invoke on every two vertex invocations? Does that mean that my list of points is used as data for the lines? – Scraph Oct 09 '14 at 04:22
  • Do you mean `GL_ELEMENT_ARRAY_BUFFER`? If so, then yes. Those vertices in-order will be the input to your geometry shader. *Keep in mind there is a transform cache, so if you share vertices in your lines like 0,1,2,1,2,0 the vertex shader might only run 3 times (later invocations of the GS will use the cached output for vertices 1,2,0).* – Andon M. Coleman Oct 09 '14 at 04:28
  • @AndonM.Coleman Thank you! This information was helpful! – Scraph Oct 09 '14 at 04:43

0 Answers0