Skip to content

Commit

Permalink
Make the desktop no longer show through when alpha blending is involved
Browse files Browse the repository at this point in the history
for borderless windows on the Mac.

This was because the blend function was
`GL_SRC_ALPHA`/`GL_ONE_MINUS_SRC_ALPHA` for both RGB and alpha, and that
was incorrect for alpha, since a destination alpha of 1.0 and a source
alpha < 1.0 should result in an alpha of 1.0.
  • Loading branch information
pcwalton committed Mar 12, 2016
1 parent 9309d52 commit 8d191d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/debug_render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ impl DebugRenderer {
gl::disable(gl::DEPTH_TEST);
gl::enable(gl::BLEND);
gl::blend_equation(gl::FUNC_ADD);
gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::blend_func_separate(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA,
gl::ONE, gl::ONE);

let projection = Matrix4::ortho(0.0,
viewport_size.width as f32,
Expand Down
17 changes: 12 additions & 5 deletions src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,8 @@ impl Renderer {
gl::disable(gl::BLEND);
} else {
gl::enable(gl::BLEND);
gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::blend_func_separate(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA,
gl::ONE, gl::ONE);
gl::blend_equation(gl::FUNC_ADD);
}

Expand Down Expand Up @@ -1417,8 +1418,8 @@ impl Renderer {
program = self.blit_program_id;
}
CompositionOp::Filter(LowLevelFilterOp::Opacity(amount)) => {
gl::blend_func(gl::SRC_ALPHA,
gl::ONE_MINUS_SRC_ALPHA);
gl::blend_func_separate(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA,
gl::ONE, gl::ONE);
gl::blend_equation(gl::FUNC_ADD);
alpha = amount.to_f32_px();
program = self.blit_program_id;
Expand All @@ -1430,15 +1431,21 @@ impl Renderer {
let (opcode, amount, param0, param1) = match filter_op {
LowLevelFilterOp::Blur(radius,
AxisDirection::Horizontal) => {
gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::blend_func_separate(gl::SRC_ALPHA,
gl::ONE_MINUS_SRC_ALPHA,
gl::ONE,
gl::ONE);
(0.0,
radius.to_f32_px() * self.device_pixel_ratio,
1.0,
0.0)
}
LowLevelFilterOp::Blur(radius,
AxisDirection::Vertical) => {
gl::blend_func(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::blend_func_separate(gl::SRC_ALPHA,
gl::ONE_MINUS_SRC_ALPHA,
gl::ONE,
gl::ONE);
(0.0,
radius.to_f32_px() * self.device_pixel_ratio,
0.0,
Expand Down

0 comments on commit 8d191d1

Please sign in to comment.