2024-03-08 16:04:38 +00:00
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
|
|
|
//pub use gltf::texture::{MagFilter, MinFilter, WrappingMode};
|
2023-10-23 01:49:31 +00:00
|
|
|
use image::DynamicImage;
|
2024-03-10 05:11:15 +00:00
|
|
|
use lyra_reflect::Reflect;
|
|
|
|
use crate::lyra_engine;
|
2023-09-12 18:25:33 +00:00
|
|
|
|
2024-03-08 16:04:38 +00:00
|
|
|
use crate::ResHandle;
|
2024-03-10 05:11:15 +00:00
|
|
|
use crate::ResourceData;
|
2024-03-08 16:04:38 +00:00
|
|
|
|
|
|
|
/// The filter mode of the sampler.
|
|
|
|
///
|
|
|
|
/// This is used for minification, magnification, and mipmap filters
|
2024-03-10 05:11:15 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Reflect)]
|
2024-03-08 16:04:38 +00:00
|
|
|
pub enum FilterMode {
|
|
|
|
Nearest,
|
|
|
|
Linear,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The wrapping mode of the Texture coordinates
|
2024-03-10 05:11:15 +00:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Reflect)]
|
2024-03-08 16:04:38 +00:00
|
|
|
pub enum WrappingMode {
|
|
|
|
ClampToEdge,
|
|
|
|
MirroredRepeat,
|
|
|
|
Repeat,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The descriptor of the sampler for a Texture.
|
2024-03-10 05:11:15 +00:00
|
|
|
#[derive(Clone, Reflect)]
|
2024-03-08 16:04:38 +00:00
|
|
|
pub struct TextureSampler {
|
|
|
|
pub mag_filter: Option<FilterMode>,
|
|
|
|
pub min_filter: Option<FilterMode>,
|
|
|
|
pub mipmap_filter: Option<FilterMode>,
|
|
|
|
pub wrap_u: WrappingMode,
|
|
|
|
pub wrap_v: WrappingMode,
|
|
|
|
pub wrap_w: WrappingMode,
|
|
|
|
}
|
|
|
|
|
2024-03-10 05:11:15 +00:00
|
|
|
#[derive(Clone, Reflect)]
|
|
|
|
pub struct Image(#[reflect(skip)] DynamicImage);
|
|
|
|
|
|
|
|
impl ResourceData for Image {
|
|
|
|
fn dependencies(&self) -> Vec<crate::UntypedResHandle> {
|
|
|
|
vec![]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_any(&self) -> &dyn std::any::Any {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-08 16:04:38 +00:00
|
|
|
|
|
|
|
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<DynamicImage> for Image {
|
|
|
|
fn from(value: DynamicImage) -> Self {
|
|
|
|
Self(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-27 04:28:49 +00:00
|
|
|
#[derive(Clone, Reflect)]
|
2023-09-12 18:25:33 +00:00
|
|
|
pub struct Texture {
|
2024-03-08 16:04:38 +00:00
|
|
|
pub image: ResHandle<Image>,
|
|
|
|
pub sampler: Option<TextureSampler>,
|
2023-09-12 18:25:33 +00:00
|
|
|
}
|
|
|
|
|
2024-03-10 05:11:15 +00:00
|
|
|
impl ResourceData for Texture {
|
|
|
|
fn dependencies(&self) -> Vec<crate::UntypedResHandle> {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-09-12 18:25:33 +00:00
|
|
|
impl Texture {
|
2024-03-08 16:04:38 +00:00
|
|
|
/// Create a texture from an image.
|
|
|
|
pub fn from_image(image: ResHandle<Image>) -> Self {
|
|
|
|
Self {
|
|
|
|
image,
|
|
|
|
sampler: None,
|
|
|
|
}
|
|
|
|
}
|
2023-09-12 18:25:33 +00:00
|
|
|
}
|