-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Thread-safety? #31
Comments
Hi @NukeBird !
SDL_GL_SetAttribute( SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1 );
mGLContext = SDL_GL_CreateContext( mSDLWindow );
mGLContextThread = SDL_GL_CreateContext( mSDLWindow );
if ( std::this_thread::get_id() != myOpenGLMainThreadId ) {
// If the current thread is not the OpenGL main thread we need to activate the GL shared context in the current thread.
glContextThreadMutex.lock();
SDL_GL_MakeCurrent( mSDLWindow, mGLContextThread );
}
SOIL_load_OGL_texture(...);
if ( std::this_thread::get_id() != myOpenGLMainThreadId ) {
// Deactivate the GL shared context.
SDL_GL_MakeCurrent( mSDLWindow, NULL );
glContextThreadMutex.unlock();
} And that's basically it. You just need to ensure that there's an active GL context in your current thread before calling any OpenGL method (and in this case any SOIL2 function). To upload any compressed texture directly to VRAM remember to use the flags for it: BTW, one clarification this example is to decode and load the OpenGL texture in other thread, If you want to decode first the image in a secondary thread, use Regards. |
Is SOIL2 threadsafe? Always?
I would love to use such a library to decode textures in parallel (OpenGL textures will be created in render context after)
jpg/png should be fine, I know stb_image have no problems with it. But what about dds and etc?
The text was updated successfully, but these errors were encountered: