Using array format when specifying vertex attributes

I was trying to specify a vertex attribute in vertex shader consisting of an array of 4 floats. Instead of vec4 I tried specifying it as array, float[4]. But I don’t seem to get the correct values with later. Is it not allowed to use array format when specifying vertex attributes?

    layout (location = 5) in float[4] v;

I guess there might be different reasons for this not working properly, just wanted to first check if this is valid in the first place.

You can have arrayed attributes, but each array element acts like its own attribute. So your definition of v declares 4 attributes, with attribute locations 5 to 8. I’m guessing your VAO doesn’t match that.

There’s not much reason to use an array of 4 elements as an attribute, as you can access vectors with [] syntax.

I see, thanks very much! I guess I would have to specify them one by one on CPU side as well, and there’s no shorter way.

glVertexArrayAttribFormat(vao, 5, 1, GL_FLOAT, GL_FALSE, offset1);
glVertexArrayAttribFormat(vao, 6, 1, GL_FLOAT, GL_FALSE, offset2);
glVertexArrayAttribFormat(vao, 7, 1, GL_FLOAT, GL_FALSE, offset3);
glVertexArrayAttribFormat(vao, 8, 1, GL_FLOAT, GL_FALSE, offset4);

The reason I wanted to use array format, was with a macro, ex v[MAX_NUMBER]. The macro can then also be used to iterate through the vector.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.