Ok guys, I think I have a very strange problem.
I have an old laptop, but its HD 6370M currently supports opengl 4.4, so i decided to learn how to use some new features of this platform, so after glVertexAttribFormat, glVertexAttribBinding and so on, I moved to shader storage buffer objects.
I thought they were useful for things like passing light data to shaders, so I tried to make a trivial example working.
the relevant pieces of code in my program are: C++ creation of buffer
struct Values
{
float val;
};
void CreateBuffers()
{
glGenBuffers(1, &ssbo);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
Values v;
v.val = 0.3;
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(Values), &v, GL_STATIC_DRAW);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
}
void Render()
{
...
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, ssbo);
...
}
Then in the fragment shader: GLSL
struct Values
{
float val;
};
layout(std430, binding = 0) buffer ssbo
{
Values vals[];
};
And then in the main I could assign a random color to the output variable and I just see my geometry of that color, as expected:
out vec4 out_color;
void main()
{
out_color = vec4(0.4, 0.3, 0.6, 1); // Yeah, random
}
Or if I output the value of the variable in the ssbo directly everything works just fine (I see a grayish color on my geometry)
out vec4 out_color;
void main()
{
out_color = vec4(vals[0].val);
}
BUT, if I try to get the length of the array with
vals.length();
in any kind of operation, like in a for loop or simply scale the output color by the length of the array, I get a completely white screen, even if the clear color is set to black, and no geometry is visible at all. It is important to say that this only happen if in the ssbo i put an array of structures.
I don't think that's relevant, but I'm using Windows 8.1 and MSVC compiler with VS13.
Thanks in advance.
EDIT: I want to say that no error is generated during runtime, the shaders compile successfully and the program is validated and linked
EDIT 2: Ok, now it seems that there is a linking error on the program where the ssbo is, but the infolog says nothing:
Vertex shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
unexpected error.
fragment link error: INVALID_OPERATION.
unexpected error.
Driver bug?