Details
Description
If context sharing is enabled with
QApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
and default surface format is set using
QSurfaceFormat format; format.setVersion(3, 2); format.setProfile(QSurfaceFormat::CoreProfile); QSurfaceFormat::setDefaultFormat(format);
and then you set the format of a QQuickWidget / QOpenGLWidget to the global shared context with
QQuickWidget foo; QOpenGLContext *globalSharedContext = QOpenGLContext::globalShareContext(); foo.setFormat(globalSharedContext->format());
Then the shared OpenGL context for "foo" fails to be created. You get the error message: "QCocoaGLContext: Falling back to unshared context".
This is because the globalSharedContext "advertises" that it is version 4.1, whereas it's actually 3.2.
If you either modify the format of foo to be "3.2" (which would be used by default because of the defaultSurfaceFormat), or use "4.1" everywhere instead, everything works.
My assumption is the following:
Once the global context is created, its format is updated in updateFormatFromContext, which uses glGetString to parse out the version.
That version is always reported as 4.1 for a Core profile, regardless if either 3.2 Core or 4.1 Core is requested.
Internally for macOS though it does seem to make a difference, because sharing between 3.2 global context and 4.1 qquickwidget context is not possible.
Sharing between "3.2 and 3.2", and "4.1 and 4.1" works fine though, regardless of the fact that the advertised version by glGetString is "4.1".