mirror of
https://github.com/wez/wezterm.git
synced 2024-09-21 11:50:42 +03:00
use constants for has_color values in wgsl shader and in the rust code
Slightly improve the efficiency of the hsv transform for text by multiplying the two transforms together and performing just one hsv color conversion.
This commit is contained in:
parent
dad5fbd1f9
commit
a4ec2560a2
@ -15,6 +15,19 @@ pub const V_TOP_RIGHT: usize = 1;
|
||||
pub const V_BOT_LEFT: usize = 2;
|
||||
pub const V_BOT_RIGHT: usize = 3;
|
||||
|
||||
/// a regular monochrome text glyph
|
||||
const IS_GLYPH: f32 = 0.0;
|
||||
/// a color emoji glyph
|
||||
const IS_COLOR_EMOJI: f32 = 1.0;
|
||||
/// a full color texture attached as the
|
||||
/// background image of the window
|
||||
const IS_BG_IMAGE: f32 = 2.0;
|
||||
/// like 2.0, except that instead of an
|
||||
/// image, we use the solid bg color
|
||||
const IS_SOLID_COLOR: f32 = 3.0;
|
||||
/// Grayscale poly quad for non-aa text render layers
|
||||
const IS_GRAY_SCALE: f32 = 4.0;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Copy, Clone, Default, Debug, bytemuck::Pod, bytemuck::Zeroable)]
|
||||
pub struct Vertex {
|
||||
@ -25,18 +38,6 @@ pub struct Vertex {
|
||||
pub fg_color: [f32; 4],
|
||||
pub alt_color: [f32; 4],
|
||||
pub hsv: [f32; 3],
|
||||
// We use a float for this because I can't get
|
||||
// bool or integer values to work:
|
||||
// "bool can't be an in in the vertex shader"
|
||||
//
|
||||
// has_color is effectively an enum with these
|
||||
// possible values:
|
||||
// 0.0 -> a regular monochrome text glyph
|
||||
// 1.0 -> a color emoji glyph
|
||||
// 2.0 -> a full color texture attached as the
|
||||
// background image of the window
|
||||
// 3.0 -> like 2.0, except that instead of an
|
||||
// image, we use the solid bg color
|
||||
pub has_color: f32,
|
||||
pub mix_value: f32,
|
||||
}
|
||||
@ -78,23 +79,23 @@ pub trait QuadTrait {
|
||||
|
||||
/// Set the color glyph "flag"
|
||||
fn set_has_color(&mut self, has_color: bool) {
|
||||
self.set_has_color_impl(if has_color { 1. } else { 0. });
|
||||
self.set_has_color_impl(if has_color { IS_COLOR_EMOJI } else { IS_GLYPH });
|
||||
}
|
||||
|
||||
/// Mark as a grayscale polyquad; color and alpha will be
|
||||
/// multipled with those in the texture
|
||||
fn set_grayscale(&mut self) {
|
||||
self.set_has_color_impl(4.0);
|
||||
self.set_has_color_impl(IS_GRAY_SCALE);
|
||||
}
|
||||
|
||||
/// Mark this quad as a background image.
|
||||
/// Mutually exclusive with set_has_color.
|
||||
fn set_is_background_image(&mut self) {
|
||||
self.set_has_color_impl(2.0);
|
||||
self.set_has_color_impl(IS_BG_IMAGE);
|
||||
}
|
||||
|
||||
fn set_is_background(&mut self) {
|
||||
self.set_has_color_impl(3.0);
|
||||
self.set_has_color_impl(IS_SOLID_COLOR);
|
||||
}
|
||||
|
||||
fn set_fg_color(&mut self, color: LinearRgba);
|
||||
|
@ -20,6 +20,23 @@ struct VertexOutput {
|
||||
@location(5) mix_value: f32,
|
||||
};
|
||||
|
||||
// a regular monochrome text glyph
|
||||
let IS_GLYPH: f32 = 0.0;
|
||||
|
||||
// a color emoji glyph
|
||||
let IS_COLOR_EMOJI: f32 = 1.0;
|
||||
|
||||
// a full color texture attached as the
|
||||
// background image of the window
|
||||
let IS_BG_IMAGE: f32 = 2.0;
|
||||
|
||||
// like 2.0, except that instead of an
|
||||
// image, we use the solid bg color
|
||||
let IS_SOLID_COLOR: f32 = 3.0;
|
||||
|
||||
// Grayscale poly quad for non-aa text render layers
|
||||
let IS_GRAY_SCALE: f32 = 4.0;
|
||||
|
||||
struct ShaderUniform {
|
||||
foreground_text_hsb: vec3<f32>,
|
||||
milliseconds: u32,
|
||||
@ -81,34 +98,31 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
var linear_tex: vec4<f32> = textureSample(atlas_linear_tex, atlas_linear_sampler, in.tex);
|
||||
var nearest_tex: vec4<f32> = textureSample(atlas_nearest_tex, atlas_nearest_sampler, in.tex);
|
||||
|
||||
if in.has_color == 3.0 {
|
||||
var hsv = in.hsv;
|
||||
|
||||
if in.has_color == IS_SOLID_COLOR {
|
||||
// Solid color block
|
||||
} else if in.has_color == 2.0 {
|
||||
} else if in.has_color == IS_BG_IMAGE {
|
||||
// Window background attachment
|
||||
// Apply window_background_image_opacity to the background image
|
||||
color = linear_tex;
|
||||
color.a *= fg_color.a;
|
||||
} else if in.has_color == 1.0 {
|
||||
} else if in.has_color == IS_COLOR_EMOJI {
|
||||
// the texture is full color info (eg: color emoji glyph)
|
||||
color = nearest_tex;
|
||||
} else if in.has_color == 4.0 {
|
||||
} else if in.has_color == IS_GRAY_SCALE {
|
||||
// Grayscale poly quad for non-aa text render layers
|
||||
color = fg_color;
|
||||
color.a *= nearest_tex.a;
|
||||
} else if in.has_color == 0.0 {
|
||||
} else if in.has_color == IS_GLYPH {
|
||||
// the texture is the alpha channel/color mask
|
||||
// and we need to tint with the fg_color
|
||||
color = fg_color;
|
||||
color.a = nearest_tex.a;
|
||||
color = apply_hsv(color, uniforms.foreground_text_hsb);
|
||||
hsv *= uniforms.foreground_text_hsb;
|
||||
}
|
||||
|
||||
color = apply_hsv(color, in.hsv);
|
||||
|
||||
// We MUST output SRGB and tell glium that we do that (outputs_srgb),
|
||||
// otherwise something in glium over-gamma-corrects depending on the gl setup.
|
||||
// color = to_srgb(color);
|
||||
color = apply_hsv(color, hsv);
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user