Reputation: 23
I got an errro when I using SSBO in an array.
this is my source code in a vertex shader:
#version 430 compatibility
in int aID;
in int bID;
out vec4 vColor;
struct Vertex{
vec4 Position;
vec4 Color;
};
layout(std430) buffer shader_data{
Vertex vertex[];
}mybuffers[4]; // using a fixed size
void main()
{
vColor = mybuffers[bID].vertex[aID].Color; // using bID to locate the ssbo. the error is here
vec4 worldPos = mybuffers[0].vertex[aID].Position;
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
}
And then I got an error when I link the glsl program object.
The error is:
Link Error
0(17) : error C1306: cannot determine type of interface variable. Need to inline function
I don't understand the meaning, need to inline function
Upvotes: 2
Views: 1712
Reputation: 26
GLSL is saying you must resolve at link time the buffer which you're using. Thus if you substitute mybuffers[bID]
by mybuffers[0]
(for example) it would link cleanly.
A solution to this problem is using an explicit if
(since your universe of buffers is small - 4 only):
void main()
{
// explicitly index the buffer so GLSL can see it at link time:
if(bId == 0)
vColor = mybuffers[0].vertex[aID].Color;
else if(bId == 1)
vColor = mybuffers[1].vertex[aID].Color;
else if(bId == 2)
vColor = mybuffers[2].vertex[aID].Color;
else if(bId == 3)
vColor = mybuffers[3].vertex[aID].Color;
vec4 worldPos = mybuffers[0].vertex[aID].Position;
gl_Position = gl_ModelViewProjectionMatrix * worldPos;
}
Upvotes: 1