3

I'm writing an application that is composed of multiple (16-32) plots that are updated several times a second and are drawn using openGL. Until now I've down most of the prototyping of the plots with GLUT. However I'd like to adopt a full fledge framework like QT and I'm getting ready to write a test QGLWidget.

Before I get started I'd like to figure out if its possible for multiple QGLWidgets to share a single openGL context? If so is there anything specifics I need to keep track of when sharing an openGL context between widgets?

2 Answers 2

3

if its possible for multiple QGLWidgets to share a single openGL context?

Now this is not possible to answer in general, because it depends on the platform in question: On X11/GLX it is indeed possible to use an indirect context on multiple drawables, however the context can be active on only one drawable at a time.

However:

It is also possible (and it is the recommended way to do this) to have multiple contexts share their data. In the very first versions of OpenGL this was only display lists, hence this still called list sharing. But with current versions of OpenGL this also includes textures, Pixel Buffer Objects and Vertex Buffer Objects. Frame Buffer Objects however can not be shared, but since textures can be used as FBO attachments that's no big deal.

QGLWidget provides a straigtforward API to share context data between QGLWidgests' contexts.

Sign up to request clarification or add additional context in comments.

4 Comments

The individual plots are extremely simple. They are a collection of scatter plots and no data needs to be shared (PBOs, VBOs, FBOs). It was my understanding that a lot of resources get allocated for each openGL context and that it is quite expensive to switch between contexts. In this case is it preferable to have a single context that is shared between all the widgets?
@slayton: The expenses in switching contexts are due to the changes in the resources. One resource will always change: The window. But if the data of the contexts is shared, things are not that bad. Also you must understand, that the expenses of context switching are more of a problem for realtime rendering applications, where the images are generated in a animation. In your case you have rather simple plots and probably no textures to be exchanged.
if the individual QGLWidgets are all contained in the same window then does that resource get changed with each context switch? Does openGL have a window resource that isn't the same thing as the window drawn by the os? Or does each context have a link to the same resource?
@slayton: Each QGLWidget maintains a separate child window of the OS graphics system. And for each of those windows one needs a individual OpenGL context. However: If all those QGLWidgets are within the same window, why not replace it with a single QGLWidget and use glViewport + glScissor to draw the different plots with just one OpenGL context?
1

Yes, it is possible to share an opengl context by using this constructor.

If so is there anything specifics I need to keep track of when sharing an openGL context between widgets?

I am not sure, but I don't think there is anything special you need to take care of.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.