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

Author Topic: Multithreading texture loading and drawing  (Read 1536 times)

0 Members and 1 Guest are viewing this topic.


  • Newbie
  • *
  • Posts: 49
    • View Profile
Multithreading texture loading and drawing
« on: July 16, 2016, 04:13:47 am »
Hi, I was wondering if it would be possible to load a texture in one thread, while another thread continues to draw. I'm noticing that if I try to load textures above 1mb, this can start causing lag up to roughly 200ms causing fps drops in drawing, and was wondering if this could be mitigated by using multiple threads.


  • Full Member
  • ***
  • Posts: 203
  • Lua coder.
    • View Profile
    • Email
Re: Multithreading texture loading and drawing
« Reply #1 on: July 16, 2016, 05:58:44 am »
SFML master should not.

But if i remember well, Binary1248 developed a branch with less internal openGL contexts and can be used to load openGL resources from differents threads.

But you should notice that its not performance wise to load those images.

If you really need to load this kind of "heavy" files, you can use a "loading phase" and pre-load all heavy files and only destroy then when the program finished. Every time you need to use it you only need to pass the sf::Texture that is already loaded.

« Last Edit: July 16, 2016, 06:10:38 am by DarkRoku »
I would like a spanish/latin community...
Problems building for Android? Look here


  • SFML Team
  • Hero Member
  • *****
  • Posts: 877
    • View Profile
Re: Multithreading texture loading and drawing
« Reply #2 on: July 16, 2016, 09:13:52 am »
You shouldn't have to (re-)load assets that often. Write your own resource manager (or pick one of the many being available) that will handle this for you so you only load textures and other heavy resources only once, even if they're used multiple times.

For example, your resource manager could load all resources upon request or you create some kind of stack that tracks everything to be loaded (you can (re-)use an sf::Texture even before it's loaded for example) and then process them once a frame or so. If the stack becomes too large, you show a loading screen and load everything at once.

Multithreaded loading is possible right now, it's just a bit tricky to get it right, and considering it would still block rendering, I wouldn't really recommend it.