1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-31 05:40:03 -04:00

[epi] Simplify TextureAllocator interface

This commit is contained in:
Emil Ernerfeldt
2021-01-07 16:29:58 +01:00
parent e8e53e9500
commit 5ef9f35d1e
6 changed files with 20 additions and 27 deletions

View File

@@ -394,9 +394,7 @@ impl TextureManager {
let pixels = gradient.to_pixel_row();
let width = pixels.len();
let height = 1;
let id = tex_allocator.alloc();
tex_allocator.set_srgba_premultiplied(id, (width, height), &pixels);
id
tex_allocator.alloc_srgba_premultiplied((width, height), &pixels)
})
}
}

View File

@@ -265,13 +265,16 @@ impl TexMngr {
image: &Image,
) -> Option<egui::TextureId> {
let tex_allocator = frame.tex_allocator().as_mut()?;
let texture_id = self.texture_id.unwrap_or_else(|| tex_allocator.alloc());
self.texture_id = Some(texture_id);
if self.loaded_url != url {
if let Some(texture_id) = self.texture_id.take() {
tex_allocator.free(texture_id);
}
self.texture_id =
Some(tex_allocator.alloc_srgba_premultiplied(image.size, &image.pixels));
self.loaded_url = url.to_owned();
tex_allocator.set_srgba_premultiplied(texture_id, image.size, &image.pixels);
}
Some(texture_id)
self.texture_id
}
}