I have a simple animation with a box and a ball. It works fine but I would like to be sure I am drawing multiple objects the right way and not being stupid/inefficient:
I create and bind VAOs for ball and box, resp. Then in the application program I have code like
glUniform1ui(objectLoc, BALL); // Send object name to shader.
glBindVertexArray(vao[BALL]);
glMultiDrawElements();
to draw the ball and similar for the box.
Relevant parts of the vertex shader are
uniform uint object;
void main(void)
{
if (object == BALL) ...;
if (object == BOX) ...;
}
and there’s a similar switch based on object in the fragment shader for color.
That’s pretty much what I do and with more objects I would add more if-switches.
Am I doing this properly or is there some other cool/efficient way to do things (maybe separate shaders for each object)?
Thanks in advance.