From 204c91c971dd2432af96e3586a706cdbc530e6f2 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Thu, 15 Jun 2023 13:34:13 +0200 Subject: [PATCH] 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 --- examples/gui/rhiwindow/main.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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.