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

Author Topic: Batching sf::Text draw calls ?  (Read 3598 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Batching sf::Text draw calls ?
« 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 ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Batching sf::Text draw calls ?
« Reply #1 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.
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Batching sf::Text draw calls ?
« Reply #2 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)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Batching sf::Text draw calls ?
« Reply #3 on: February 21, 2018, 12:40:19 pm »
Definitely, texture switching is an expensive operation.
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Batching sf::Text draw calls ?
« Reply #4 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Batching sf::Text draw calls ?
« Reply #5 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, ...).
Laurent Gomila - SFML developer

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Batching sf::Text draw calls ?
« Reply #6 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

 

anything