From 69fb78e2c909dd4fdbed44fef9d2e9c1e4040362 Mon Sep 17 00:00:00 2001 From: Sami Liedes Date: Thu, 11 Sep 2025 01:41:01 +0200 Subject: [PATCH] Gui: Request 24-bit color depth if available In some configurations, Qt apparently defaults to giving the "first acceptable" buffer format. This often ends up being RGB565, which gives us little color resolution. Request 8-bit RGB samples to fix this. This tends to happen easiest with `QT_WAYLAND_DISABLE_WINDOWDECORATION=1` and `QT_QPA_PLATFORM=wayland`. --- src/Gui/Application.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 0ec6a39980..47702e2949 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -2384,11 +2384,30 @@ void Application::runApplication() { StartupProcess::setupApplication(); - QSurfaceFormat fmt; - fmt.setRenderableType(QSurfaceFormat::OpenGL); - fmt.setProfile(QSurfaceFormat::CompatibilityProfile); - fmt.setOption(QSurfaceFormat::DeprecatedFunctions, true); - QSurfaceFormat::setDefaultFormat(fmt); + { + QSurfaceFormat defaultFormat; + defaultFormat.setRenderableType(QSurfaceFormat::OpenGL); + defaultFormat.setProfile(QSurfaceFormat::CompatibilityProfile); + defaultFormat.setOption(QSurfaceFormat::DeprecatedFunctions, true); +#if defined(FC_OS_LINUX) || defined(FC_OS_BSD) + // QGuiApplication::platformName() doesn't yet work at this point, so we use the env var + if (getenv("WAYLAND_DISPLAY")) { + // In some settings (at least EGL on Wayland) we get RGB565 by default. + // Request something better. + defaultFormat.setRedBufferSize(8); + defaultFormat.setGreenBufferSize(8); + defaultFormat.setBlueBufferSize(8); + // Qt's behavior with format requests seems opaque, underdocumented and, + // unfortunately, inconsistent between platforms. Requesting an alpha + // channel tends to steer it away from weird legacy choices like RGB565. + defaultFormat.setAlphaBufferSize(8); + // And a depth/stencil buffer is generally useful if we can have it. + defaultFormat.setDepthBufferSize(24); + defaultFormat.setStencilBufferSize(8); + } +#endif + QSurfaceFormat::setDefaultFormat(defaultFormat); + } // A new QApplication Base::Console().log("Init: Creating Gui::Application and QApplication\n");