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.
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.
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With