-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Managed texture loading #3297
Managed texture loading #3297
Conversation
I think so - the A potential optimization is to replace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting!
@@ -1998,6 +2016,8 @@ impl Context { | |||
|
|||
/// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, a single impl Into<Bytes>
produces a smaller API surface area
mutex::Mutex, | ||
}; | ||
use std::{sync::Arc, task::Poll}; | ||
|
||
type Entry = Poll<Result<Arc<[u8]>, String>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also use Bytes
here 🤷
@@ -95,6 +95,11 @@ impl TextureHandle { | |||
crate::Vec2::new(w as f32, h as f32) | |||
} | |||
|
|||
/// `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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size
method also unwraps, so I just copied that. I'll change both to not unwrap.
Part of #3291.
egui_extras