0
\$\begingroup\$

I have to draw a lot of cubes in my OpenGL programme for android. All the cubes have the same size but different colors. I know that calling glDrawArrays is expensive operation so I should call it less as possible. But as I know I have to call it 6 times (one per each side) and since I have more than 500 cubes it's not efficient at all. Does anyone have the idea what to do?

Btw, I am using OpenGL ES 1.0.

I saw that I can use one big VBO but I don't know how to do that.

\$\endgroup\$
  • 1
    \$\begingroup\$ 1.) Are you trying to create a voxel game? 2.) Why are you using OpenGL 1? You can achieve better performance with anything above it and they're mostly supported everywhere. \$\endgroup\$ – Bálint Jan 4 '18 at 7:24
1
\$\begingroup\$
  • Use OpenGL ES 2
  • Set each vertex x,y,z and color information to one big VBO
  • Set the color in the fragment shader
  • Use ONE unique call to glDrawArrays
\$\endgroup\$
  • \$\begingroup\$ If the cubes need to be interactive this gets a bit more tricky as you'd have to create draw commands to skip the deactivated cubes. If everything is in one buffer it means that all vertices will always be processed. They will be culled if outside of the device coordinates and not send off to the fragment shader, but you have to consider this as well. Alternatively you could cull objects based on whether they are visible and only pass the visible objects to gpu. A draw call isn't necessarily evil though if states don't change. \$\endgroup\$ – Sidar Jan 4 '18 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.