From 345a80d2f346b73b09bd63122a68b545c60194d1 Mon Sep 17 00:00:00 2001 From: Tomi Korpipaa Date: Wed, 29 Nov 2017 10:08:22 +0200 Subject: Fix qml examples for macOS Task-number: QT3DS-583 Change-Id: If51b8caf3cf5c3f8422cf17fa45fdfece10f2668 Reviewed-by: Miikka Heikkinen --- examples/studio3d/qmldynamickeyframes/main.cpp | 12 ++++++++++++ examples/studio3d/qmlstreamer/main.cpp | 12 ++++++++++++ 2 files changed, 24 insertions(+) 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); -- cgit v1.2.3