eframe: always provide a texture allocator

This commit is contained in:
Emil Ernerfeldt 2021-02-28 19:09:48 +01:00
parent fdb1aa6bec
commit 84cc227f11
6 changed files with 15 additions and 12 deletions

View File

@ -45,7 +45,7 @@ impl epi::App for ColorTest {
ui.separator();
}
ScrollArea::auto_sized().show(ui, |ui| {
self.ui(ui, frame.tex_allocator());
self.ui(ui, &mut Some(frame.tex_allocator()));
});
});
}

View File

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

View File

@ -191,7 +191,7 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
let mut app_output = epi::backend::AppOutput::default();
let mut frame = epi::backend::FrameBuilder {
info: integration_info(&display, None),
tex_allocator: Some(&mut painter),
tex_allocator: &mut painter,
#[cfg(feature = "http")]
http: http.clone(),
output: &mut app_output,
@ -229,7 +229,7 @@ pub fn run(mut app: Box<dyn epi::App>) -> ! {
let mut app_output = epi::backend::AppOutput::default();
let mut frame = epi::backend::FrameBuilder {
info: integration_info(&display, previous_frame_time),
tex_allocator: Some(&mut painter),
tex_allocator: &mut painter,
#[cfg(feature = "http")]
http: http.clone(),
output: &mut app_output,

View File

@ -206,7 +206,7 @@ impl AppRunner {
seconds_since_midnight: Some(seconds_since_midnight()),
native_pixels_per_point: Some(native_pixels_per_point()),
},
tex_allocator: Some(self.web_backend.painter.as_tex_allocator()),
tex_allocator: self.web_backend.painter.as_tex_allocator(),
#[cfg(feature = "http")]
http: self.http.clone(),
output: &mut app_output,

View File

@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* You can control the initial size of the native window with `App::initial_window_size`.
* You can control the maximum egui web canvas size with `App::max_size_points`.
* `Frame::tex_allocator()` no longer returns an `Option` (there is always a texture allocator).
## 0.9.0 - 2021-02-07

View File

@ -156,9 +156,9 @@ impl<'a> Frame<'a> {
&self.0.info
}
/// A way to allocate textures (on integrations that support it).
pub fn tex_allocator(&mut self) -> &mut Option<&'a mut dyn TextureAllocator> {
&mut self.0.tex_allocator
/// A way to allocate textures.
pub fn tex_allocator(&mut self) -> &mut dyn TextureAllocator {
self.0.tex_allocator
}
/// Signal the app to stop/exit/quit the app (only works for native apps, not web apps).
@ -368,7 +368,7 @@ pub mod backend {
/// Information about the integration.
pub info: IntegrationInfo,
/// A way to allocate textures (on integrations that support it).
pub tex_allocator: Option<&'a mut dyn TextureAllocator>,
pub tex_allocator: &'a mut dyn TextureAllocator,
/// Do http requests.
#[cfg(feature = "http")]
pub http: std::sync::Arc<dyn backend::Http>,