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:
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user