diff options
author | Gabriel Martinez <reitaka@gmail.com> | 2017-08-20 09:55:45 -0700 |
---|---|---|
committer | Joe Wilm <jwilm@users.noreply.github.com> | 2017-08-20 09:55:45 -0700 |
commit | 5009566ea5c46a85fa243b18ce4b7fe8e0b89b62 (patch) | |
tree | cc14c0de9686a52f0732a4a7ec29b5c23ea86efb /src/renderer/mod.rs | |
parent | 4e9b1c590e8b0990f5f43fa9d7c53a31a92840a8 (diff) | |
download | alacritty-5009566ea5c46a85fa243b18ce4b7fe8e0b89b62.tar.gz alacritty-5009566ea5c46a85fa243b18ce4b7fe8e0b89b62.zip |
Add background_opacity option to set terminal transparency (#331)
The option is an Alpha struct that ensures that the contained float is
between 0.0 and 1.0. Background colors are multiplied by the opacity
to properly alpha blend them.
Diffstat (limited to 'src/renderer/mod.rs')
-rw-r--r-- | src/renderer/mod.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index 3cad4a01..0dad716e 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -119,6 +119,8 @@ pub struct ShaderProgram { padding_x: f32, padding_y: f32, + + u_bg_opacity: GLint, } @@ -604,6 +606,7 @@ impl QuadRenderer { self.program.activate(); self.program.set_term_uniforms(props); self.program.set_visual_bell(visual_bell_intensity as _); + self.program.set_bg_opacity(config.background_opacity().get()); gl::BindVertexArray(self.vao); gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, self.ebo); @@ -685,12 +688,13 @@ impl QuadRenderer { impl<'a> RenderApi<'a> { pub fn clear(&self, color: Rgb) { + let alpha = self.config.background_opacity().get(); unsafe { gl::ClearColor( - (self.visual_bell_intensity + color.r as f32 / 255.0).min(1.0), - (self.visual_bell_intensity + color.g as f32 / 255.0).min(1.0), - (self.visual_bell_intensity + color.b as f32 / 255.0).min(1.0), - 1.0 + (self.visual_bell_intensity + color.r as f32 / 255.0).min(1.0) * alpha, + (self.visual_bell_intensity + color.g as f32 / 255.0).min(1.0) * alpha, + (self.visual_bell_intensity + color.b as f32 / 255.0).min(1.0) * alpha, + alpha ); gl::Clear(gl::COLOR_BUFFER_BIT); } @@ -916,13 +920,14 @@ impl ShaderProgram { } // get uniform locations - let (projection, term_dim, cell_dim, visual_bell, background) = unsafe { + let (projection, term_dim, cell_dim, visual_bell, background, bg_opacity) = unsafe { ( gl::GetUniformLocation(program, cptr!(b"projection\0")), gl::GetUniformLocation(program, cptr!(b"termDim\0")), gl::GetUniformLocation(program, cptr!(b"cellDim\0")), gl::GetUniformLocation(program, cptr!(b"visualBell\0")), gl::GetUniformLocation(program, cptr!(b"backgroundPass\0")), + gl::GetUniformLocation(program, cptr!(b"bgOpacity\0")), ) }; @@ -937,6 +942,7 @@ impl ShaderProgram { u_background: background, padding_x: config.padding().x.floor(), padding_y: config.padding().y.floor(), + u_bg_opacity: bg_opacity, }; shader.update_projection(*size.width as f32, *size.height as f32); @@ -997,6 +1003,12 @@ impl ShaderProgram { } } + fn set_bg_opacity(&self, bg_opacity: f32) { + unsafe { + gl::Uniform1f(self.u_bg_opacity, bg_opacity); + } + } + fn create_program(vertex: GLuint, fragment: GLuint) -> GLuint { unsafe { let program = gl::CreateProgram(); |