From 8b4f1ebbea4acdd9a89881330bb7eeb4cdf04b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Mon, 25 Jul 2022 20:33:47 +0200 Subject: [PATCH] Wayland: Fix window opacity on older systems On systems lacking the EGL_EXT_present_opaque extension, some compositors treat any buffer with an alpha channel as per-pixel transparent. This commit ignores any EGLConfig with an alpha channel if the extension is missing and the window is created with GLFW_TRANSPARENT_FRAMEBUFFER set to false. This is technically not a breaking change since GLFW_ALPHA_BITS is not a hard constraint, but it is still going to inconvenience anyone using the framebuffer alpa channel to store other kinds of data. Related to #1895 (cherry picked from commit ef6c9d8b4f957c2a53374558e393bdb5c4264fa5) --- CONTRIBUTORS.md | 1 + README.md | 2 ++ docs/news.dox | 13 +++++++++++++ src/egl_context.c | 12 ++++++++++++ 4 files changed, 28 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 8dbedda0..835b788a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -180,6 +180,7 @@ video tutorials. - pthom - Martin Pulec - Guillaume Racicot + - Christian Rauch - Philip Rideout - Eddie Ringle - Max Risuhin diff --git a/README.md b/README.md index 8ae21365..ea830772 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,8 @@ information on what to include when reporting a bug. ## Changelog - [Wayland] Bugfix: Connecting a mouse after `glfwInit` would segfault (#1450) + - [Wayland] Disabled alpha channel for opaque windows on systems lacking + `EGL_EXT_present_opaque` (#1895) - [Linux] Bugfix: Joysticks without buttons were ignored (#2042,#2043) [EGL] Added loading of glvnd `libOpenGL.so.0` where available for OpenGL - [GLX] Added loading of glvnd `libGLX.so.0` where available diff --git a/docs/news.dox b/docs/news.dox index 1f016d39..3a7ce4dd 100644 --- a/docs/news.dox +++ b/docs/news.dox @@ -312,6 +312,19 @@ Starting with GLFW 3.3.7, events posted with @ref glfwPostEmptyEvent now use a s unnamed pipe instead of sending an X11 client event to the helper window. +@subsubsection wayland_alpha_34 Frambuffer may lack alpha channel on older Wayland systems + +On Wayland, when creating an EGL context on a machine lacking the new +`EGL_EXT_present_opaque` extension, the @ref GLFW_ALPHA_BITS window hint will be +ignored and the framebuffer will have no alpha channel. This is because some +Wayland compositors treat any buffer with an alpha channel as per-pixel +transparent. + +If you want a per-pixel transparent window, see the +[GLFW_TRANSPARENT_FRAMEBUFFER](@ref GLFW_TRANSPARENT_FRAMEBUFFER_hint) window +hint. + + @subsection deprecations_33 Deprecations in version 3.3 @subsubsection charmods_callback_33 Character with modifiers callback diff --git a/src/egl_context.c b/src/egl_context.c index ec0ff49e..00f43b5d 100644 --- a/src/egl_context.c +++ b/src/egl_context.c @@ -172,6 +172,18 @@ static GLFWbool chooseEGLConfig(const _GLFWctxconfig* ctxconfig, u->depthBits = getEGLConfigAttrib(n, EGL_DEPTH_SIZE); u->stencilBits = getEGLConfigAttrib(n, EGL_STENCIL_SIZE); +#if defined(_GLFW_WAYLAND) + // NOTE: The wl_surface opaque region is no guarantee that its buffer + // is presented as opaque, if it also has an alpha channel + // HACK: If EGL_EXT_present_opaque is unavailable, ignore any config + // with an alpha channel to ensure the buffer is opaque + if (!_glfw.egl.EXT_present_opaque) + { + if (!desired->transparent && u->alphaBits > 0) + continue; + } +#endif // _GLFW_WAYLAND + u->samples = getEGLConfigAttrib(n, EGL_SAMPLES); u->doublebuffer = desired->doublebuffer;