mirror of
https://github.com/wez/wezterm.git
synced 2024-12-26 06:42:12 +03:00
wezterm: add a linear scaling sampler for graphics
The fragment shader was set to use nearest texel sampling because that made for sharper lines when rendering the cursor bar or outlines. This commit adds a supplemental sampler over the same texture that is set to merge nearby texels. We now use this sampler for the background image and cells marked as having full color textures (eg: emoji, image protocol). This makes the window background image look better when it is scaled. I'm not 100% sure about image protocol cells, but I'm looking into that in general at the moment.
This commit is contained in:
parent
7f82f333f1
commit
b49b82ae89
@ -13,7 +13,8 @@ uniform mat4 projection;
|
||||
uniform bool window_bg_layer;
|
||||
uniform bool bg_and_line_layer;
|
||||
uniform bool has_background_image;
|
||||
uniform sampler2D glyph_tex;
|
||||
uniform sampler2D atlas_nearest_sampler;
|
||||
uniform sampler2D atlas_linear_sampler;
|
||||
|
||||
out vec4 color;
|
||||
|
||||
@ -63,7 +64,7 @@ void main() {
|
||||
if (window_bg_layer) {
|
||||
if (o_has_color == 2.0) {
|
||||
// We're the window background image.
|
||||
color = texture(glyph_tex, o_tex);
|
||||
color = texture(atlas_linear_sampler, o_tex);
|
||||
// Apply window_background_image_opacity to the background image
|
||||
color.a = o_bg_color.a;
|
||||
} else {
|
||||
@ -85,7 +86,7 @@ void main() {
|
||||
// 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 = texture(glyph_tex, o_underline);
|
||||
vec4 under_color = texture(atlas_nearest_sampler, o_underline);
|
||||
if (under_color.a != 0.0) {
|
||||
// if the underline glyph isn't transparent in this position then
|
||||
// we take the text fg color, otherwise we'll leave the color
|
||||
@ -97,7 +98,7 @@ void main() {
|
||||
// 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 = texture(glyph_tex, o_cursor);
|
||||
vec4 cursor_outline = texture(atlas_nearest_sampler, o_cursor);
|
||||
if (cursor_outline.a != 0.0) {
|
||||
color = o_cursor_color;
|
||||
}
|
||||
@ -107,10 +108,12 @@ void main() {
|
||||
// the window_bg_layer.
|
||||
discard;
|
||||
} else {
|
||||
color = texture(glyph_tex, o_tex);
|
||||
if (o_has_color == 0.0) {
|
||||
// if it's not a color emoji, tint with the fg_color
|
||||
color = texture(atlas_nearest_sampler, o_tex);
|
||||
color.rgb = o_fg_color.rgb;
|
||||
} else {
|
||||
color = texture(atlas_linear_sampler, o_tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2566,11 +2566,16 @@ impl TermWindow {
|
||||
// Clamp and use the nearest texel rather than interpolate.
|
||||
// This prevents things like the box cursor outlines from
|
||||
// being randomly doubled in width or height
|
||||
let glyph_tex = Sampler::new(&*tex)
|
||||
let atlas_nearest_sampler = Sampler::new(&*tex)
|
||||
.wrap_function(SamplerWrapFunction::Clamp)
|
||||
.magnify_filter(MagnifySamplerFilter::Nearest)
|
||||
.minify_filter(MinifySamplerFilter::Nearest);
|
||||
|
||||
let atlas_linear_sampler = Sampler::new(&*tex)
|
||||
.wrap_function(SamplerWrapFunction::Clamp)
|
||||
.magnify_filter(MagnifySamplerFilter::Linear)
|
||||
.minify_filter(MinifySamplerFilter::Linear);
|
||||
|
||||
let has_background_image = self.window_background.is_some();
|
||||
|
||||
// Pass 1: Draw backgrounds
|
||||
@ -2580,7 +2585,8 @@ impl TermWindow {
|
||||
&gl_state.program,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
glyph_tex: glyph_tex,
|
||||
atlas_nearest_sampler: atlas_nearest_sampler,
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
window_bg_layer: true,
|
||||
bg_and_line_layer: false,
|
||||
has_background_image: has_background_image,
|
||||
@ -2617,7 +2623,8 @@ impl TermWindow {
|
||||
&gl_state.program,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
glyph_tex: glyph_tex,
|
||||
atlas_nearest_sampler: atlas_nearest_sampler,
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
window_bg_layer: false,
|
||||
bg_and_line_layer: true,
|
||||
has_background_image: has_background_image,
|
||||
@ -2632,7 +2639,8 @@ impl TermWindow {
|
||||
&gl_state.program,
|
||||
&uniform! {
|
||||
projection: projection,
|
||||
glyph_tex: glyph_tex,
|
||||
atlas_nearest_sampler: atlas_nearest_sampler,
|
||||
atlas_linear_sampler: atlas_linear_sampler,
|
||||
window_bg_layer: false,
|
||||
bg_and_line_layer: false,
|
||||
has_background_image: has_background_image,
|
||||
|
Loading…
Reference in New Issue
Block a user