One GL Context Multiple Widgets - Qt 6
I'm trying to create multiple OpenGL-capable QWidget's but sharing the same GL context. I tried to use QOpenGLWidget but it creates a GL context for every widget.
Is it possible to achieve this using QWidget and Create QOpenGLContext manually and associate it with every created QWidget? Any working examples?
Thanks.
Re: One GL Context Multiple Widgets - Qt 6
I hope my question is clear otherwise I will assume it's not something doable using Qt. Fair enough! :D
Re: One GL Context Multiple Widgets - Qt 6
Quote:
Is it possible to achieve this using QWidget and Create QOpenGLContext manually and associate it with every created QWidget?
QOpenGLContext::setShareContext() won't do what you want?
Re: One GL Context Multiple Widgets - Qt 6
Quote:
Originally Posted by
d_stranz
Not really. Once QOpenGLWidget is instantiated, a GL context is created for the widget and cannot be used for subsequent instances of QOpenGLWidget.
Re: One GL Context Multiple Widgets - Qt 6
If you create the widget, call its method to retrieve the context, then call setShareContext() with that pointer using your common context, that doesn't work?
Re: One GL Context Multiple Widgets - Qt 6
Quote:
Originally Posted by
d_stranz
If you create the widget, call its method to retrieve the context, then call setShareContext() with that pointer using your common context, that doesn't work?
Then the default created context has to be deleted and the shared context is assigned to every new widget, assuming setShareContext changes the widget context. But this sounds like a hack!
Re: One GL Context Multiple Widgets - Qt 6
Quote:
But this sounds like a hack!
Don't know; I don't write explicit OpenGL code that much. I think your only option is to look at the implementation of QOpenGLWidget and then derive your own version from QWidget that lets you set the context externally instead of creating it by default. With luck you may be able to reuse a lot of the source code.