wglShareLists() and Multiple Render Windows

MSDN is the only crediable source on wiggle (that I know of) and it’s pretty much outdated with plenty of missing functions so there’s usually some sort of dark magic involved if one is about to step outside the cozy shelter and enter the dark realm of lesser-used functions. wglShareLists() is one member of this family. MSDN states that this function informs OpenGL server to share the diplay-list space between several rendering contexts but it never talks about other server-side resources.

I’m assuming that other server-side resources such as textures and VBOs are also shared, but to my experience server-side states are not. I’ve been playing around with wglShareLists() for a few days now so my knowledge on the subject is limitted. My interpretation might also be completely wrong, especially considering the scarce documentaion that’s available but my experience is that server-side states (states that are set by glEnable/glDisable for instance) are not shared between the rendering contexts so they must be explicitly set for every single rendering context that’s available, which is a pain in the rear end in applications with multiple render window setups. These states tend to get out of synch and cause headaches in the long run. So my first question is this: Do you have any experience with wglShareLists()? What’s your take on the aforementioned dilemma?

As far as I’m concerned, D3D’s architecture is a whole lot cleaner in this regard. In D3D, pipeline states are stored inside the device object, which, as far as I know, is not directly related or bound to a window. These states are shared among all windows which in turn, are represented by swap chains. There is always at least one swap chain for each device, known as the implicit swap chain. However, an additional swap chain for rendering multiple views from the same device can be created. In OpenGL, rendering contexts are bound to windows (rendering contexts are bound to device contexts which in turn are bound to windows, to be exact), which makes sharing them non-trivial considering the set of functions that are available. I even went as far as creating a dummy rendering context that’s attached to a dummy window and used that as a hub to share other states, but you see, wglShareLists doesn’t allow sharing of states. So, do you know of a workaround? Did you find this issue problematic?


only the list space is shared. Initially, GL had only display lists objects and the docs weren’t updated in a while, but the term “list space” also apply to other GL objects like textures and shaders. Still, you deal with different contexts here, each of which has it’s own state. If you just have multiple windows but want to use the same context, you can do it by using wglMakeCurrent function to draw to all windows using the same context.

edit: or just copy the image from one of your windows to another…

Many thanks.

But how?! Each rendering context must be associated with a device context (wglCreateContext needs that) and each window has a device context of its own. So, I think the question boils down to this: how can several windows share a device context? Or am I missing something? A code snippet might help clarify these points.

Any help is greatly appreciated.



Thanks man.

It’s strange though. So the trick is to create one RC and bind that with other DCs?! Like this: ?

RC = wglCreateContext( DC1 );
wglMakeCurrent( DC1, RC );
wglMakeCurrent( DC2, RC );

… and so on? EVEN THOUGH RC is not created for DC2? Does that really work?

Ashan, if you would read the documentation carefully, you will find out, there is no “trick” at all. The RC has nothing, really nothing to do with a DC. The RC is created with a special PixelFormat (and device and stuff) in mind and is compatible with any DC that has that pixelformat. So the dc parameter in the CreateContext function is kind of a prototype; it does not mean “create it for this DC only”, but rather “create it for this class of DC”. So, any DC (window) in the same device (graphis card) with the same pixelformat can be made renderable to using the same context.

Hope it helps.

Thank you very much zengar.

Well, using the same rendering context for multiple device contexts is way better than using wglShareLists, but since it’s not possible to have a single rendering context for two device contexts which have different pixelformats, do you know of an approach that allows me to share the rendering context for device contexts with different pixel formats? Let’s say I want anti-aliasing enabled in one of my windows and disabled in others, or I want one of my windows to have a higher depth percision, what should I do under such circumstances? Should I setup two totally different rendering contexts and load all server-side resources twice?

Thanks in advance.