From my experience the best way to use multiple gl contexts (even with sharing) between multiple threads is to:
- In main thread create N gl contexts that you need, but DO NOT MAKE THEM CURRENT.
- Start N threads and pass one RC per each thread.
- Inside thread’s worker function, call wglMakeCurrent once at beggining and the use context as usuall.
Few years ago I did some tests with OpenGL UI elements. The problem was how to decuople OpenGL UI rendering from scene rendering… If scene is too complex, UI start lagging.
So I create 3 GL contexts… first for scene rendering, second for UI rendering and third as muxer.
- scene rendering contex have infinite update+render loop. Scene was rendererd in FBO
- UI rendering thread perform update&render only on some event. UI is also rendererd in FBO
- mixer have fixed FPS (60) and it use shared textres from first two contexts mix them and render on screen.
During development of that test I tried everything to achive proper multiple thread & contexts rendering and resource sharing.