17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
909 stars 63 forks source link

Drawing meshes are slow. #264

Open fossegutten opened 3 years ago

fossegutten commented 3 years ago

Summary: Drawing a mesh multiple times per frame is super slow. Even slower when creating the mesh every frame. (40 fps with 325 rectangles). Creating a complex mesh with many rectangles, using GeometryBuilder every frame, is also slow. (120fps) Creating a complex mesh once and drawing it every frame seems fast. (500 fps). Would it be possible to reach the same speeds from drawing a simple mesh multiple times by batching or some other approach?

Edit: sorry, didn´t read enough docs. I havent tried using one geometrybuilder to create meshes every frame yet

Why is this needed? To be able to write simpler code and still have good performance

17cupsofcoffee commented 3 years ago

Mesh is a pretty thin layer over OpenGL buffers at the moment, so it's kinda easy to shoot yourself in the foot with them performance-wise.

My recommendations for using them efficiently are:

In general, you want to minimize the amount of times you're uploading mesh data to the GPU, and minimize the number of seperate draw calls.

Things I'd like to do to make this easier:

17cupsofcoffee commented 3 years ago

Instancing support is now on the main branch! It's a bit limited at the moment due to the fact you can't make custom buffers (so you're kinda limited to using uniform arrays, which can't be very big), but if you need to render a few copies of a very complex mesh, it'll might give you a performance boost.