OpenGL basics: calling glDrawElements once per object

a 夏天 提交于 2019-12-06 01:35:24

Basically, as you're looping through data once per frame, you're probably starting to hit Python's performance limits. It's probable that if you rewrote your code in, say, C you'd have much better performance.

Anyway, to increase performance in OpenGL, independently of the language, you have to limit the number of draw calls (calls to glDrawElements), to limit the CPU usage and improve the communication between CPU and GPU.

Depending of your target, you have multiple options to speed up your test :

  • if all your cubes are to remain static, you could combine their geometries into a single VBO, by pretransforming the vertices, and issue a single draw call for all your cubes.

  • if all your cubes are to be animated independently, you could use hardware instancing (if your hardware allows it), or pseudo-hardware instancing, you can find some pointers here. Using these techniques, you basically can draw multiple cubes with a single draw call, it's then up to the shader to fetch the cube position according its primitive id.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!