Dirty glyph detection.
@@ -18,8 +18,10 @@ pub(crate) struct SimpleBackendWithBackground {
pub(crate) base_z: f32,
last_background: Option<Vec<[f32; 4]>>,
last_foreground: Option<Vec<[f32; 4]>>,
+ last_glyphs: Option<Vec<u16>>,
pub(crate) background_changed: bool,
pub(crate) foreground_changed: bool,
+ pub(crate) glyphs_changed: bool,
}
impl SimpleBackendWithBackground {
@@ -46,6 +48,8 @@ impl SimpleBackendWithBackground {
background_changed: true,
last_foreground: None,
foreground_changed: true,
+ last_glyphs: None,
+ glyphs_changed: false,
};
let mesh = back_end.build_mesh(parent);
let mesh_handle = meshes.add(mesh);
@@ -279,13 +283,32 @@ impl SimpleBackendWithBackground {
self.foreground_changed = true;
}
}
+
+ fn check_for_glyph_changes(&mut self, terminals: &[crate::consoles::TerminalGlyph]) {
+ let glyphs: Vec<u16> = terminals.iter().map(|c| c.glyph).collect();
+ if let Some(g) = &mut self.last_glyphs {
+ let changed = g.iter().zip(glyphs.iter()).any(|(b1, b2)| b1 != b2);
+
+ if !changed {
+ self.glyphs_changed = false;
+ } else {
+ self.last_glyphs = Some(glyphs);
+ self.glyphs_changed = true;
+ }
+ } else {
+ self.last_glyphs = Some(glyphs);
+ self.glyphs_changed = true;
+ }
+ }
}
impl SimpleConsoleBackend for SimpleBackendWithBackground {
fn update_mesh(&self, front_end: &SimpleConsole, meshes: &mut Assets<Mesh>) {
if let Some(mesh_handle) = &self.mesh_handle {
if let Some(mesh) = meshes.get_mut(mesh_handle.clone()) {
+ if self.glyphs_changed {
mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, self.build_uvs(front_end));
+ }
if self.foreground_changed {
mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, self.build_colors(front_end));
}
@@ -326,10 +349,12 @@ impl SimpleConsoleBackend for SimpleBackendWithBackground {
fn clear_dirty(&mut self) {
self.background_changed = false;
self.foreground_changed = false;
+ self.glyphs_changed = false;
}
fn update_dirty(&mut self, terminals: &[crate::consoles::TerminalGlyph]) {
self.check_for_background_changes(terminals);
self.check_for_foreground_changes(terminals);
+ self.check_for_glyph_changes(terminals);
}
}
