Can you pass an array of vec2's to a geometry shader as input? If so what is the syntax?
1 Answers
Arrays of arrays in GLSL are read left to right. vec2[3][6]
is read as "an array of 3 elements, where each element is an array of 6 elements, where each element is a vec2
."
GS inputs are arrayed; each element represents a single output from the preceding shader stage. The fact that the "single output" may actually be an array type is irrelevant.
So if you're using input/output variables that are not in interface blocks, this would look like this:
//Vertex Shader
out vec2[6] someVariable;
//Geometry Shader
in vec2[][6] someVariable;
The first index is the vertex index.
Note that this may require GLSL 4.30 or the ARB_arrays_of_arrays.
If you use interface blocks to pass data, then the array goes on the instance name of the interface block itself:
//Vertex Shader
out SomeName
{
vec2[6] someVariable;
};
//Geometry Shader
in SomeName
{
vec2[6] someVariable;
} instanceName[];
Since the block has an instance name, you would refer to it in GLSL as instanceName[index].someVariable
.
This can be done in OpenGL 3.2.

- 449,505
- 63
- 781
- 982