diff options
author | Tomi Korpipää <tomi.korpipaa@qt.io> | 2017-11-29 07:47:05 +0200 |
---|---|---|
committer | Pasi Keränen <pasi.keranen@qt.io> | 2017-11-29 07:00:57 +0000 |
commit | 13a1d0a5a9886a9bc7f8fcfb18f79e3248efd061 (patch) | |
tree | ff6a8d499387abe97f04ce42d1b4ab98491df4cf /examples | |
parent | c49afe176ba07082aa1eaba3c6a2b014a02e0827 (diff) |
Fix viewer examples for macOS
Also update the surface format of all macOS viewers to 4.1.
Task-number: QT3DS-581
Change-Id: I642bc9a145b225dd3ac71e6c66dbf8d096d4e538
Reviewed-by: Antti Määttä <antti.maatta@qt.io>
Reviewed-by: Pasi Keränen <pasi.keranen@qt.io>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/studio3d/surfaceviewer/main.cpp | 13 | ||||
-rw-r--r-- | examples/studio3d/surfaceviewer_offscreen/main.cpp | 21 | ||||
-rw-r--r-- | examples/studio3d/widgetviewer/main.cpp | 19 |
3 files changed, 37 insertions, 16 deletions
diff --git a/examples/studio3d/surfaceviewer/main.cpp b/examples/studio3d/surfaceviewer/main.cpp index 12fcdd0b..ab198e47 100644 --- a/examples/studio3d/surfaceviewer/main.cpp +++ b/examples/studio3d/surfaceviewer/main.cpp @@ -61,6 +61,19 @@ int main(int argc, char *argv[]) { + // 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 + QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); diff --git a/examples/studio3d/surfaceviewer_offscreen/main.cpp b/examples/studio3d/surfaceviewer_offscreen/main.cpp index eb26803a..8d72c026 100644 --- a/examples/studio3d/surfaceviewer_offscreen/main.cpp +++ b/examples/studio3d/surfaceviewer_offscreen/main.cpp @@ -60,14 +60,25 @@ int main(int argc, char *argv[]) { - QGuiApplication app(argc, argv); + QSurfaceFormat openGLFormat; + openGLFormat.setStencilBufferSize(8); + openGLFormat.setDepthBufferSize(24); + + // 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) + openGLFormat.setRenderableType(QSurfaceFormat::OpenGL); + openGLFormat.setProfile(QSurfaceFormat::CoreProfile); + openGLFormat.setMajorVersion(4); + openGLFormat.setMinorVersion(1); + QSurfaceFormat::setDefaultFormat(openGLFormat); +#endif - QSurfaceFormat format; - format.setDepthBufferSize(24); - format.setStencilBufferSize(8); + QGuiApplication app(argc, argv); QOpenGLContext context; - context.setFormat(format); + context.setFormat(openGLFormat); if (!context.create()) qFatal("Failed to create OpenGL context"); diff --git a/examples/studio3d/widgetviewer/main.cpp b/examples/studio3d/widgetviewer/main.cpp index 9ad8eed9..278aa847 100644 --- a/examples/studio3d/widgetviewer/main.cpp +++ b/examples/studio3d/widgetviewer/main.cpp @@ -55,20 +55,17 @@ int main(int argc, char *argv[]) { - // to enable QOpenGLWidget to work on macOS, we must set the default + // To enable QOpenGLWidget to work on macOS, we must set the default // QSurfaceFormat before QApplication is created. Otherwise context-sharing // fails and QOpenGLWidget breaks. - - // fortunately, we know which OpenGL version we can use on macOS, so we - // can simply hard-code it here. #if defined(Q_OS_MACOS) - QSurfaceFormat openGL33Format; - openGL33Format.setRenderableType(QSurfaceFormat::OpenGL); - openGL33Format.setProfile(QSurfaceFormat::CoreProfile); - openGL33Format.setMajorVersion(3); - openGL33Format.setMinorVersion(3); - openGL33Format.setStencilBufferSize(8); - QSurfaceFormat::setDefaultFormat(openGL33Format); + QSurfaceFormat openGLFormat; + openGLFormat.setRenderableType(QSurfaceFormat::OpenGL); + openGLFormat.setProfile(QSurfaceFormat::CoreProfile); + openGLFormat.setMajorVersion(4); + openGLFormat.setMinorVersion(1); + openGLFormat.setStencilBufferSize(8); + QSurfaceFormat::setDefaultFormat(openGLFormat); #endif // Enable high DPI scaling |