Managed texture loading - #3297
Conversation
I think so - the A potential optimization is to replace |
|
|
||
| /// Try loading the texture from the given uri using any available texture loaders. | ||
| /// | ||
| /// Loaders are expected to cache results, so that this call is immediate-mode safe. |
There was a problem hiding this comment.
👍
We should consider how we can alert the user of methods that aren't immediate safe, most notably the old Context::load_texture. Adding a ⚠️ Not immediate-mode safe warning to them might be a start, but perhaps we could also add it to their name somehow. load_texture_sync or something.
|
I'm not totally sure about the API I came up with for |
| /// Load the image from some raw bytes. | ||
| /// | ||
| /// See [`ImageSource::Bytes`]. | ||
| pub fn from_bytes(name: &'static str, bytes: impl Into<Arc<[u8]>>) -> Self { |
There was a problem hiding this comment.
Again, a single impl Into<Bytes> produces a smaller API surface area
| }; | ||
| use std::{sync::Arc, task::Poll}; | ||
|
|
||
| type Entry = Poll<Result<Arc<[u8]>, String>>; |
|
|
||
| /// `width x height x bytes_per_pixel` | ||
| pub fn byte_size(&self) -> usize { | ||
| self.tex_mngr.read().meta(self.id).unwrap().bytes_used() |
There was a problem hiding this comment.
Let's avoid unwrap please 😬
We can fall back to zero instead (if we are not in the texture manager, we are not loaded)
There was a problem hiding this comment.
The size method also unwraps, so I just copied that. I'll change both to not unwrap.
Part of #3291.
egui_extras