Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha chanel causes transparent window with glium backend under Wayland #1347

Closed
alvinhochun opened this issue Apr 30, 2020 · 0 comments · Fixed by #1375
Closed

Alpha chanel causes transparent window with glium backend under Wayland #1347

alvinhochun opened this issue Apr 30, 2020 · 0 comments · Fixed by #1375

Comments

@alvinhochun
Copy link
Collaborator

I believe this is related to glium/glium#1678. I'm absolutely not familiar with how OpenGL surfaces should interact with Wayland, but what I gathered is that the resulting alpha channel will affect the compositing of the window.

The glium backend uses the glium::Blend::alpha_blending() alpha blending function (

let blend = glium::Blend::alpha_blending();
) in which the alpha channel is calculated by srcAlpha * srcAlpha + dstAlpha * (1 - srcAlpha) (https://github.com/glium/glium/blob/776413b4eb8da16a4e9801feb27754e400e7d25a/src/draw_parameters/blend.rs#L28). To me this seems really wrong. I believe the usual way of combining the alpha channels is srcAlpha + dstAlpha * (1 - srcAlpha), which means the code should be changed into this:

diff --git a/backends/conrod_glium/src/lib.rs b/backends/conrod_glium/src/lib.rs
index d58bd56..8e2d7eb 100644
--- a/backends/conrod_glium/src/lib.rs
+++ b/backends/conrod_glium/src/lib.rs
@@ -291,7 +291,18 @@ pub fn program<F>(facade: &F) -> Result<glium::Program, glium::program::ProgramC
 
 /// Default glium `DrawParameters` with alpha blending enabled.
 pub fn draw_parameters() -> glium::DrawParameters<'static> {
-    let blend = glium::Blend::alpha_blending();
+    use glium::{Blend, BlendingFunction, LinearBlendingFactor};
+    let blend = Blend {
+        color: BlendingFunction::Addition {
+            source: LinearBlendingFactor::SourceAlpha,
+            destination: LinearBlendingFactor::OneMinusSourceAlpha,
+        },
+        alpha: BlendingFunction::Addition {
+            source: LinearBlendingFactor::One,
+            destination: LinearBlendingFactor::OneMinusSourceAlpha,
+        },
+        constant_value: (0.0, 0.0, 0.0, 0.0),
+    };
     glium::DrawParameters { multisampling: true, blend: blend, ..Default::default() }
 }
 

However I do wonder if this should be fixed in glium by changing glium::Blend::alpha_blending().

The new blending function matches that of of the wgpu backend, which does not exhibit this issue.

The gfx backend, while it to does not appear to exhibit this issue, uses gfx::preset::blend::ALPHA which is srcAlpha + dstAlpha, so it is also incorrect.

alvinhochun added a commit to alvinhochun/conrod that referenced this issue Aug 8, 2020
alvinhochun added a commit to alvinhochun/conrod that referenced this issue Aug 10, 2020
wez added a commit to wez/wezterm that referenced this issue Feb 16, 2021
This commit:

* Fixes up the alpha blending draw parameters as discussed in
  glium/glium#1844 and
  PistonDevelopers/conrod#1347

* Introduces `colorize` and `colorize_hsv` functions to the shader.
  comments in the code explain those functions in detail.

As of this commit, `colorize_hsv` is what is used now.  To my
eye on this mac, it produces blended glyphs with less noticeable
dark antialiasing fringes.

refs: #470
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant