work with several contexts from different threads

From my experience the best way to use multiple gl contexts (even with sharing) between multiple threads is to:

  1. In main thread create N gl contexts that you need, but DO NOT MAKE THEM CURRENT.
  2. Start N threads and pass one RC per each thread.
  3. 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.

  1. scene rendering contex have infinite update+render loop. Scene was rendererd in FBO
  2. UI rendering thread perform update&render only on some event. UI is also rendererd in FBO
  3. 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.