Background loading of changing images #5200
-
I'm trying to build an application for displaying the image files in a folder using eframe. It should provide a way to quickly navigate through the images, displaying one image at a time (for now). If I use |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I'm using wgpu where it's relatively easy to upload images from another thread, so if you don't rely on opengl in some other way you could try switching to wgpu (with eframe it's as simple as turning off default features and turning on the wgpu feature). I plan on open sourcing my texture loader (which is also much more efficient at loading textures in wasm, relying on the browser to decode them) at some point but I haven't gotten to that yet. |
Beta Was this translation helpful? Give feedback.
-
If I just enable the wgpu renderer, I don't notice any delay between image changes anymore, even though from my understanding the texture uploading should still happen in the main thread. But if I change images too quickly, it crashes due to missing textures ("Texture with 'egui_texid_Managed(33)' label has been destroyed"). I guess it tries to display textures, which the worker thread already unloaded. egui::CentralPanel::default().show(context, |ui| {
if let Some(file_index) = self.file_index {
let file_name = &self.file_names[file_index];
let texture: Option<egui::TextureHandle> = self.image_loader.get(file_name, SizeKind::Full);
if let Some(ref texture) = texture {
ui.add_sized(ui.available_size(),
egui::Image::new(egui::ImageSource::Texture(texture.into()))
.max_size(ui.available_size()),
);
}
}
}); What does the use of |
Beta Was this translation helpful? Give feedback.
-
Even though I still have open questions, just using wgpu does it for me. The speed is sufficient and the crash fixed. So I'm marking your comment as the answer. |
Beta Was this translation helpful? Give feedback.
I'm using wgpu where it's relatively easy to upload images from another thread, so if you don't rely on opengl in some other way you could try switching to wgpu (with eframe it's as simple as turning off default features and turning on the wgpu feature).
You can then use Renderer::register_native_texture to register the texture with egui.
Or you could write a custom texture loader that basically does the same thing (which is what I'm doing).
I plan on open sourcing my texture loader (which is also much more efficient at loading textures in wasm, relying on the browser to decode them) at some point but I haven't gotten to that yet.