Neil G
Neil G

Reputation: 33252

How do I pass values to a vertex shader's attribute array in OpenGL?

In my vertex shader, I have

in float data[6];

That means that if I have 100 vertices, I want to pass 600 floats. glVertexAttribPointer only supports sizes up to 4. If I use size 1, then will it automatically pick up the 6 elements?

Upvotes: 3

Views: 1158

Answers (1)

BDL
BDL

Reputation: 22175

An attribute array in glsl is treated as a number of independent attributes with consecutive attribute locations. You'll have to setup the vertex attribute pointer for each them separately.

If you query the location of the first element with idx = glGetAttribLocation(program_index, "data"), then data[1] will have location idx + 1. You can then loop over them and call glVertexAttribPointer* with the index and the correct byte offset for each of the array elements.

Upvotes: 5

Related Questions