[refactor] rename Texture::id to version
This commit is contained in:
parent
d959f71d12
commit
0e870dae3e
4 changed files with 14 additions and 13 deletions
|
@ -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 {
|
||||
|
|
|
@ -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<u8>,
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use {
|
|||
pub struct Painter {
|
||||
program: glium::Program,
|
||||
texture: texture::texture2d::Texture2d,
|
||||
current_texture_id: Option<u64>,
|
||||
current_texture_version: Option<u64>,
|
||||
}
|
||||
|
||||
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(
|
||||
|
|
|
@ -23,7 +23,7 @@ pub struct Painter {
|
|||
tc_buffer: WebGlBuffer,
|
||||
color_buffer: WebGlBuffer,
|
||||
tex_size: (u16, u16),
|
||||
current_texture_id: Option<u64>,
|
||||
current_texture_version: Option<u64>,
|
||||
}
|
||||
|
||||
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(
|
||||
|
|
Loading…
Reference in a new issue