Trait egui::load::TextureLoader
source · pub trait TextureLoader {
// Required methods
fn id(&self) -> &str;
fn load(
&self,
ctx: &Context,
uri: &str,
texture_options: TextureOptions,
size_hint: SizeHint
) -> TextureLoadResult;
fn forget(&self, uri: &str);
fn forget_all(&self);
fn byte_size(&self) -> usize;
// Provided method
fn end_frame(&self, frame_index: usize) { ... }
}
Expand description
A TextureLoader
uploads a ColorImage
to the GPU, returning a SizedTexture
.
egui
comes with an implementation that uses Context::load_texture
,
which just asks the egui backend to upload the image to the GPU.
You can implement this trait if you do your own uploading of images to the GPU. For instance, you can use this to refer to textures in a game engine that egui doesn’t otherwise know about.
Implementations are expected to cache each combination of (URI, TextureOptions)
.
Required Methods§
sourcefn id(&self) -> &str
fn id(&self) -> &str
Unique ID of this loader.
To reduce the chance of collisions, include module_path!()
as part of this ID.
For example: concat!(module_path!(), "::MyLoader")
for my_crate::my_loader::MyLoader
.
sourcefn load(
&self,
ctx: &Context,
uri: &str,
texture_options: TextureOptions,
size_hint: SizeHint
) -> TextureLoadResult
fn load( &self, ctx: &Context, uri: &str, texture_options: TextureOptions, size_hint: SizeHint ) -> TextureLoadResult
Try loading the texture from the given uri.
Implementations should call ctx.request_repaint
to wake up the ui
once the texture is ready.
The implementation should cache any result, so that calling this is immediate-mode safe.
Errors
This may fail with:
LoadError::NotSupported
if the loader does not support loadinguri
.LoadError::Loading
if the loading process failed.
sourcefn forget(&self, uri: &str)
fn forget(&self, uri: &str)
Forget the given uri
.
If uri
is cached, it should be evicted from cache,
so that it may be fully reloaded.
sourcefn forget_all(&self)
fn forget_all(&self)
Forget all URIs ever given to this loader.
If the loader caches any URIs, the entire cache should be cleared, so that all of them may be fully reloaded.