Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is OpenGL threadsafe for multiple threads with distinct contexts?

I know that sharing a single context between threads is bad news. I know that I can safely create and use a context with an offscreen framebuffer on a secondary thread when nothing is happening with GL on the main thread.

I haven't yet been able to find a definitive answer to the question of whether I can safely create two contexts on two different threads (say, a main thread drawing to the screen, and a secondary thread doing offscreen drawing work) and have them both making GL function calls simultaneously.

In other words, as long as the contexts are different, can two threads "share" the C API and thus the GPU? Or is that inherently something that is unshareable? Or is this implementation-specific?

Asking specifically for OpenGL ES on iOS, but it's probably a general GL question.

like image 352
Ben Zotto Avatar asked Oct 14 '10 20:10

Ben Zotto


People also ask

Is OpenGL a Threadsafe?

OpenGL commands for a specific context are not thread safe. You should never have more than one thread accessing a single context simultaneously. Contexts that are on different threads can share object resources.

What does Threadsafe mean Python?

Thread safety is a computer programming concept applicable to multi-threaded code. Thread-safe code only manipulates shared data structures in a manner that ensures that all threads behave properly and fulfill their design specifications without unintended interaction.


1 Answers

Yes, you need to use one context for each thread you want to use OpenGL with, also you can share objects between the contexts. This is the way to go :)

like image 69
Dr. Snoopy Avatar answered Oct 03 '22 17:10

Dr. Snoopy