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

Author Topic: CircleShape performance  (Read 3560 times)

0 Members and 1 Guest are viewing this topic.

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
CircleShape performance
« on: September 23, 2015, 03:37:45 pm »
I caught some performance issues with CircleShape.
When the total count of circles grows up to 1000 per frame, the performance slows down dramaticaly. When it's count grows up to 2000, I get 5-10 fps... :(
I run profiler and it shows that SFML consumes for about 80% of time in drawing circles...

Could you please suggest any optimization techniques to improve performance?
I added condition to render rectangles instead of circles when it's physical size is lower than 3-4 pixels. It helps very well (fps increased for 1,5 times), but it's not enough. I need more optimizations. Any ideas are welcome.
Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: CircleShape performance
« Reply #1 on: September 23, 2015, 03:39:37 pm »
Reading the official tutorials might come in handy. ;)

Use vertex arrays instead thus reducing the draw calls to one.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: CircleShape performance
« Reply #2 on: September 23, 2015, 04:06:06 pm »
Sorry, could you please give me the link with more details about it?

I forgot to mention that I need to render filled circles with outlines.
I'm using vertices for fast line drawing, but it seems not so useful, because it didn't support line thickness.

I tried to add conditions to change point count for CircleShape depends on circle count, it's size and scale, but it seems like not a trivial task :) 
Maybe someone can help me with algorithm to calculate best point count for a circle shape, which depends on it's physical radius in pixels?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CircleShape performance
« Reply #3 on: September 23, 2015, 04:21:28 pm »
Can't you a circle texture (in which case you'd be able to use a single vertex array)? Or do you need to control the outline color/thickness separately for each circle?
Laurent Gomila - SFML developer

AlexxanderX

  • Full Member
  • ***
  • Posts: 128
    • View Profile
    • AlexanderX
Re: CircleShape performance
« Reply #4 on: September 23, 2015, 05:20:11 pm »
You can also use a fragment shader.
Here you can find my blog and tutorials about SFML - http://alexanderx.net/ (died...) - http://web.archive.org/web/20160110002847/http://alexanderx.net/

mkalex777

  • Full Member
  • ***
  • Posts: 206
    • View Profile
Re: CircleShape performance
« Reply #5 on: September 23, 2015, 11:44:13 pm »
I'm not familiar with shaders and don't understand an idea with using vertex array to render circles. Can you please explain it?  Do you mean that I need to split all circles into triangles manualy? It looks too complicated...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: CircleShape performance
« Reply #6 on: September 24, 2015, 07:37:33 am »
I just meant that you could draw simple sprites, with a texture that contains a circle. Then, you can merge all these sprites to a single vertex array to improve performances. But this removes the ability to control the properties of the circles' outline.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: CircleShape performance
« Reply #7 on: September 24, 2015, 03:37:09 pm »
Every circle with an outline is two draw calls so that's understandable loss of performance.
You could try calculate all circle and outline triangles yourself and then draw it all in one draw call.
Back to C++ gamedev with SFML in May 2023

DarkRoku12

  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: CircleShape performance
« Reply #8 on: September 24, 2015, 08:19:58 pm »
Post a minimal and testable example so we can know better whats really you want to use, like the answer above you can use vertex array, you will gane a SIGNIFICANT boost but you will lose some of "control" properties.

You can add too what really you want to do, if you need to changes somes propertie likes texture, color , thickness , outline etc...
I would like a spanish/latin community...
Problems building for Android? Look here

 

anything