use std::ops::{Deref, DerefMut}; //pub use gltf::texture::{MagFilter, MinFilter, WrappingMode}; use image::DynamicImage; use lyra_reflect::Reflect; use crate::lyra_engine; use crate::ResHandle; use crate::ResourceData; /// The filter mode of the sampler. /// /// This is used for minification, magnification, and mipmap filters #[derive(Clone, Copy, PartialEq, Eq, Reflect)] pub enum FilterMode { Nearest, Linear, } /// The wrapping mode of the Texture coordinates #[derive(Clone, Copy, PartialEq, Eq, Reflect)] pub enum WrappingMode { ClampToEdge, MirroredRepeat, Repeat, } /// The descriptor of the sampler for a Texture. #[derive(Clone, Reflect)] pub struct TextureSampler { pub mag_filter: Option, pub min_filter: Option, pub mipmap_filter: Option, pub wrap_u: WrappingMode, pub wrap_v: WrappingMode, pub wrap_w: WrappingMode, } #[derive(Clone, Reflect)] pub struct Image(#[reflect(skip)] DynamicImage); impl ResourceData for Image { fn dependencies(&self) -> Vec { vec![] } fn as_any(&self) -> &dyn std::any::Any { self } fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self } } impl Deref for Image { type Target = DynamicImage; fn deref(&self) -> &Self::Target { &self.0 } } impl DerefMut for Image { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.0 } } impl From for Image { fn from(value: DynamicImage) -> Self { Self(value) } } #[derive(Clone, Reflect)] pub struct Texture { pub image: ResHandle, pub sampler: Option, } impl ResourceData for Texture { fn dependencies(&self) -> Vec { vec![self.image.untyped_clone()] } fn as_any(&self) -> &dyn std::any::Any { self } fn as_any_mut(&mut self) -> &mut dyn std::any::Any { self } } impl Texture { /// Create a texture from an image. pub fn from_image(image: ResHandle) -> Self { Self { image, sampler: None, } } }