Multiple windows, single context

Currently making a gui rendering system and it needs to be able to render to a bunch of windows. The original way I was going to do this would be to have a dedicated renderer (and by extension dedicated gl objects) per window, however because my renderer takes up quite a bit of memory and there may be several windows at once, this isn’t ideal. So is there any way to have the same opengl context across multiple windows. Not shared objects as with glfwCreateWindow(..., shared) but truely the same context where all objects even containers are shared, I was able to find an example for xgl here but it uses glut and xgl where I am using glad and glfw. Is there any way to do this kind of thing within the glfw api?

Another (mostly separate) option that I think might work but still am not entirely sure about is to render to framebuffers and then send render those framebuffers to their windows, but framebuffer objects are also container objects so I don’t think this really will work, but I haven’t tried it either.

Thanks in advance.

You could potentially make this work for GLX and WGL using the GLFW native access functions and each platforms MakeCurrent function (glXMakeCurrent and wglMakeCurrent) along with a few other function calls (get HDC from HWND etc.).

For NSGL (Mac OS X) you would need a different approach, as the OpenGL context is bound to an NSView. You should be able to get this from the native access functions and use then set the view as below:

However using a window created with a shared context will give you similar capability, so if you can alter your renderer so that you can set the current context prior to rendering the scene for a given window you should be able to make this approach work in a platform independent way.

Thanks for the info on the native access API, I would indeed prefer to do it through the standard GLFW api, The issue with my renderer design is that it has container objects, specifically VAOs and programs, unfortunately these cannot be shared because they are container objects. I suppose I could have a copy of each of them for each context, I don’t think that would be super expensive, nor extremely complex. Just set them when binding the context.