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 <laszlo.agocs@qt.io>
This commit is contained in:
Laszlo Agocs 2023-06-15 13:34:13 +02:00
parent 5328fdd8ba
commit 204c91c971

View File

@ -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.