Reputation: 4155
I understand it is possible to set per-instance attributes when drawing with glDrawArraysInstanced
and friends, so I was wondering if it's also possible to set an attribute once (i.e. per instance) for all vertices generated by glDrawArrays
instead of setting them individually for each vertex?
Upvotes: 0
Views: 201
Reputation: 54592
Certainly. For example if your attribute is a vec4
, and the attribute location is attrLoc
, you can use one of the following to set an attribute value that applies to the whole draw call:
glVertexAttrib4f(attrLoc, 1.0f, 2.0f, 3.0f, 4.0f);
glDrawArrays(...);
GLfloat attrVal[4] = {1.0f, 2.0f, 3.0f, 4.0f};
glVertexAttrib4fv(attrLoc, attrVal);
glDrawArrays(...);
There are equivalent calls for vectors with 1, 2, and 3 members.
Upvotes: 4