Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawing meshes are slow. #264

Open
fossegutten opened this issue May 11, 2021 · 2 comments
Open

Drawing meshes are slow. #264

fossegutten opened this issue May 11, 2021 · 2 comments
Labels
Type: Feature Request Improvements that could be made to the code/documentation.

Comments

@fossegutten
Copy link

fossegutten commented May 11, 2021

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

@fossegutten fossegutten added the Type: Feature Request Improvements that could be made to the code/documentation. label May 11, 2021
@17cupsofcoffee
Copy link
Owner

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:

  • Avoid creating new Meshes every frame, if you can avoid it (e.g. for static geometry).
  • Try to put multiple shapes in the same Mesh, if they don't move relative to each other.
  • If you're just drawing lots of rectangles, consider just using the solid Texture approach instead, so you can take advantage of sprite batching.

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:

  • Better docs/examples.
  • It'd be nice to have a way of doing batched shape drawing - this would require some changes to the batcher though, as it only currently supports quads.
  • Drawing filled rectangles through Mesh/GeometryBuilder is much slower than it needs to be at the moment, I think I can make a fast path for this.
  • I may add support for instanced rendering.

@17cupsofcoffee
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Request Improvements that could be made to the code/documentation.
Projects
None yet
Development

No branches or pull requests

2 participants