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

Author Topic: Efficiency question: Sprite vs Text  (Read 2312 times)

0 Members and 1 Guest are viewing this topic.

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Efficiency question: Sprite vs Text
« on: June 27, 2016, 08:22:19 pm »
So, I need to draw a lot of text on the screen - an array of sf::Text objects. This text is not going to change very often. So, I thought, why not draw all these sf::Text objects on sf::RenderTexture object and then, when the text updates, just redraw the texture? Will drawing the sf::RenderTexture through a sprite in the main window be more efficient than drawing the text in the same window?
What I think is maybe drawing text is more expensive than drawing it once on a texture and then just drawing the texture.
« Last Edit: June 27, 2016, 08:27:32 pm by xqbt »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Efficiency question: Sprite vs Text
« Reply #1 on: June 27, 2016, 08:49:38 pm »
It depends. Since both options are pretty easy to implement, you should just try.
Laurent Gomila - SFML developer

xqbt

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Efficiency question: Sprite vs Text
« Reply #2 on: June 27, 2016, 10:59:59 pm »
Laurent, thanks for advice. I ran some tests, for anyone interested, here are the results.
1)
  • Rendering 500 heavily overlapping text objects directly gained ~170 fps
  • Rendering through sf::RenderTexture (without redrawing) gained ~380 fps.
.
2)
  • Rendering 50 non-overlapping text objects directly gained ~470 fps
  • Rendering through sf::RenderTexture (without redrawing) gained ~340 fps.
.
Well, the slowness of the second case with texture can be explained by the size of this texture - 800 * 800.
Anyway, bottom line: predrawing non-overlapping text is faster with plain text objects.

 

anything