SFML community forums

Help => Graphics => Topic started by: Phanoo on February 21, 2018, 10:27:08 am

Title: Batching sf::Text draw calls ?
Post by: Phanoo on February 21, 2018, 10:27:08 am
Hello

I've noticed the draw() function is very expensive due du driver things, I've already batched my sf::Shapes for great performance improvements, now I'm looking for batching sf::Text drawings since I have lots of them but I'm not sure how to do that.
Do you have ideas ? Is there a way to get the glyph Texture and all rects that represents the Text so I can put them in a single VertexArray ?
Title: Re: Batching sf::Text draw calls ?
Post by: Laurent on February 21, 2018, 11:45:57 am
This is currently not possible. An alternative way would be to pre-render your texts to one or more sf::RenderTexture and draw them with sprites or vertex arrays.
Title: Re: Batching sf::Text draw calls ?
Post by: Phanoo on February 21, 2018, 11:51:20 am
Ok thanks :) I'll think a bit to see if it's worth to do something about that.

Can you tell me if this is an improvement to draw all text (using the same font and charsize) in the same place, instead of switching between draw types ?

eg:
- draw(text1)
- draw(text2)
- draw(text3)
- draw(a sprite)
- draw(a sprite)
- draw(a sprite)

VS

- draw(text1)
- draw(a sprite)
- draw(text2)
- draw(a sprite)
- draw(text3)
- draw(a sprite)
Title: Re: Batching sf::Text draw calls ?
Post by: Laurent on February 21, 2018, 12:40:19 pm
Definitely, texture switching is an expensive operation.
Title: Re: Batching sf::Text draw calls ?
Post by: Phanoo on February 21, 2018, 06:16:07 pm
Oh i see. And what about Shapes ? Do they force a texture switching too ?

- draw(text1)
- draw(a shape)
- draw(text2)
- draw(a shape)
- draw(text3)
- draw(a shape)

I'm using mostly Text and Shapes in my app, not much sprites.
Title: Re: Batching sf::Text draw calls ?
Post by: Laurent on February 21, 2018, 06:29:13 pm
Nothing "forces" texture switching, it simply happens when you draw things that use different textures. Since it is unlikely that your shapes use the same textures as your text, then yes, a switch will happen for each call to draw in your example.

In the end you should base your decisions on actual testing, never rely on some generic rules, things are really more complicated with so many things involved (your code, compiler, OS, graphics card, driver, ...).
Title: Re: Batching sf::Text draw calls ?
Post by: Phanoo on February 21, 2018, 06:46:59 pm
Thank you for your help, yeah i'm going to do dome testing. Most of my shapes doesn't use any texture, they are plain color