From cb8c193408b82e208504f22fa75aa0a4609b00cb Mon Sep 17 00:00:00 2001 From: Karliss Date: Sun, 9 Feb 2025 16:53:18 +0200 Subject: [PATCH] Workaround for transparency problems on wayland. Reset alpha channel value to 1 at the end of 3d rendering. The way Qt handles OpenGL widgets with transparent pixels in their final output is inconsistent. --- src/Gui/View3DInventorViewer.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 88498eaf09..5cae26dcb7 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2457,6 +2457,26 @@ void View3DInventorViewer::renderScene() if (naviCubeEnabled) { naviCube->drawNaviCube(); } + + // Workaround for inconsistent QT behavior related to handling custom OpenGL widgets that + // leave non opaque alpha values in final output. + // On wayland that can cause window to become transparent or blurry trail effect in the + // parts that contain partially transparent objects. + // + // At the end of rendering clear alpha value, so that it doesn't matter how rest of the + // compositing stack at QT and desktop level would interpret transparent pixels. + // + // Related issues: + // https://bugreports.qt.io/browse/QTBUG-110014 + // https://bugreports.qt.io/browse/QTBUG-132197 + // https://bugreports.qt.io/browse/QTBUG-119214 + // https://github.com/FreeCAD/FreeCAD/issues/8341 + // https://github.com/FreeCAD/FreeCAD/issues/6177 + glPushAttrib(GL_COLOR_BUFFER_BIT); + glColorMask(false, false, false, true); + glClearColor(0, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); + glPopAttrib(); } void View3DInventorViewer::setSeekMode(bool on)