summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaszlo Agocs <[email protected]>2023-06-15 13:34:13 +0200
committerLaszlo Agocs <[email protected]>2023-06-21 15:09:03 +0200
commit204c91c971dd2432af96e3586a706cdbc530e6f2 (patch)
tree4d2ab9957c19c59a795642e791c9980af183f4e9
parent5328fdd8baa813c4a170501c2fad740dc2d0b433 (diff)
rhiwindow example: Make -g option (OpenGL) work on macOS
Of course we managed to rely on a GLSL feature that is only in GLSL 130 and newer, not 120 which is what the default 2.1 OpenGL contexts support on macOS. Change-Id: Ib75e750ea15d59e51b2207669068fba7719a48b1 Pick-to: 6.6 Reviewed-by: Laszlo Agocs <[email protected]>
-rw-r--r--examples/gui/rhiwindow/main.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/examples/gui/rhiwindow/main.cpp b/examples/gui/rhiwindow/main.cpp
index c6d9ce56697..6ca38e7b542 100644
--- a/examples/gui/rhiwindow/main.cpp
+++ b/examples/gui/rhiwindow/main.cpp
@@ -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.