2

I'm developing an editor in Qt that will have multiple GL contexts running simultaneously in multiple top-level windows. Since VAOs can't be shared between contexts, I'm trying to come up with a way to manage them on a per-context basis, which is proving to be fairly complicated.

It would be a lot simpler if I could just simply use the same context between both, but this doesn't seem to be possible with Qt 5.4. QGLWidget was able to explicitly take a QGLContext pointer as a constructor parameter, but there's no corresponding function for QOpenGLWidget. This is what the documentation says about context sharing:

When multiple QOpenGLWidgets are added as children to the same top-level widget, their contexts will share with each other. This does not apply for QOpenGLWidget instances that belong to different windows.

Is there a way around this?

I can't find too much info on the subject unfortunately, since QOpenGLWidget is relatively new - most of what I can find is talking about QGLWidget.

edit: I'm trying some different things and I've had a little bit of success creating a custom GL widget so I can manage the contexts myself, although there's some bad bugs. However it's sounding like it's actually required to have different contexts for different windows in some cases, which would mean I should just stick with QOpenGLWidget and come up with a VAO-management system. It would be cool if someone with more knowledge/experience on the subject could explain how this works though.

asked Apr 24, 2015 at 3:44
4
  • maybe you can play with QOpenGLContext::makeCurrent(QSurface) ? Commented Apr 24, 2015 at 7:13
  • You might also rely on one context, one canvas, and do the screen splitting by yourself, using viewports. You might even implement some kind of resizing manually. This gives you a lot of room for optimization. Commented Apr 24, 2015 at 8:23
  • @otopolsky hmm interesting... I'm gonna try out setting up my own GL widget using a QWindow. That might allow me to manage the contexts myself. Commented Apr 24, 2015 at 16:12
  • 1
    Gave it a shot and it seems to sorta work, although there are some pretty ugly bugs. I might be able to fix most of them with a little more work, though. I don't really know enough about OpenGL and Qt's setup for this to know whether this is really a good idea, though, as opposed to just calling QOpenGLContext::SetCurrent(QSurface*) in QOpenGLWidgets. I'm not sure how many pitfalls there are that I don't know about (in terms of performance, bugs, context not being valid for a surface for some reason, etc). Commented Apr 24, 2015 at 17:46

1 Answer 1

2

From the QOpenGLWidget documentation:

To set up sharing between QOpenGLWidget instances belonging to different windows, set the Qt::AA_ShareOpenGLContexts application attribute before instantiating QApplication. This will trigger sharing between all QOpenGLWidget instances without any further steps.

According to the Application Attribute documentation, this flag was introduced in version 5.4

answered Mar 14, 2016 at 11:02
Sign up to request clarification or add additional context in comments.

2 Comments

I've realised that this does not solve the problem in the question, as it does not actually share the context, but enables sharing of a subset of resources, not including VAOs. This point isn't made entirely clear by the Qt documentation. Should I remove this answer, or leave it here for others to learn from my misunderstanding?
Please leave it. I ran into the exact same problem (VAOs not being sharable) and it is indeed very confusing. Knowing that it's defined behavior (no matter how stupid), rules out user errors and driver bugs.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.