summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/studio3d/qmldynamickeyframes/main.cpp12
-rw-r--r--examples/studio3d/qmlstreamer/main.cpp12
2 files changed, 24 insertions, 0 deletions
diff --git a/examples/studio3d/qmldynamickeyframes/main.cpp b/examples/studio3d/qmldynamickeyframes/main.cpp
index adddbdce..12e3fa3c 100644
--- a/examples/studio3d/qmldynamickeyframes/main.cpp
+++ b/examples/studio3d/qmldynamickeyframes/main.cpp
@@ -64,6 +64,18 @@ int main(int argc, char *argv[])
#ifdef USE_EMBEDDED_FONTS
qputenv("QT_QPA_FONTDIR",".");
#endif
+ // To enable QOpenGLWidget to work on macOS, we must set the default
+ // QSurfaceFormat before QApplication is created. Otherwise context-sharing
+ // fails and QOpenGLWidget breaks.
+#if defined(Q_OS_MACOS)
+ QSurfaceFormat openGLFormat;
+ openGLFormat.setRenderableType(QSurfaceFormat::OpenGL);
+ openGLFormat.setProfile(QSurfaceFormat::CoreProfile);
+ openGLFormat.setMajorVersion(4);
+ openGLFormat.setMinorVersion(1);
+ openGLFormat.setStencilBufferSize(8);
+ QSurfaceFormat::setDefaultFormat(openGLFormat);
+#endif
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
diff --git a/examples/studio3d/qmlstreamer/main.cpp b/examples/studio3d/qmlstreamer/main.cpp
index 82b640a8..09cd9f8b 100644
--- a/examples/studio3d/qmlstreamer/main.cpp
+++ b/examples/studio3d/qmlstreamer/main.cpp
@@ -62,6 +62,18 @@ int main(int argc, char *argv[])
#ifdef USE_EMBEDDED_FONTS
qputenv("QT_QPA_FONTDIR",".");
#endif
+ // To enable QOpenGLWidget to work on macOS, we must set the default
+ // QSurfaceFormat before QApplication is created. Otherwise context-sharing
+ // fails and QOpenGLWidget breaks.
+#if defined(Q_OS_MACOS)
+ QSurfaceFormat openGLFormat;
+ openGLFormat.setRenderableType(QSurfaceFormat::OpenGL);
+ openGLFormat.setProfile(QSurfaceFormat::CoreProfile);
+ openGLFormat.setMajorVersion(4);
+ openGLFormat.setMinorVersion(1);
+ openGLFormat.setStencilBufferSize(8);
+ QSurfaceFormat::setDefaultFormat(openGLFormat);
+#endif
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);