1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-24 22:01:47 +03:00

remove draw pass 4

This was added in 365a68dfb8 to free the
orca from its cage.  With the recent dynamic quad allocation changes, we
don't need a distinct 4th pass any more and can simply layer a separate
quad on top of the glyph quad.

refs: #986
This commit is contained in:
Wez Furlong 2021-07-30 17:27:24 -07:00
parent 89586d658e
commit 175ca9f722
7 changed files with 85 additions and 151 deletions

View File

@ -5,7 +5,6 @@ precision highp float;
in float o_has_color;
in vec2 o_cursor;
in vec2 o_tex;
in vec2 o_img_tex;
in vec2 o_underline;
in vec3 o_hsv;
in vec4 o_bg_color;

View File

@ -1,16 +0,0 @@
// This is the per-cell image attachment fragment shader.
// 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;
}
color = sample_texture(atlas_nearest_sampler, o_img_tex);
color = apply_hsv(color, o_hsv);
}

View File

@ -1,16 +0,0 @@
// This is the image vertex shader.
// It is responsible for placing per-cell attached images in the
// correct place on screen.
// 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 {
gl_Position = projection * vec4(position, 0.0, 1.0);
}
}

View File

@ -21,8 +21,6 @@ pub struct Vertex {
pub adjust: (f32, f32),
// glyph texture
pub tex: (f32, f32),
// iterm/sixel/image protocol texture
pub img_tex: (f32, f32),
// underline texture
pub underline: (f32, f32),
// cursor texture
@ -51,7 +49,6 @@ pub struct Vertex {
position,
adjust,
tex,
img_tex,
underline,
cursor,
cursor_color,
@ -76,13 +73,6 @@ impl<'a> Quad<'a> {
self.vert[V_BOT_RIGHT].tex = (coords.max_x(), coords.max_y());
}
pub fn set_image_texture(&mut self, coords: TextureRect) {
self.vert[V_TOP_LEFT].img_tex = (coords.min_x(), coords.min_y());
self.vert[V_TOP_RIGHT].img_tex = (coords.max_x(), coords.min_y());
self.vert[V_BOT_LEFT].img_tex = (coords.min_x(), coords.max_y());
self.vert[V_BOT_RIGHT].img_tex = (coords.max_x(), coords.max_y());
}
/// Apply bearing adjustment for the glyph texture.
pub fn set_texture_adjust(&mut self, left: f32, top: f32, right: f32, bottom: f32) {
self.vert[V_TOP_LEFT].adjust = (left, top);

View File

@ -109,7 +109,6 @@ pub struct RenderState {
pub background_prog: glium::Program,
pub line_prog: glium::Program,
pub glyph_prog: glium::Program,
pub img_prog: glium::Program,
pub glyph_vertex_buffer: TripleVertexBuffer,
}
@ -132,9 +131,8 @@ impl RenderState {
Self::compile_prog(&context, do_gamma, Self::background_shader)?;
let line_prog = Self::compile_prog(&context, do_gamma, Self::line_shader)?;
let glyph_prog = Self::compile_prog(&context, do_gamma, Self::glyph_shader)?;
// Last prog outputs srgb for gamma correction
let img_prog = Self::compile_prog(&context, true, Self::img_shader)?;
let glyph_prog = Self::compile_prog(&context, true, Self::glyph_shader)?;
let glyph_vertex_buffer = Self::compute_vertices(&context, 1024)?;
@ -145,7 +143,6 @@ impl RenderState {
background_prog,
line_prog,
glyph_prog,
img_prog,
glyph_vertex_buffer,
});
}
@ -215,23 +212,6 @@ impl RenderState {
)
}
fn img_shader(version: &str) -> (String, String) {
(
format!(
"#version {}\n{}\n{}",
version,
include_str!("vertex-common.glsl"),
include_str!("img-vertex.glsl")
),
format!(
"#version {}\n{}\n{}",
version,
include_str!("fragment-common.glsl"),
include_str!("img-frag.glsl")
),
)
}
fn line_shader(version: &str) -> (String, String) {
(
format!(

View File

@ -560,20 +560,6 @@ impl super::TermWindow {
atlas_linear_sampler: atlas_linear_sampler,
foreground_text_hsb: foreground_text_hsb,
},
&alpha_blending,
)?;
// Pass 4: Draw image attachments
frame.draw(
vertices.slice(0..vertex_count).unwrap(),
vb.indices.slice(0..index_count).unwrap(),
&gl_state.img_prog,
&uniform! {
projection: projection,
atlas_nearest_sampler: atlas_nearest_sampler,
atlas_linear_sampler: atlas_linear_sampler,
foreground_text_hsb: foreground_text_hsb,
},
&blend_but_set_alpha_to_one,
)?;
@ -882,13 +868,12 @@ impl super::TermWindow {
cursor_bg: params.cursor_bg,
});
if let Some(images) = cluster.attrs.images() {
// FIXME: This is where we need to allocate distinct quads for each of
// these images
let images = cluster.attrs.images().unwrap_or_else(|| vec![]);
for image in images {
for img in &images {
if img.z_index() < 0 {
self.populate_image_quad(
&image,
&img,
gl_state,
quads,
cell_idx,
@ -901,6 +886,7 @@ impl super::TermWindow {
)?;
}
}
let mut did_custom = false;
if self.config.custom_block_glyphs && glyph_idx == 0 {
if let Some(cell) = params.line.cells().get(cell_idx) {
@ -917,75 +903,93 @@ impl super::TermWindow {
style_params.underline_color,
bg_color,
)?;
continue;
did_custom = true;
}
}
}
let texture = glyph
.texture
.as_ref()
.unwrap_or(&gl_state.util_sprites.white_space);
if !did_custom {
let texture = glyph
.texture
.as_ref()
.unwrap_or(&gl_state.util_sprites.white_space);
let left = info.pos.x_offset.get() as f32 + info.pos.bearing_x;
let slice = SpriteSlice {
cell_idx: glyph_idx,
num_cells: info.pos.num_cells as usize,
cell_width: self.render_metrics.cell_size.width as usize,
scale: glyph.scale as f32,
left_offset: left,
};
let left = info.pos.x_offset.get() as f32 + info.pos.bearing_x;
let slice = SpriteSlice {
cell_idx: glyph_idx,
num_cells: info.pos.num_cells as usize,
cell_width: self.render_metrics.cell_size.width as usize,
scale: glyph.scale as f32,
left_offset: left,
};
let pixel_rect = slice.pixel_rect(texture);
let texture_rect = texture.texture.to_texture_coords(pixel_rect);
let pixel_rect = slice.pixel_rect(texture);
let texture_rect = texture.texture.to_texture_coords(pixel_rect);
let left = if glyph_idx == 0 { left } else { slice_left };
let bottom = (pixel_rect.size.height as f32 * glyph.scale as f32) + top
- self.render_metrics.cell_size.height as f32;
let right = pixel_rect.size.width as f32 + left
- self.render_metrics.cell_size.width as f32;
let left = if glyph_idx == 0 { left } else { slice_left };
let bottom = (pixel_rect.size.height as f32 * glyph.scale as f32) + top
- self.render_metrics.cell_size.height as f32;
let right = pixel_rect.size.width as f32 + left
- self.render_metrics.cell_size.width as f32;
// Save the `right` position; we'll use it for the `left` adjust for
// the next slice that comprises this glyph.
// This is important because some glyphs (eg: 현재 브랜치) can have
// fractional advance/offset positions that leave one half slightly
// out of alignment with the other if we were to simply force the
// `left` value to be 0 when glyph_idx > 0.
slice_left = right;
// Save the `right` position; we'll use it for the `left` adjust for
// the next slice that comprises this glyph.
// This is important because some glyphs (eg: 현재 브랜치) can have
// fractional advance/offset positions that leave one half slightly
// out of alignment with the other if we were to simply force the
// `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_image_texture(params.white_space);
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
});
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
});
}
for img in &images {
if img.z_index() >= 0 {
self.populate_image_quad(
&img,
gl_state,
quads,
cell_idx,
&params,
hsv,
cursor_shape,
glyph_color,
style_params.underline_color,
bg_color,
)?;
}
}
}
current_idx += info.pos.num_cells as usize;
}
@ -1023,7 +1027,6 @@ impl super::TermWindow {
quad.set_bg_color(params.selection_bg);
quad.set_fg_color(params.selection_fg);
quad.set_image_texture(params.white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
quad.set_texture(params.white_space);
quad.set_underline_color(params.selection_fg);
@ -1049,7 +1052,6 @@ impl super::TermWindow {
quad.set_bg_color(params.foreground); // reverse video
quad.set_fg_color(params.default_bg);
quad.set_image_texture(params.white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
quad.set_texture(params.white_space);
quad.set_underline_color(params.selection_fg);
@ -1091,7 +1093,6 @@ impl super::TermWindow {
quad.set_position(pos_x, pos_y, pos_x + cell_width, pos_y + cell_height);
quad.set_texture(params.white_space);
quad.set_image_texture(params.white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
quad.set_underline(params.white_space);
quad.set_has_color(false);
@ -1160,7 +1161,6 @@ impl super::TermWindow {
quad.set_underline_color(underline_color);
quad.set_bg_color(bg_color);
quad.set_texture(sprite);
quad.set_image_texture(params.white_space);
quad.set_texture_adjust(0., 0., 0., 0.);
quad.set_underline(params.white_space);
quad.set_has_color(false);
@ -1250,7 +1250,7 @@ impl super::TermWindow {
quad.set_fg_color(glyph_color);
quad.set_underline_color(underline_color);
quad.set_bg_color(bg_color);
quad.set_image_texture(texture_rect);
quad.set_texture(texture_rect);
quad.set_underline(params.white_space);
quad.set_has_color(true);
quad.set_cursor(

View File

@ -6,7 +6,6 @@ precision highp float;
in vec2 position;
in vec2 adjust;
in vec2 tex;
in vec2 img_tex;
in vec2 underline;
in vec4 bg_color;
in vec4 fg_color;
@ -21,7 +20,6 @@ uniform mat4 projection;
out float o_has_color;
out vec2 o_cursor;
out vec2 o_tex;
out vec2 o_img_tex;
out vec2 o_underline;
out vec3 o_hsv;
out vec4 o_bg_color;
@ -31,7 +29,6 @@ out vec4 o_underline_color;
void pass_through_vertex() {
o_tex = tex;
o_img_tex = img_tex;
o_has_color = has_color;
o_fg_color = fg_color;
o_bg_color = bg_color;