The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_Surface, SDL_Texture and multithreading
Naith


Joined: 03 Jul 2014
Posts: 158
Hello,

I'm creating a multithreaded program and have a question:

I've heard that SDL-specific functions, such as SDL_CreateTexture and SDL_CreateTextureFromSurface, should only be executed from the thread that created the SDL window, i.e the main thread.

What I do in my program to prevent this is using SDL_Image's function IMG_Load to load an image and saves it into a SDL_Surface. This is made in another thread (a loading-thread). Then, in the main-thread, I'm creating the final texture by calling the SDL_CreateTextureFromSurface function, and passing the SDL_Surface into it.

Is it safe to call IMG_Load in another thread and creating the SDL_Surface the way I do?
SDL_Surface, SDL_Texture and multithreading
wutipong.wongsakuldej@...
Guest

I'm doing the same thing in both Linux and Windows. So far i haven't seen any problems.

Sent from my ASUS

-------- Original Message --------
From:Naith
Sent:Sat, 02 Apr 2016 07:08:40 +0700
To:
Subject:[SDL] SDL_Surface, SDL_Texture and multithreading

Hello, I'm creating a multithreaded program and have a question: I've heard that SDL-specific functions, such as SDL_CreateTexture and SDL_CreateTextureFromSurface, should only be executed from the thread that created the SDL window, i.e the main thread. What I do in my program to prevent this is using SDL_Image's function IMG_Load to load an image and saves it into a SDL_Surface. This is made in another thread (a loading-thread). Then, in the main-thread, I'm creating the final texture by calling the SDL_CreateTextureFromSurface function, and passing the SDL_Surface into it. Is it safe to call IMG_Load in another thread and creating the SDL_Surface the way I do?
SDL_Surface, SDL_Texture and multithreading
Frank Kevin Zey (Privat)
Guest

As far as I'm concern, IMG_Load and SDL_Surface are cpu bound, so loading and creating in a different thread is okay. If you are going to create a texture, which is gpu bound, you have to do it in your main thread or the thread, where you created the window with the opengl context(SDL uses opengl for acceleration). Because opengl isn't multithreating capable, your way of doing it is right.


--
Mit freundlichen Grüßen / Best regards

Frank Kevin Zey B.Sc. Informatik
 

On 04/03/2016 07:38 AM, wrote:

Quote:
I'm doing the same thing in both Linux and Windows. So far i haven't seen any problems.

Sent from my ASUS

-------- Original Message --------
From:Naith
Sent:Sat, 02 Apr 2016 07:08:40 +0700
To: ([email]To:[/email])
Subject:[SDL] SDL_Surface, SDL_Texture and multithreading

Hello,

I'm creating a multithreaded program and have a question:

I've heard that SDL-specific functions, such as SDL_CreateTexture and SDL_CreateTextureFromSurface, should only be executed from the thread that created the SDL window, i.e the main thread.

What I do in my program to prevent this is using SDL_Image's function IMG_Load to load an image and saves it into a SDL_Surface. This is made in another thread (a loading-thread). Then, in the main-thread, I'm creating the final texture by calling the SDL_CreateTextureFromSurface function, and passing the SDL_Surface into it.

Is it safe to call IMG_Load in another thread and creating the SDL_Surface the way I do?


Quote:
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Naith


Joined: 03 Jul 2014
Posts: 158
Thank you both very much for your answers!
Naith


Joined: 03 Jul 2014
Posts: 158
Another question regarding multithreading with SDL.

Is it safe to use SDL_Mixer and SDL_TTF in another thread and, for example, loading a music file (Mix_LoadMUS) and a font file (TTF_OpenFont) in a loading thread?