Let's say we have a GL program consisting of the following vertex, geometry and fragment shaders.
vertex:
#version 410
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 size;
layout (location = 2) in float rot;
layout (location = 3) in vec4 color;
layout (location = 0) out vec2 p;
layout (location = 1) out vec2 s;
layout (location = 2) out float r;
layout (location = 3) out vec4 c;
void main(){
gl_Position = vec4(pos,0.0,1.0);
p = pos;
s = size;
r = rot;
c = color;
}
geometry:
#version 410
layout (points) in;
layout (triangle_strip, max_vertices = 4) out;
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 size;
layout (location = 2) in float rot;
layout (location = 3) in vec4 color;
layout (location = 0) out vec2 p;
layout (location = 1) out vec2 s;
layout (location = 2) out float r;
layout (location = 3) out vec4 c;
void main()
{
gl_Position = gl_in[0].gl_Position + vec4(-0.2, -0.2, 0.0, 0.0); // 1:bottom-left
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4( 0.2, -0.2, 0.0, 0.0); // 2:bottom-right
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4(-0.2, 0.2, 0.0, 0.0); // 3:top-left
EmitVertex();
gl_Position = gl_in[0].gl_Position + vec4( 0.2, 0.2, 0.0, 0.0); // 4:top-right
EmitVertex();
EndPrimitive();
p = pos;
s = size;
r = rot;
c = color;
}
fragment:
#version 410
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 size;
layout (location = 2) in float rot;
layout (location = 3) in vec4 color;
out vec4 FragColor;
void main()
{
FragColor = color;
}
The program takes points and display them as quads.
What I'm trying to do here is to pass the 4 vertex attributes (pos, size, rot and color) to the fragment shader through the geometry shader.
If I remove the geometry shader from my program, it manages to pass the vertex attributes to the fragment shaders and it displays colored dots.
If I keep the geometry shader and remove the layouts (in and out), it displays black quads.
Am I missing something here?