0
$\begingroup$

I am trying to pass a vec3 array from vertex shader to tessellation shader.

passing just one value works fine, but how to pass an array?

Vertex shader

#version 430
out vec3 data; //working!
out vec3 dataArray[2];
void main()
{
    gl_position = vec4(0,0,0,0);
    data = vec3(1,2,3);
    dataArray[0] = vec3(1,2,3);
    dataArray[1] = vec3(4,5,6);
}

tessellation controll shader

#version 430
layout (vertices = 3) out;

in vec3 data[]; //working!
in vec3 dataArray[2][]; // how to do this?

void main()
{
    ...
}

The error message is: error C7618: OpenGL/ES does not allow input array declarations with size not equal to gl_MaxPatchVertices

I also tried

in vec3 dataArray[2][gl_MaxPatchVertices]

But this also doesn't work.

$\endgroup$
1
  • $\begingroup$ how can I get the value of gl_MaxPatchVertices? $\endgroup$
    – Thomas
    Sep 15 at 8:47
1
$\begingroup$
in vec3 dataArray[2][]; // how to do this?

Arrays of arrays in GLSL work differently than you might expect. The array indices are read left-to-right. For example, vec2 var[2][3] is a 2-element array of 3-element arrays of vec2s.

What you want is an "unsized array of 2 element arrays of vec3". To do that, you need in vec3 dataArray[][2];.

Alternatively, you can declare the main type next to the type name and the array aggregation beside the variable name: in vec3[2] dataArray[];. GLSL allows this kind of split declaration style, where the array sizes on the type happen before the array sizes on the variable.

$\endgroup$
1
$\begingroup$

Change the output of the vertex shader to

out vec3[2] dataArray;

and the input to the tessellation control shader as

in vec3[2] dataArray[];

That should work. Alternatively you could also define the type of dataArray as a struct.

$\endgroup$
1
  • $\begingroup$ The answer of Nicol Bolas is more detailed, so I will accept his answer. But I am going to use the arrays like you describe "in vec3[2] dataArray[];". +1 $\endgroup$
    – Thomas
    Sep 16 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.