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

Author Topic: Is drawing to sf::Texture a good idea?  (Read 297 times)

0 Members and 1 Guest are viewing this topic.

StriderPulse599

  • Newbie
  • *
  • Posts: 16
    • View Profile
Is drawing to sf::Texture a good idea?
« on: December 20, 2023, 03:09:21 am »
Currently I'm using a single sf::VertexArray to draw to one window, then modify some vertices before drawing to another window.

Would drawing shared elements to sf::Texture and then drawing over it be a good idea? I know that draw calls are generally expensive, so I wanted to ask first

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Is drawing to sf::Texture a good idea?
« Reply #1 on: December 20, 2023, 10:10:10 pm »
I presume you mean an sf::RenderTexture that you can draw to. This allows you to draw to it and then use it as a texture, then allowing you to draw that texture (such as on each separate window perhaps). However, drawing that texture would still require a draw call but it would be potentially fewer vertices (only need 6 vertices for 1 quad/2 triangles).

If it's very many vertices, it may be worthwhile to render to a texture and then duplicating from the texture but there is some (significant) overhead with a render texture so if drawing the vertices separately doesn't cause any issues, you could consider keeping with that.

In addition, if you are making many draw calls then drawing to a render texture can reduce the number of duplicated draw calls. However, it might be first better to consider ways to reduce draw calls on the original output. If there are a lot already, maybe this is already too many.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10821
    • View Profile
    • development blog
    • Email
Re: Is drawing to sf::Texture a good idea?
« Reply #2 on: December 25, 2023, 09:33:26 pm »
When it comes to performance questions, there are some tips like Hapax gave, but in the end it comes down to the specific situation and then all that counts is to measure and profile. Optimizing something that isn't a bottleneck is usually just wasted time.
Until you run into performance issues, you might just pick whatever solution works best for you.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything