in my program I want to draw many spheres. 1st I create vertices,indices for sphere then bind them to voa/vbo/ibo. After that I create 1000 random model Matrices. Now I have 2 ways to Draw the mesh.
- just loop 1000 times through list of ModelMatrices calling
glDrawElements. Where matrix MVP is computed on CPU and sent to shader like as uniform. - bind all Matrices to additional VBO and send them to shader like as "in"
variable. Then call just once with
glDrawElementsInstanced.
in test program I draw 1000 spheres (around 20milions vertices) When I use 1st method I get around 27FPS while 2nd decrease performance to 19FPS.In theory 2nd method should achieve better performance then 1st.
Here is the code.
- Binding matrices to VBO http://pastebin.com/iX9tUWfY
- Drawing http://pastebin.com/FsSXcnqK http://pastebin.com/8WMrUiu1
- Vertex Shader http://pastebin.com/39m34PZk
I think that the bottleneck is this multiplication in vertex shader (VP * ModelMatrix) ,because it needs to be done for each (vertex in mesh)*1000.
What can be upgraded and what am I doing wrong?