108 lines
2.1 KiB
Rust
108 lines
2.1 KiB
Rust
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<FilterMode>,
|
|
pub min_filter: Option<FilterMode>,
|
|
pub mipmap_filter: Option<FilterMode>,
|
|
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<crate::UntypedResHandle> {
|
|
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<DynamicImage> for Image {
|
|
fn from(value: DynamicImage) -> Self {
|
|
Self(value)
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Reflect)]
|
|
pub struct Texture {
|
|
pub image: ResHandle<Image>,
|
|
pub sampler: Option<TextureSampler>,
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
|
|
}
|
|
|
|
impl Texture {
|
|
/// Create a texture from an image.
|
|
pub fn from_image(image: ResHandle<Image>) -> Self {
|
|
Self {
|
|
image,
|
|
sampler: None,
|
|
}
|
|
}
|
|
} |