reduce to a single draw call
Taking further advantage of dynamic quad allocation, we can now remove the multiple render passes in favor of allocating the quads and painting them from back to front. In turn, this means that we can reduce the amount of data that we store in the vertex, which simplifies the shaders a bit, at the expense of making the render code in rust a bit more complex. However, we can take advantage of stretching runs of cells with background colors in to a single quad. refs: #986
This commit is contained in:
1 parent
9a8b2e1e81
commit
725572de9c
13 files changed
+251
-480
No files matched your search
@@ -205,7 +205,7 @@ impl SrgbaPixel {
|
||||
}
|
||||
|
||||
/// A pixel value encoded as linear RGBA values in f32 format (range: 0.0-1.0)
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
#[derive(Copy, Clone, Debug, Default, PartialEq)]
|
||||
pub struct LinearRgba(f32, f32, f32, f32);
|
||||
|
||||
impl LinearRgba {
|
||||
@@ -232,10 +232,12 @@ impl LinearRgba {
|
||||
}
|
||||
|
||||
/// Create using the provided f32 components in the range 0.0-1.0
|
||||
pub fn with_components(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||
pub const fn with_components(red: f32, green: f32, blue: f32, alpha: f32) -> Self {
|
||||
Self(red, green, blue, alpha)
|
||||
}
|
||||
|
||||
pub const TRANSPARENT: Self = Self::with_components(0., 0., 0., 0.);
|
||||
|
||||
/// Convert to an SRGB u32 pixel
|
||||
pub fn srgba_pixel(self) -> SrgbaPixel {
|
||||
SrgbaPixel::rgba(
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
// This shader is responsible for coloring the window background.
|
||||
|
||||
// Note: fragment-common.glsl is automatically prepended!
|
||||
|
||||
uniform sampler2D atlas_linear_sampler;
|
||||
|
||||
void main() {
|
||||
if (o_has_color == 2.0) {
|
||||
// We're the window background image.
|
||||
color = sample_texture(atlas_linear_sampler, o_tex);
|
||||
// Apply window_background_image_opacity to the background image
|
||||
color.a = o_bg_color.a;
|
||||
} else if (o_has_color == 3.0) {
|
||||
color = o_bg_color;
|
||||
} else {
|
||||
// Nothing else should render on the background layer
|
||||
discard;
|
||||
}
|
||||
color = apply_hsv(color, o_hsv);
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
// This is the window background shader.
|
||||
// It places the background image in the full viewport.
|
||||
|
||||
// Note: vertex-common.glsl is automatically prepended!
|
||||
|
||||
void main() {
|
||||
pass_through_vertex();
|
||||
|
||||
if (o_has_color == 2.0) {
|
||||
// Background image takes up its full coordinates
|
||||
gl_Position = projection * vec4(position, 0.0, 1.0);
|
||||
} else {
|
||||
// Nothing else should render on the background layer
|
||||
gl_Position = off_screen();
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,9 @@
|
||||
precision highp float;
|
||||
|
||||
in float o_has_color;
|
||||
in vec2 o_cursor;
|
||||
in vec2 o_tex;
|
||||
in vec2 o_underline;
|
||||
in vec3 o_hsv;
|
||||
in vec4 o_bg_color;
|
||||
in vec4 o_cursor_color;
|
||||
in vec4 o_fg_color;
|
||||
in vec4 o_underline_color;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
@@ -88,6 +83,15 @@ vec4 colorize(vec4 glyph, vec4 color, vec4 background) {
|
||||
// return vec4(glyph.rgb * color.rgb, glyph.a);
|
||||
}
|
||||
|
||||
vec4 colorize2(vec4 glyph, vec4 color) {
|
||||
float r = glyph.r * color.r;// + (1.0 - glyph.r) * background.r;
|
||||
float g = glyph.g * color.g;// + (1.0 - glyph.g) * background.g;
|
||||
float b = glyph.b * color.b;// + (1.0 - glyph.b) * background.b;
|
||||
|
||||
return vec4(r, g, b, glyph.a);
|
||||
// return vec4(glyph.rgb * color.rgb, glyph.a);
|
||||
}
|
||||
|
||||
vec4 from_linear(vec4 v) {
|
||||
return pow(v, vec4(2.2));
|
||||
}
|
||||
|
||||
@@ -4,29 +4,20 @@
|
||||
// Note: fragment-common.glsl is automatically prepended!
|
||||
|
||||
uniform sampler2D atlas_nearest_sampler;
|
||||
uniform sampler2D atlas_linear_sampler;
|
||||
|
||||
void main() {
|
||||
if (o_has_color >= 2.0) {
|
||||
// Don't render the background image on anything other than
|
||||
// the window_bg_layer.
|
||||
discard;
|
||||
return;
|
||||
}
|
||||
|
||||
color = sample_texture(atlas_nearest_sampler, o_tex);
|
||||
if (o_has_color == 0.0) {
|
||||
// if it's not a color emoji it will be grayscale
|
||||
// and we need to tint with the fg_color
|
||||
if (o_fg_color == o_bg_color) {
|
||||
// However, if we're a monochrome glyph and the foreground and
|
||||
// background colors are the same, just render a transparent pixel
|
||||
// instead; this avoids generating shadowy anti-aliasing artifacts
|
||||
// for something that should otherwise be invisible.
|
||||
color = vec4(0.0, 0.0, 0.0, 0.0);
|
||||
discard;
|
||||
return;
|
||||
} else {
|
||||
color = colorize(color, o_fg_color, o_bg_color);
|
||||
if (o_has_color == 2.0) {
|
||||
// The window background attachment
|
||||
color = sample_texture(atlas_linear_sampler, o_tex);
|
||||
// Apply window_background_image_opacity to the background image
|
||||
color.a = o_fg_color.a;
|
||||
} else {
|
||||
color = sample_texture(atlas_nearest_sampler, o_tex);
|
||||
if (o_has_color == 0.0) {
|
||||
// if it's not a color emoji it will be grayscale
|
||||
// and we need to tint with the fg_color
|
||||
color = colorize2(color, o_fg_color);
|
||||
color = apply_hsv(color, foreground_text_hsb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,6 @@
|
||||
void main() {
|
||||
pass_through_vertex();
|
||||
|
||||
if (o_has_color == 2.0) {
|
||||
// If we're the background image and we're not rendering
|
||||
// the background layer, then move this off screen
|
||||
gl_Position = off_screen();
|
||||
} else {
|
||||
// Use only the adjusted cell position to render the glyph
|
||||
gl_Position = projection * vec4(position + adjust, 0.0, 1.0);
|
||||
}
|
||||
// Use only the adjusted cell position to render the glyph
|
||||
gl_Position = projection * vec4(position + adjust, 0.0, 1.0);
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// This shader is responsible for coloring the underline and
|
||||
// glyph background graphics.
|
||||
|
||||
// Note: fragment-common.glsl is automatically prepended!
|
||||
|
||||
uniform sampler2D atlas_nearest_sampler;
|
||||
|
||||
void main() {
|
||||
if (o_has_color >= 2.0) {
|
||||
// Don't render the background image on anything other than
|
||||
// the window_bg_layer.
|
||||
discard;
|
||||
return;
|
||||
}
|
||||
|
||||
// Note that o_bg_color is set to transparent if the background
|
||||
// color is "default" and there is a window background attachment
|
||||
color = o_bg_color;
|
||||
|
||||
// Sample the underline glyph texture for this location.
|
||||
// Note that the texture is whitespace in the case where this is
|
||||
// no underline or strikethrough.
|
||||
vec4 under_color = sample_texture(atlas_nearest_sampler, o_underline);
|
||||
if (under_color.a != 0.0) {
|
||||
// if the underline glyph isn't transparent in this position then
|
||||
// we overlay the underline color, otherwise we'll leave the color
|
||||
// at the background color.
|
||||
color = color * (1.0 - under_color) + under_color * o_underline_color;
|
||||
}
|
||||
|
||||
// Similar to the above: if the cursor texture isn't transparent
|
||||
// in this location, we'll use the cursor color instead of the background.
|
||||
// The cursor color overrides any underline color we might have picked
|
||||
// in the section above.
|
||||
vec4 cursor_outline = sample_texture(atlas_nearest_sampler, o_cursor);
|
||||
if (cursor_outline.a != 0.0) {
|
||||
color = o_cursor_color;
|
||||
}
|
||||
|
||||
color = apply_hsv(color, o_hsv);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
// This is the underline/strikethrough and text-background color
|
||||
// shader. It is responsible for locating the cell boundaries.
|
||||
|
||||
// Note: vertex-common.glsl is automatically prepended!
|
||||
|
||||
void main() {
|
||||
pass_through_vertex();
|
||||
|
||||
if (o_has_color == 2.0) {
|
||||
// If we're the background image and we're not rendering
|
||||
// the background layer, then move this off screen
|
||||
gl_Position = off_screen();
|
||||
} else {
|
||||
// Want to fill the whole cell when painting backgrounds
|
||||
gl_Position = projection * vec4(position, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
+1
-54
@@ -21,14 +21,7 @@ pub struct Vertex {
|
||||
pub adjust: (f32, f32),
|
||||
// glyph texture
|
||||
pub tex: (f32, f32),
|
||||
// underline texture
|
||||
pub underline: (f32, f32),
|
||||
// cursor texture
|
||||
pub cursor: (f32, f32),
|
||||
pub cursor_color: (f32, f32, f32, f32),
|
||||
pub bg_color: (f32, f32, f32, f32),
|
||||
pub fg_color: (f32, f32, f32, f32),
|
||||
pub underline_color: (f32, f32, f32, f32),
|
||||
pub hsv: (f32, f32, f32),
|
||||
// We use a float for this because I can't get
|
||||
// bool or integer values to work:
|
||||
@@ -44,20 +37,7 @@ pub struct Vertex {
|
||||
// image, we use the solid bg color
|
||||
pub has_color: f32,
|
||||
}
|
||||
::window::glium::implement_vertex!(
|
||||
Vertex,
|
||||
position,
|
||||
adjust,
|
||||
tex,
|
||||
underline,
|
||||
cursor,
|
||||
cursor_color,
|
||||
bg_color,
|
||||
fg_color,
|
||||
underline_color,
|
||||
hsv,
|
||||
has_color
|
||||
);
|
||||
::window::glium::implement_vertex!(Vertex, position, adjust, tex, fg_color, hsv, has_color);
|
||||
|
||||
/// A helper for updating the 4 vertices that compose a glyph cell
|
||||
pub struct Quad<'a> {
|
||||
@@ -109,39 +89,6 @@ impl<'a> Quad<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_underline_color(&mut self, color: LinearRgba) {
|
||||
for v in self.vert.iter_mut() {
|
||||
v.underline_color = color.tuple();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_bg_color(&mut self, color: LinearRgba) {
|
||||
for v in self.vert.iter_mut() {
|
||||
v.bg_color = color.tuple();
|
||||
}
|
||||
}
|
||||
|
||||
/// Assign the underline texture coordinates for the cell
|
||||
pub fn set_underline(&mut self, coords: TextureRect) {
|
||||
self.vert[V_TOP_LEFT].underline = (coords.min_x(), coords.min_y());
|
||||
self.vert[V_TOP_RIGHT].underline = (coords.max_x(), coords.min_y());
|
||||
self.vert[V_BOT_LEFT].underline = (coords.min_x(), coords.max_y());
|
||||
self.vert[V_BOT_RIGHT].underline = (coords.max_x(), coords.max_y());
|
||||
}
|
||||
|
||||
pub fn set_cursor(&mut self, coords: TextureRect) {
|
||||
self.vert[V_TOP_LEFT].cursor = (coords.min_x(), coords.min_y());
|
||||
self.vert[V_TOP_RIGHT].cursor = (coords.max_x(), coords.min_y());
|
||||
self.vert[V_BOT_LEFT].cursor = (coords.min_x(), coords.max_y());
|
||||
self.vert[V_BOT_RIGHT].cursor = (coords.max_x(), coords.max_y());
|
||||
}
|
||||
|
||||
pub fn set_cursor_color(&mut self, color: LinearRgba) {
|
||||
for v in self.vert.iter_mut() {
|
||||
v.cursor_color = color.tuple();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_hsv(&mut self, hsv: Option<config::HsbTransform>) {
|
||||
let s = hsv
|
||||
.map(|t| (t.hue, t.saturation, t.brightness))
|
||||
|
||||
@@ -106,8 +106,6 @@ pub struct RenderState {
|
||||
pub context: Rc<GliumContext>,
|
||||
pub glyph_cache: RefCell<GlyphCache<SrgbTexture2d>>,
|
||||
pub util_sprites: UtilSprites<SrgbTexture2d>,
|
||||
pub background_prog: glium::Program,
|
||||
pub line_prog: glium::Program,
|
||||
pub glyph_prog: glium::Program,
|
||||
pub glyph_vertex_buffer: TripleVertexBuffer,
|
||||
}
|
||||
@@ -125,12 +123,6 @@ impl RenderState {
|
||||
let result = UtilSprites::new(&mut *glyph_cache.borrow_mut(), metrics);
|
||||
match result {
|
||||
Ok(util_sprites) => {
|
||||
let do_gamma = cfg!(target_os = "macos");
|
||||
|
||||
let background_prog =
|
||||
Self::compile_prog(&context, do_gamma, Self::background_shader)?;
|
||||
let line_prog = Self::compile_prog(&context, do_gamma, Self::line_shader)?;
|
||||
|
||||
// Last prog outputs srgb for gamma correction
|
||||
let glyph_prog = Self::compile_prog(&context, true, Self::glyph_shader)?;
|
||||
|
||||
@@ -140,8 +132,6 @@ impl RenderState {
|
||||
context,
|
||||
glyph_cache,
|
||||
util_sprites,
|
||||
background_prog,
|
||||
line_prog,
|
||||
glyph_prog,
|
||||
glyph_vertex_buffer,
|
||||
});
|
||||
@@ -212,40 +202,6 @@ impl RenderState {
|
||||
)
|
||||
}
|
||||
|
||||
fn line_shader(version: &str) -> (String, String) {
|
||||
(
|
||||
format!(
|
||||
"#version {}\n{}\n{}",
|
||||
version,
|
||||
include_str!("vertex-common.glsl"),
|
||||
include_str!("line-vertex.glsl")
|
||||
),
|
||||
format!(
|
||||
"#version {}\n{}\n{}",
|
||||
version,
|
||||
include_str!("fragment-common.glsl"),
|
||||
include_str!("line-frag.glsl")
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fn background_shader(version: &str) -> (String, String) {
|
||||
(
|
||||
format!(
|
||||
"#version {}\n{}\n{}",
|
||||
version,
|
||||
include_str!("vertex-common.glsl"),
|
||||
include_str!("background-vertex.glsl")
|
||||
),
|
||||
format!(
|
||||
"#version {}\n{}\n{}",
|
||||
version,
|
||||
include_str!("fragment-common.glsl"),
|
||||
include_str!("background-frag.glsl")
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/// Compute a vertex buffer to hold the quads that comprise the visible
|
||||
/// portion of the screen. We recreate this when the screen is resized.
|
||||
/// The idea is that we want to minimize any heavy lifting and computation
|
||||
|
||||
@@ -21,7 +21,7 @@ use smol::Timer;
|
||||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
|
||||
use termwiz::cell::Blink;
|
||||
use termwiz::cell::{unicode_column_width, Blink};
|
||||
use termwiz::cellcluster::CellCluster;
|
||||
use termwiz::surface::{CursorShape, CursorVisibility};
|
||||
use wezterm_font::units::PixelLength;
|
||||
@@ -44,6 +44,7 @@ pub struct RenderScreenLineOpenGLParams<'a> {
|
||||
pub pos: &'a PositionedPane,
|
||||
|
||||
pub white_space: TextureRect,
|
||||
pub filled_box: TextureRect,
|
||||
|
||||
pub cursor_border_color: LinearRgba,
|
||||
pub foreground: LinearRgba,
|
||||
@@ -245,6 +246,7 @@ impl super::TermWindow {
|
||||
let cursor_border_color = rgbcolor_to_window_color(palette.cursor_border);
|
||||
let foreground = rgbcolor_to_window_color(palette.foreground);
|
||||
let white_space = gl_state.util_sprites.white_space.texture_coords();
|
||||
let filled_box = gl_state.util_sprites.filled_box.texture_coords();
|
||||
|
||||
let window_is_transparent =
|
||||
self.window_background.is_some() || config.window_background_opacity != 1.0;
|
||||
@@ -258,6 +260,32 @@ impl super::TermWindow {
|
||||
},
|
||||
);
|
||||
|
||||
if pos.index == 0 {
|
||||
// Render the window background image
|
||||
if let Some(im) = self.window_background.as_ref() {
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(
|
||||
self.dimensions.pixel_width as f32 / -2.,
|
||||
self.dimensions.pixel_height as f32 / -2.,
|
||||
self.dimensions.pixel_width as f32 / 2.,
|
||||
self.dimensions.pixel_height as f32 / 2.,
|
||||
);
|
||||
|
||||
let background_image_alpha = (config.window_background_opacity * 255.0) as u8;
|
||||
let color =
|
||||
rgbcolor_alpha_to_window_color(palette.background, background_image_alpha);
|
||||
|
||||
let (sprite, next_due) =
|
||||
gl_state.glyph_cache.borrow_mut().cached_image(im, None)?;
|
||||
self.update_next_frame_time(next_due);
|
||||
quad.set_texture(sprite.texture_coords());
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_is_background_image();
|
||||
quad.set_hsv(config.window_background_image_hsb);
|
||||
quad.set_fg_color(color);
|
||||
}
|
||||
}
|
||||
|
||||
if self.show_tab_bar && pos.index == 0 {
|
||||
let tab_dims = RenderableDimensions {
|
||||
cols: self.terminal_size.cols as _,
|
||||
@@ -294,6 +322,7 @@ impl super::TermWindow {
|
||||
cursor_fg: LinearRgba::default(),
|
||||
cursor_bg: LinearRgba::default(),
|
||||
white_space,
|
||||
filled_box,
|
||||
window_is_transparent,
|
||||
default_bg,
|
||||
},
|
||||
@@ -335,49 +364,12 @@ impl super::TermWindow {
|
||||
let right = self.dimensions.pixel_width as f32 / 2.;
|
||||
let left = right - padding;
|
||||
|
||||
quad.set_bg_color(color);
|
||||
quad.set_fg_color(color);
|
||||
quad.set_underline_color(color);
|
||||
quad.set_position(left, top, right, bottom);
|
||||
quad.set_texture(white_space);
|
||||
quad.set_texture(filled_box);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(None);
|
||||
quad.set_underline(white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_cursor(white_space);
|
||||
quad.set_cursor_color(rgbcolor_to_window_color(background_color));
|
||||
}
|
||||
|
||||
{
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_underline(white_space);
|
||||
quad.set_cursor(white_space);
|
||||
quad.set_position(
|
||||
self.dimensions.pixel_width as f32 / -2.,
|
||||
self.dimensions.pixel_height as f32 / -2.,
|
||||
self.dimensions.pixel_width as f32 / 2.,
|
||||
self.dimensions.pixel_height as f32 / 2.,
|
||||
);
|
||||
|
||||
let background_image_alpha = (config.window_background_opacity * 255.0) as u8;
|
||||
let color = rgbcolor_alpha_to_window_color(palette.background, background_image_alpha);
|
||||
|
||||
if let Some(im) = self.window_background.as_ref() {
|
||||
let (sprite, next_due) =
|
||||
gl_state.glyph_cache.borrow_mut().cached_image(im, None)?;
|
||||
self.update_next_frame_time(next_due);
|
||||
quad.set_texture(sprite.texture_coords());
|
||||
quad.set_is_background_image();
|
||||
} else {
|
||||
quad.set_texture(white_space);
|
||||
quad.set_is_background();
|
||||
}
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(config.window_background_image_hsb);
|
||||
quad.set_cursor_color(color);
|
||||
quad.set_fg_color(color);
|
||||
quad.set_underline_color(color);
|
||||
quad.set_bg_color(color);
|
||||
}
|
||||
|
||||
let selrange = self.selection(pos.pane.pane_id()).range.clone();
|
||||
@@ -411,6 +403,7 @@ impl super::TermWindow {
|
||||
cursor_fg,
|
||||
cursor_bg,
|
||||
white_space,
|
||||
filled_box,
|
||||
window_is_transparent,
|
||||
default_bg,
|
||||
},
|
||||
@@ -482,33 +475,6 @@ impl super::TermWindow {
|
||||
|
||||
let vertices = vb.current_vb();
|
||||
|
||||
// Pass 1: Draw backgrounds
|
||||
frame.draw(
|
||||
vertices.slice(0..vertex_count).unwrap(),
|
||||
vb.indices.slice(0..index_count).unwrap(),
|
||||
&gl_state.background_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
foreground_text_hsb: foreground_text_hsb,
|
||||
},
|
||||
&alpha_blending,
|
||||
)?;
|
||||
|
||||
// Pass 2: strikethrough and underline
|
||||
frame.draw(
|
||||
vertices.slice(0..vertex_count).unwrap(),
|
||||
vb.indices.slice(0..index_count).unwrap(),
|
||||
&gl_state.line_prog,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
atlas_nearest_sampler: atlas_nearest_sampler,
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
foreground_text_hsb: foreground_text_hsb,
|
||||
},
|
||||
&alpha_blending,
|
||||
)?;
|
||||
|
||||
// Use regular alpha blending when we draw the glyphs!
|
||||
// This is trying to avoid an issue that is most prevalent
|
||||
// on Wayland and X11. If our glyph pixels end up with alpha
|
||||
@@ -549,7 +515,6 @@ impl super::TermWindow {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
// Pass 3: Draw glyphs
|
||||
frame.draw(
|
||||
vertices.slice(0..vertex_count).unwrap(),
|
||||
vb.indices.slice(0..index_count).unwrap(),
|
||||
@@ -560,7 +525,8 @@ impl super::TermWindow {
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
foreground_text_hsb: foreground_text_hsb,
|
||||
},
|
||||
&blend_but_set_alpha_to_one,
|
||||
//&blend_but_set_alpha_to_one,
|
||||
&alpha_blending,
|
||||
)?;
|
||||
|
||||
vb.next_index();
|
||||
@@ -577,7 +543,6 @@ impl super::TermWindow {
|
||||
let vb = &gl_state.glyph_vertex_buffer;
|
||||
let mut vb_mut = vb.current_vb_mut();
|
||||
let mut quads = vb.map(&mut vb_mut);
|
||||
let config = &self.config;
|
||||
let block = BlockKey::from_char(if split.direction == SplitDirection::Horizontal {
|
||||
'\u{2502}'
|
||||
} else {
|
||||
@@ -586,21 +551,12 @@ impl super::TermWindow {
|
||||
.expect("to have box drawing glyph");
|
||||
let palette = pane.palette();
|
||||
let foreground = rgbcolor_to_window_color(palette.split);
|
||||
let background = rgbcolor_alpha_to_window_color(
|
||||
palette.background,
|
||||
if self.window_background.is_some() || config.window_background_opacity != 1.0 {
|
||||
0x00
|
||||
} else {
|
||||
(config.text_background_opacity * 255.0) as u8
|
||||
},
|
||||
);
|
||||
|
||||
let first_row_offset = if self.show_tab_bar && !self.config.tab_bar_at_bottom {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let white_space = gl_state.util_sprites.white_space.texture_coords();
|
||||
|
||||
let x_y_iter: Box<dyn Iterator<Item = (usize, usize)>> =
|
||||
if split.direction == SplitDirection::Horizontal {
|
||||
@@ -627,15 +583,10 @@ impl super::TermWindow {
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
|
||||
quad.set_fg_color(foreground);
|
||||
quad.set_underline_color(foreground);
|
||||
quad.set_bg_color(background);
|
||||
quad.set_hsv(None);
|
||||
quad.set_texture(sprite);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_underline(white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_cursor(white_space);
|
||||
quad.set_cursor_color(background);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -719,6 +670,79 @@ impl super::TermWindow {
|
||||
}
|
||||
let mut last_style = None;
|
||||
|
||||
// Make a pass to compute background colors.
|
||||
// Need to consider:
|
||||
// * background when it is not the default color
|
||||
// * Reverse video attribute
|
||||
for cluster in &cell_clusters {
|
||||
let attrs = &cluster.attrs;
|
||||
let cluster_width = unicode_column_width(&cluster.text);
|
||||
|
||||
let bg_is_default = attrs.background() == ColorAttribute::Default;
|
||||
let bg_color = params.palette.resolve_bg(attrs.background());
|
||||
|
||||
let fg_color =
|
||||
resolve_fg_color_attr(&attrs, attrs.foreground(), ¶ms, &Default::default());
|
||||
|
||||
let (bg_color, bg_is_default) = {
|
||||
let mut fg = fg_color;
|
||||
let mut bg = bg_color;
|
||||
let mut bg_default = bg_is_default;
|
||||
|
||||
// Check the line reverse_video flag and flip.
|
||||
if attrs.reverse() == !params.line.is_reverse() {
|
||||
std::mem::swap(&mut fg, &mut bg);
|
||||
bg_default = false;
|
||||
}
|
||||
|
||||
(rgbcolor_to_window_color(bg), bg_default)
|
||||
};
|
||||
|
||||
if !bg_is_default {
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (current_idx + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_x + cluster_width as f32 * cell_width,
|
||||
pos_y + cell_height,
|
||||
);
|
||||
quad.set_fg_color(bg_color);
|
||||
quad.set_texture(params.filled_box);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_has_color(false);
|
||||
}
|
||||
|
||||
current_idx += cluster_width;
|
||||
}
|
||||
|
||||
// Render the selection background color
|
||||
if !params.selection.is_empty() {
|
||||
let mut quad = quads.allocate()?;
|
||||
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (params.selection.start + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
quad.set_position(
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_x + (params.selection.end - params.selection.start) as f32 * cell_width,
|
||||
pos_y + cell_height,
|
||||
);
|
||||
|
||||
quad.set_fg_color(params.selection_bg);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_texture(params.filled_box);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(hsv);
|
||||
}
|
||||
|
||||
current_idx = 0;
|
||||
|
||||
for cluster in &cell_clusters {
|
||||
if !matches!(last_style.as_ref(), Some(ClusterStyleCache{attrs,..}) if *attrs == &cluster.attrs)
|
||||
{
|
||||
@@ -868,6 +892,41 @@ impl super::TermWindow {
|
||||
cursor_bg: params.cursor_bg,
|
||||
});
|
||||
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (cell_idx + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
|
||||
if bg_color != style_params.bg_color {
|
||||
// Override the background color
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_fg_color(bg_color);
|
||||
quad.set_texture(params.filled_box);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_has_color(false);
|
||||
}
|
||||
|
||||
if cursor_shape.is_some() {
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_has_color(false);
|
||||
|
||||
quad.set_texture(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_fg_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
params.cursor_border_color
|
||||
});
|
||||
}
|
||||
|
||||
let images = cluster.attrs.images().unwrap_or_else(|| vec![]);
|
||||
|
||||
for img in &images {
|
||||
@@ -879,30 +938,39 @@ impl super::TermWindow {
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
cursor_shape,
|
||||
glyph_color,
|
||||
style_params.underline_color,
|
||||
bg_color,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Underlines
|
||||
if style_params.underline_tex_rect != params.white_space {
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_has_color(false);
|
||||
|
||||
quad.set_texture(style_params.underline_tex_rect);
|
||||
quad.set_fg_color(style_params.underline_color);
|
||||
}
|
||||
|
||||
let mut did_custom = false;
|
||||
|
||||
if self.config.custom_block_glyphs && glyph_idx == 0 {
|
||||
if let Some(cell) = params.line.cells().get(cell_idx) {
|
||||
if let Some(block) = BlockKey::from_cell(cell) {
|
||||
self.populate_block_quad(
|
||||
block,
|
||||
gl_state,
|
||||
quads,
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
cursor_shape,
|
||||
glyph_color,
|
||||
style_params.underline_color,
|
||||
bg_color,
|
||||
)?;
|
||||
if glyph_color != bg_color {
|
||||
self.populate_block_quad(
|
||||
block,
|
||||
gl_state,
|
||||
quads,
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
glyph_color,
|
||||
)?;
|
||||
}
|
||||
did_custom = true;
|
||||
}
|
||||
}
|
||||
@@ -940,38 +1008,28 @@ impl super::TermWindow {
|
||||
// `left` value to be 0 when glyph_idx > 0.
|
||||
slice_left = right;
|
||||
|
||||
let mut quad = quads.allocate()?;
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (cell_idx + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_fg_color(glyph_color);
|
||||
quad.set_bg_color(bg_color);
|
||||
quad.set_texture(texture_rect);
|
||||
quad.set_texture_adjust(left, top, right, bottom);
|
||||
quad.set_underline(style_params.underline_tex_rect);
|
||||
quad.set_underline_color(style_params.underline_color);
|
||||
quad.set_hsv(if glyph.brightness_adjust != 1.0 {
|
||||
let hsv = hsv.unwrap_or_else(|| HsbTransform::default());
|
||||
Some(HsbTransform {
|
||||
brightness: hsv.brightness * glyph.brightness_adjust,
|
||||
..hsv
|
||||
})
|
||||
} else {
|
||||
hsv
|
||||
});
|
||||
quad.set_has_color(glyph.has_color);
|
||||
quad.set_cursor(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_cursor_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
params.cursor_border_color
|
||||
});
|
||||
if glyph_color != bg_color || glyph.has_color {
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_x + cell_width,
|
||||
pos_y + cell_height,
|
||||
);
|
||||
quad.set_fg_color(glyph_color);
|
||||
quad.set_texture(texture_rect);
|
||||
quad.set_texture_adjust(left, top, right, bottom);
|
||||
quad.set_hsv(if glyph.brightness_adjust != 1.0 {
|
||||
let hsv = hsv.unwrap_or_else(|| HsbTransform::default());
|
||||
Some(HsbTransform {
|
||||
brightness: hsv.brightness * glyph.brightness_adjust,
|
||||
..hsv
|
||||
})
|
||||
} else {
|
||||
hsv
|
||||
});
|
||||
quad.set_has_color(glyph.has_color);
|
||||
}
|
||||
}
|
||||
|
||||
for img in &images {
|
||||
@@ -983,10 +1041,7 @@ impl super::TermWindow {
|
||||
cell_idx,
|
||||
¶ms,
|
||||
hsv,
|
||||
cursor_shape,
|
||||
glyph_color,
|
||||
style_params.underline_color,
|
||||
bg_color,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -998,76 +1053,35 @@ impl super::TermWindow {
|
||||
// If the clusters don't extend to the full physical width of the display,
|
||||
// we have a little bit more work to do to ensure that we correctly paint:
|
||||
// * Selection
|
||||
// * Cursor (although it is really unlikely that the cursor is outside
|
||||
// of one of the clusters)
|
||||
// * Cursor
|
||||
let right_fill_start = Instant::now();
|
||||
if last_cell_idx < num_cols {
|
||||
let mut reverse_left = 0..0;
|
||||
let mut reverse_right = last_cell_idx..num_cols;
|
||||
|
||||
// Render the selection beyond the end of the line
|
||||
if let Some(sel_range) =
|
||||
rangeset::range_intersection(¶ms.selection, &(last_cell_idx + 1..num_cols))
|
||||
{
|
||||
// revise the reverse video range
|
||||
reverse_left = last_cell_idx..sel_range.start;
|
||||
reverse_right = sel_range.end..num_cols;
|
||||
|
||||
if params.line.is_reverse() {
|
||||
let mut quad = quads.allocate()?;
|
||||
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (sel_range.start + params.pos.left) as f32 * cell_width
|
||||
+ (last_cell_idx + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
quad.set_position(
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_x + (sel_range.end - sel_range.start) as f32 * cell_width,
|
||||
pos_x + (num_cols - last_cell_idx) as f32 * cell_width,
|
||||
pos_y + cell_height,
|
||||
);
|
||||
|
||||
quad.set_bg_color(params.selection_bg);
|
||||
quad.set_fg_color(params.selection_fg);
|
||||
quad.set_fg_color(params.foreground);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_texture(params.white_space);
|
||||
quad.set_underline_color(params.selection_fg);
|
||||
quad.set_underline(params.white_space);
|
||||
quad.set_cursor(params.white_space);
|
||||
quad.set_texture(params.filled_box);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(hsv);
|
||||
}
|
||||
|
||||
if params.line.is_reverse() {
|
||||
for r in [reverse_left, reverse_right] {
|
||||
let mut quad = quads.allocate()?;
|
||||
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (r.start + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
quad.set_position(
|
||||
pos_x,
|
||||
pos_y,
|
||||
pos_x + (r.end - r.start) as f32 * cell_width,
|
||||
pos_y + cell_height,
|
||||
);
|
||||
|
||||
quad.set_bg_color(params.foreground); // reverse video
|
||||
quad.set_fg_color(params.default_bg);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_texture(params.white_space);
|
||||
quad.set_underline_color(params.selection_fg);
|
||||
quad.set_underline(params.white_space);
|
||||
quad.set_cursor(params.white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(hsv);
|
||||
}
|
||||
}
|
||||
|
||||
if params.stable_line_idx == Some(params.cursor.y)
|
||||
&& ((params.cursor.x > last_cell_idx) || cell_clusters.is_empty())
|
||||
{
|
||||
// Compute the cursor fg/bg
|
||||
let ComputeCellFgBgResult {
|
||||
fg_color: glyph_color,
|
||||
fg_color: _glyph_color,
|
||||
bg_color,
|
||||
cursor_shape,
|
||||
} = self.compute_cell_fg_bg(ComputeCellFgBgParams {
|
||||
@@ -1086,31 +1100,34 @@ impl super::TermWindow {
|
||||
cursor_bg: params.cursor_bg,
|
||||
});
|
||||
|
||||
let mut quad = quads.allocate()?;
|
||||
let pos_x = (self.dimensions.pixel_width as f32 / -2.)
|
||||
+ (params.cursor.x + params.pos.left) as f32 * cell_width
|
||||
+ self.config.window_padding.left as f32;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
|
||||
quad.set_texture(params.white_space);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_underline(params.white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(hsv);
|
||||
for (tex, color) in [
|
||||
(params.filled_box, bg_color),
|
||||
(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
params.cursor_border_color,
|
||||
),
|
||||
] {
|
||||
let mut quad = quads.allocate()?;
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
|
||||
quad.set_bg_color(bg_color);
|
||||
quad.set_fg_color(glyph_color);
|
||||
quad.set_cursor(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_cursor_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
params.cursor_border_color
|
||||
});
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_has_color(false);
|
||||
quad.set_hsv(hsv);
|
||||
|
||||
quad.set_texture(tex);
|
||||
quad.set_fg_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
color
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
metrics::histogram!(
|
||||
@@ -1135,10 +1152,7 @@ impl super::TermWindow {
|
||||
cell_idx: usize,
|
||||
params: &RenderScreenLineOpenGLParams,
|
||||
hsv: Option<config::HsbTransform>,
|
||||
cursor_shape: Option<CursorShape>,
|
||||
glyph_color: LinearRgba,
|
||||
underline_color: LinearRgba,
|
||||
bg_color: LinearRgba,
|
||||
) -> anyhow::Result<()> {
|
||||
let sprite = gl_state
|
||||
.glyph_cache
|
||||
@@ -1158,24 +1172,9 @@ impl super::TermWindow {
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_fg_color(glyph_color);
|
||||
quad.set_underline_color(underline_color);
|
||||
quad.set_bg_color(bg_color);
|
||||
quad.set_texture(sprite);
|
||||
quad.set_texture_adjust(0., 0., 0., 0.);
|
||||
quad.set_underline(params.white_space);
|
||||
quad.set_has_color(false);
|
||||
quad.set_cursor(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_cursor_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
params.cursor_border_color
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1188,10 +1187,7 @@ impl super::TermWindow {
|
||||
cell_idx: usize,
|
||||
params: &RenderScreenLineOpenGLParams,
|
||||
hsv: Option<config::HsbTransform>,
|
||||
cursor_shape: Option<CursorShape>,
|
||||
glyph_color: LinearRgba,
|
||||
underline_color: LinearRgba,
|
||||
bg_color: LinearRgba,
|
||||
) -> anyhow::Result<()> {
|
||||
let padding = self
|
||||
.render_metrics
|
||||
@@ -1248,29 +1244,14 @@ impl super::TermWindow {
|
||||
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
|
||||
quad.set_hsv(hsv);
|
||||
quad.set_fg_color(glyph_color);
|
||||
quad.set_underline_color(underline_color);
|
||||
quad.set_bg_color(bg_color);
|
||||
quad.set_texture(texture_rect);
|
||||
quad.set_underline(params.white_space);
|
||||
quad.set_has_color(true);
|
||||
quad.set_cursor(
|
||||
gl_state
|
||||
.util_sprites
|
||||
.cursor_sprite(cursor_shape)
|
||||
.texture_coords(),
|
||||
);
|
||||
quad.set_cursor_color(if self.config.force_reverse_video_cursor {
|
||||
bg_color
|
||||
} else {
|
||||
params.cursor_border_color
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn compute_cell_fg_bg(&self, params: ComputeCellFgBgParams) -> ComputeCellFgBgResult {
|
||||
let selected = params.selection.contains(¶ms.cell_idx);
|
||||
|
||||
let is_cursor =
|
||||
params.stable_line_idx == Some(params.cursor.y) && params.cursor.x == params.cell_idx;
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ impl RenderMetrics {
|
||||
|
||||
pub struct UtilSprites<T: Texture2d> {
|
||||
pub white_space: Sprite<T>,
|
||||
pub filled_box: Sprite<T>,
|
||||
pub cursor_box: Sprite<T>,
|
||||
pub cursor_i_beam: Sprite<T>,
|
||||
pub cursor_underline: Sprite<T>,
|
||||
@@ -78,6 +79,9 @@ impl<T: Texture2d> UtilSprites<T> {
|
||||
|
||||
let cell_rect = Rect::new(Point::new(0, 0), metrics.cell_size);
|
||||
|
||||
buffer.clear_rect(cell_rect, white);
|
||||
let filled_box = glyph_cache.atlas.allocate(&buffer)?;
|
||||
|
||||
buffer.clear_rect(cell_rect, black);
|
||||
let white_space = glyph_cache.atlas.allocate(&buffer)?;
|
||||
|
||||
@@ -169,6 +173,7 @@ impl<T: Texture2d> UtilSprites<T> {
|
||||
|
||||
Ok(Self {
|
||||
white_space,
|
||||
filled_box,
|
||||
cursor_box,
|
||||
cursor_i_beam,
|
||||
cursor_underline,
|
||||
|
||||
@@ -6,36 +6,21 @@ precision highp float;
|
||||
in vec2 position;
|
||||
in vec2 adjust;
|
||||
in vec2 tex;
|
||||
in vec2 underline;
|
||||
in vec4 bg_color;
|
||||
in vec4 fg_color;
|
||||
in vec4 underline_color;
|
||||
in float has_color;
|
||||
in vec2 cursor;
|
||||
in vec4 cursor_color;
|
||||
in vec3 hsv;
|
||||
|
||||
uniform mat4 projection;
|
||||
|
||||
out float o_has_color;
|
||||
out vec2 o_cursor;
|
||||
out vec2 o_tex;
|
||||
out vec2 o_underline;
|
||||
out vec3 o_hsv;
|
||||
out vec4 o_bg_color;
|
||||
out vec4 o_cursor_color;
|
||||
out vec4 o_fg_color;
|
||||
out vec4 o_underline_color;
|
||||
|
||||
void pass_through_vertex() {
|
||||
o_tex = tex;
|
||||
o_has_color = has_color;
|
||||
o_fg_color = fg_color;
|
||||
o_bg_color = bg_color;
|
||||
o_underline = underline;
|
||||
o_underline_color = underline_color;
|
||||
o_cursor = cursor;
|
||||
o_cursor_color = cursor_color;
|
||||
o_hsv = hsv;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user