Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How should I avoid calling draw every frame?  (Read 2184 times)

0 Members and 1 Guest are viewing this topic.

kepler0

  • Newbie
  • *
  • Posts: 23
    • View Profile
How should I avoid calling draw every frame?
« on: September 09, 2017, 06:02:53 pm »
I've recently found out drawing 6000+ Sprites/Shapes is very heavy on performance, and I require advice on how I should begin handling this.

I intend to have an upwards of 1 million Sprites/Shapes in the future, and this can only worsen as I am actually drawing these 6000 sprites/shapes twice (one for the minimap, one for the main view). Obviously ~12000 draw calls every frame is going to slow down any computer, but I'm interested in how VertexArray handled this issue.

The first, most obvious route to take is chunking, but with the way I have things set up right now, implementing chunking would go against the framework of my program. Are there any other ways I can cut down the unnecessary draw calls per frame, or draw them in a more optimized way?

Thanks.
Zzz

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11016
    • View Profile
    • development blog
    • Email
Re: How should I avoid calling draw every frame?
« Reply #1 on: September 09, 2017, 06:35:09 pm »
A vertex array uses only one draw call per texture, which cuts down on performance due to draw calls being expensive.

If only part is visible you should only upload these vertices and not everything. If your framework isn't set up for, then you may want to change that.

Other potential optimizations, especially maybe for the minimap is, to render the static data to a render texture and use that, instead of redrawing everything.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

kepler0

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: How should I avoid calling draw every frame?
« Reply #2 on: September 09, 2017, 07:16:04 pm »
Thanks for the advice. I've already got it back up to a smooth stable framerate, but I'm still working on it to maintain an acceptable amount of detail, especially since the minimap can be zoomed in and out.
Zzz