Shared OpenGL context SDL2 |
Frederik vom Hofe
|
Yes you can do that.
First you have to enable shared context in SDL_GL attributes. The last context created will be active in the creator thread. So create the glRenderContext last, or after creating use SDL_GL_MakeCurrent to make it current. This will also make sure that the glThreadContext is not active in this thread and can be activated in another one. (Only one can be current in a thread) To call SDL_GL_MakeCurrent in the thread you just use the pointer to your main windows. A example below: Note that a real loading thread would not get closed until the program is. Because MakeCurrent is very expensive. Better paused it by a Semaphore and then throw work at it when you need something done.
|
|||||||||||||
|
slimshader
|
Thanks! Works like a charm. Not being able to create a context without making it current is unfortunate but I really am happy SDL has portable solution for sharing mechanism. I am aware of issues you mentioned - as I said we alread have think implemented using Qt's GL objects. Fortunately windowing / input was abstracted away enough that it took 1 day to make it work with SDL2 instead of Qt 4.8. Ony thing missing was background texture uploading and now we have it too. Thanks again.
|
|||||||||||
|