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

Author Topic: Final answer for async loading texture ?  (Read 1002 times)

0 Members and 1 Guest are viewing this topic.

Nafffen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Final answer for async loading texture ?
« on: March 25, 2024, 10:20:49 pm »
Hey,
I want to load textures while my application is still running (logic + rendering).
I have been looking for a clear answer and the best I could find was in this topic some years ago :
https://en.sfml-dev.org/forums/index.php?topic=20569.0
It's said it's not recommended. Is it the same in 2024 ?
I don't know much about OpenGL, I have seen topics about internal/external context but not really a clear answer.
What are the best practices ?
Thank you

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: Final answer for async loading texture ?
« Reply #1 on: March 27, 2024, 08:16:09 am »
Yes, OpenGL didn't change. ;D

The recommended way is to load the image data with sf::Image or similar from disk in a separate thread, which is one of the slowest parts, as you do IO and decompression, and then move the image data to a texture in the main thread.
This should speed up things noticeably.

And of course making sure you generally use texture atlases withe texture rect on a sprite, instead of loading many small textures. This will prevent you from having to load and handle many textures and will reduce texture switches, that are a bit expensive.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nafffen

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Final answer for async loading texture ?
« Reply #2 on: March 27, 2024, 11:14:23 am »
Perfect ! Thank you