Reputation: 24111
I want to render two objects in OpenGL using shaders.
To render my first object, I create a vertex buffer using glGenBuffers()
, then fill the vertex buffer with data using glBufferData()
, and finally draw the vertex buffer using glDrawArrays()
.
Now, to draw my second object, there are two methods I can think of. First, I could append all the vertices of my second object to the vertex buffer created above, and then draw all the vertices of both objects using one call to glDrawArrays()
. Alternatively, I could create a second vertex buffer, fill that with data from the second object, and call glDrawArrays()
a second time for that second object.
Which is the best method? The second method allows me keep the rendering of each object independent, which might make the code easier to follow, but it also might be slower at runtime...
Upvotes: 1
Views: 748
Reputation: 870
If you can combine multiple objects into 1 draw call, its always a good idea to do so because it means less calls to opengl and it will be faster. One problem is that when your objects need different transformation matrices, different shaders, etc, it will a little more complicated.
Upvotes: 1