summaryrefslogtreecommitdiffstats
path: root/examples/gui/rhiwindow/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'examples/gui/rhiwindow/main.cpp')
-rw-r--r--examples/gui/rhiwindow/main.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/examples/gui/rhiwindow/main.cpp b/examples/gui/rhiwindow/main.cpp
index c6d9ce5669..37977e3a34 100644
--- a/examples/gui/rhiwindow/main.cpp
+++ b/examples/gui/rhiwindow/main.cpp
@@ -14,7 +14,7 @@ int main(int argc, char **argv)
// Use platform-specific defaults when no command-line arguments given.
#if defined(Q_OS_WIN)
graphicsApi = QRhi::D3D11;
-#elif defined(Q_OS_MACOS) || defined(Q_OS_IOS)
+#elif QT_CONFIG(metal)
graphicsApi = QRhi::Metal;
#elif QT_CONFIG(vulkan)
graphicsApi = QRhi::Vulkan;
@@ -52,10 +52,20 @@ int main(int argc, char **argv)
graphicsApi = QRhi::Metal;
//! [api-setup]
- // For OpenGL.
+ // For OpenGL, to ensure there is a depth/stencil buffer for the window.
+ // With other APIs this is under the application's control (QRhiRenderBuffer etc.)
+ // and so no special setup is needed for those.
QSurfaceFormat fmt;
fmt.setDepthBufferSize(24);
fmt.setStencilBufferSize(8);
+ // Special case macOS to allow using OpenGL there.
+ // (the default Metal is the recommended approach, though)
+ // gl_VertexID is a GLSL 130 feature, and so the default OpenGL 2.1 context
+ // we get on macOS is not sufficient.
+#ifdef Q_OS_MACOS
+ fmt.setVersion(4, 1);
+ fmt.setProfile(QSurfaceFormat::CoreProfile);
+#endif
QSurfaceFormat::setDefaultFormat(fmt);
// For Vulkan.