added underdeveloped but working image support (no freeing or samplers)
This commit is contained in:
48
src/layout/texture.rs
Normal file
48
src/layout/texture.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use image::DynamicImage;
|
||||
|
||||
use crate::render::TexturePrimitive;
|
||||
|
||||
/// TODO: proper resource management
|
||||
pub struct TextureHandle {
|
||||
pub inner: TexturePrimitive,
|
||||
}
|
||||
|
||||
/// a texture manager for a ui
|
||||
/// note that this is heavily oriented towards wgpu's renderer so the primitives don't need mapped
|
||||
#[derive(Default)]
|
||||
pub struct Textures {
|
||||
/// TODO: these are images, not views rn
|
||||
views: Vec<DynamicImage>,
|
||||
changed: bool,
|
||||
}
|
||||
|
||||
pub struct TextureUpdates<'a> {
|
||||
pub images: Option<&'a [DynamicImage]>,
|
||||
}
|
||||
|
||||
impl Textures {
|
||||
pub fn add(&mut self, image: DynamicImage) -> TextureHandle {
|
||||
let view_idx = self.views.len() as u32;
|
||||
self.views.push(image);
|
||||
// 0 == default in renderer; TODO: actually create samplers here
|
||||
let sampler_idx = 0;
|
||||
self.changed = true;
|
||||
TextureHandle {
|
||||
inner: TexturePrimitive {
|
||||
view_idx,
|
||||
sampler_idx,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn updates(&mut self) -> TextureUpdates<'_> {
|
||||
if self.changed {
|
||||
self.changed = false;
|
||||
TextureUpdates {
|
||||
images: Some(&self.views),
|
||||
}
|
||||
} else {
|
||||
TextureUpdates { images: None }
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user