SFML community forums
Help => Graphics => Topic started 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 ?
-
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.
-
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)
-
Definitely, texture switching is an expensive operation.
-
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.
-
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, ...).
-
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