From 0e870dae3e447fea072187d9b65e71d6d305417d Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 9 Sep 2020 13:32:40 +0200 Subject: [PATCH] [refactor] rename Texture::id to version --- egui/src/paint/fonts.rs | 2 +- egui/src/paint/texture_atlas.rs | 9 +++++---- egui_glium/src/painter.rs | 8 ++++---- egui_web/src/webgl.rs | 8 ++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/egui/src/paint/fonts.rs b/egui/src/paint/fonts.rs index faf77b5b..6ea9b30e 100644 --- a/egui/src/paint/fonts.rs +++ b/egui/src/paint/fonts.rs @@ -126,7 +126,7 @@ impl Fonts { let mut hasher = ahash::AHasher::default(); self.texture.pixels.hash(&mut hasher); - self.texture.id = hasher.finish(); + self.texture.version = hasher.finish(); } pub fn texture(&self) -> &Texture { diff --git a/egui/src/paint/texture_atlas.rs b/egui/src/paint/texture_atlas.rs index 9c50a98d..c9f5f6d8 100644 --- a/egui/src/paint/texture_atlas.rs +++ b/egui/src/paint/texture_atlas.rs @@ -2,7 +2,8 @@ #[derive(Clone, Default)] pub struct Texture { /// e.g. a hash of the data. Use this to detect changes! - pub id: u64, + /// If the texture changes, this too will change. + pub version: u64, pub width: usize, pub height: usize, pub pixels: Vec, @@ -42,7 +43,7 @@ impl TextureAtlas { pub fn new(width: usize, height: usize) -> Self { Self { texture: Texture { - id: 0, + version: 0, width, height, pixels: vec![0; width * height], @@ -56,7 +57,7 @@ impl TextureAtlas { } pub fn texture_mut(&mut self) -> &mut Texture { - self.texture.id += 1; + self.texture.version += 1; &mut self.texture } @@ -88,7 +89,7 @@ impl TextureAtlas { let pos = self.cursor; self.cursor.0 += w; - self.texture.id += 1; + self.texture.version += 1; (pos.0 as usize, pos.1 as usize) } } diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index 77b47583..162cf392 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -12,7 +12,7 @@ use { pub struct Painter { program: glium::Program, texture: texture::texture2d::Texture2d, - current_texture_id: Option, + current_texture_version: Option, } impl Painter { @@ -171,12 +171,12 @@ impl Painter { Painter { program, texture, - current_texture_id: None, + current_texture_version: None, } } fn upload_texture(&mut self, facade: &dyn glium::backend::Facade, texture: &egui::Texture) { - if self.current_texture_id == Some(texture.id) { + if self.current_texture_version == Some(texture.version) { return; // No change } @@ -190,7 +190,7 @@ impl Painter { let mipmaps = texture::MipmapsOption::NoMipmap; self.texture = texture::texture2d::Texture2d::with_format(facade, pixels, format, mipmaps).unwrap(); - self.current_texture_id = Some(texture.id); + self.current_texture_version = Some(texture.version); } pub fn paint_jobs( diff --git a/egui_web/src/webgl.rs b/egui_web/src/webgl.rs index aa5056d5..7e5f06b7 100644 --- a/egui_web/src/webgl.rs +++ b/egui_web/src/webgl.rs @@ -23,7 +23,7 @@ pub struct Painter { tc_buffer: WebGlBuffer, color_buffer: WebGlBuffer, tex_size: (u16, u16), - current_texture_id: Option, + current_texture_version: Option, } impl Painter { @@ -138,7 +138,7 @@ impl Painter { tc_buffer, color_buffer, tex_size: (0, 0), - current_texture_id: None, + current_texture_version: None, }) } @@ -148,7 +148,7 @@ impl Painter { } fn upload_texture(&mut self, texture: &Texture) { - if self.current_texture_id == Some(texture.id) { + if self.current_texture_version == Some(texture.version) { return; // No change } @@ -174,7 +174,7 @@ impl Painter { .unwrap(); self.tex_size = (texture.width as u16, texture.height as u16); - self.current_texture_id = Some(texture.id); + self.current_texture_version = Some(texture.version); } pub fn paint_jobs(