DreaminD's picture

Context sharing in an extensible MDI app

Hello :) I'm making a MDI (actually, tabbed multi-document) application, which should display/edit a couple of different types of documents (and the list should be extendable by third parties).
I intend to use context-sharing between all documents (well, this is the only way to share contexts using current GraphicsContext, anyway :J). I suppose all documents that want to share contexts would have to use the same OpenGL version. Are there any other considerations/limitations I should take into account when allowing third-party extensions?


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

In my experience, context sharing is very hard to implement reliably on arbitrary hardware. Out-of-the-box, you lose support for Intel/windows where context sharing isn't supported at all (I don't know whether this has changed with their recent 3.1 drivers).

Another thing to keep in mind is that context sharing may fail when creating contexts with different pixel formats (e.g. with and without antialiasing) or different versions (GL 2.x and 3.x). Finally, some GL objects cannot be shared (e.g. GL3.x vertex array objects).

Consider following a different approach: create a single OpenGL context and use MakeCurrent() to attach it to different windows. The current implementation has a limitation in that MakeCurrent() only works on windows with pixel formats set (e.g. GLControls, see #2474: WinGLContext.MakeCurrent only works for windows used to create an opengl context). Even so, this is significantly more reliable than multiple contexts with sharing.

DreaminD's picture

Thanks, this is an extremely valuable advice :)
I use GTK too, so it seems that the fix suggested by muhkuh may be necessary for my app as well. Will there be ways to do it without modifying OpenTK source?

the Fiddler's picture

GTK# with GLWidget? In this case, you will be able to call GraphicsContext.MakeCurrent(IWindowInfo) on any GLWidget (since all GLWidgets have a pixel format set).

In short: create as many GLWidgets as you need; ignore all GraphicsContexts other than the first one; call MakeCurrent to draw using the first context on any GLWidget. The only limitation is that you won't be able to call MakeCurrent on arbitrary windows until muhkuh's code is merged.

DreaminD's picture

Thanks again. I do not plan to render to non-GL widgets, so I guess this should work for me ^^