use alloc::borrow::Cow;
use ownable::IntoOwned;
use serde::Deserialize;
use crate::{Extensions, Extras};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilterEnum {
Nearest,
Linear,
NearestMipmapNearest,
LinearMipmapNearest,
NearestMipmapLinear,
LinearMipmapLinear,
}
#[derive(Clone, Copy, PartialEq, Eq, Deserialize, IntoOwned)]
#[serde(transparent)]
pub struct Filter(pub u64);
impl core::fmt::Debug for Filter {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if let Some(e) = self.to_enum() {
e.fmt(f)
} else {
self.0.fmt(f)
}
}
}
impl Filter {
pub const NEAREST: Self = Self(9728);
pub const LINEAR: Self = Self(9729);
pub const NEAREST_MIPMAP_NEAREST: Self = Self(9984);
pub const LINEAR_MIPMAP_NEAREST: Self = Self(9985);
pub const NEAREST_MIPMAP_LINEAR: Self = Self(9986);
pub const LINEAR_MIPMAP_LINEAR: Self = Self(9987);
pub fn to_enum(self) -> Option<FilterEnum> {
Some(match self {
Self::NEAREST => FilterEnum::Nearest,
Self::LINEAR => FilterEnum::Linear,
Self::NEAREST_MIPMAP_NEAREST => FilterEnum::NearestMipmapNearest,
Self::LINEAR_MIPMAP_NEAREST => FilterEnum::LinearMipmapNearest,
Self::NEAREST_MIPMAP_LINEAR => FilterEnum::NearestMipmapLinear,
Self::LINEAR_MIPMAP_LINEAR => FilterEnum::LinearMipmapLinear,
_ => return None,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrapEnum {
ClampToEdge,
MirroredRepeat,
Repeat,
}
#[derive(Clone, Copy, PartialEq, Eq, Deserialize, IntoOwned)]
#[serde(transparent)]
pub struct Wrap(pub u64);
impl Default for Wrap {
fn default() -> Self {
Self::REPEAT
}
}
impl core::fmt::Debug for Wrap {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if let Some(e) = self.to_enum() {
e.fmt(f)
} else {
self.0.fmt(f)
}
}
}
impl Wrap {
pub const CLAMP_TO_EDGE: Self = Self(33071);
pub const MIRRORED_REPEAT: Self = Self(33648);
pub const REPEAT: Self = Self(10497);
pub fn to_enum(self) -> Option<WrapEnum> {
Some(match self {
Self::CLAMP_TO_EDGE => WrapEnum::ClampToEdge,
Self::MIRRORED_REPEAT => WrapEnum::MirroredRepeat,
Self::REPEAT => WrapEnum::Repeat,
_ => return None,
})
}
}
#[derive(Debug, Clone, Deserialize, IntoOwned)]
pub struct Sampler<'a> {
#[serde(borrow)]
pub name: Option<Cow<'a, str>>,
#[serde(rename = "magFilter")]
pub mag_filter: Option<Filter>,
#[serde(rename = "minFilter")]
pub min_filter: Option<Filter>,
#[serde(rename = "wrapS")]
#[serde(default)]
pub wrap_s: Wrap,
#[serde(rename = "wrapT")]
#[serde(default)]
pub wrap_t: Wrap,
#[serde(borrow)]
pub extensions: Option<Extensions<'a>>,
#[serde(borrow)]
pub extras: Option<Extras<'a>>,
}