use serde::{Deserialize, Serialize};
use strum::FromRepr;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub struct Sampler {
pub address_x: AddressMode,
pub address_y: AddressMode,
pub min_filter: FilterMode,
pub mag_filter: FilterMode,
}
impl Default for Sampler {
#[inline]
fn default() -> Self {
Self::new(
AddressMode::Repeat,
AddressMode::Repeat,
FilterMode::Linear,
FilterMode::Nearest,
)
}
}
impl Sampler {
#[inline]
pub fn all() -> Vec<Self> {
let mut samplers = Vec::new();
for ax in AddressMode::VARIANTS {
for ay in AddressMode::VARIANTS {
for min in FilterMode::VARIANTS {
for mag in FilterMode::VARIANTS {
samplers.push(Self::new(ax, ay, min, mag));
}
}
}
}
samplers
}
#[inline]
pub const fn new(
address_x: AddressMode,
address_y: AddressMode,
min_filter: FilterMode,
mag_filter: FilterMode,
) -> Self {
Self {
address_x,
address_y,
min_filter,
mag_filter,
}
}
#[inline]
pub const fn with(address: AddressMode, filter: FilterMode) -> Self {
Self::new(address, address, filter, filter)
}
#[inline]
pub const fn clamp(filter: FilterMode) -> Self {
Self::with(AddressMode::Clamp, filter)
}
#[inline]
pub const fn repeat(filter: FilterMode) -> Self {
Self::with(AddressMode::Repeat, filter)
}
#[inline]
pub const fn nearest(address: AddressMode) -> Self {
Self::with(address, FilterMode::Nearest)
}
#[inline]
pub const fn linear(address: AddressMode) -> Self {
Self::with(address, FilterMode::Linear)
}
}
#[derive(
Debug, Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize,
)]
pub enum AddressMode {
#[default]
Clamp,
Repeat,
MirrorRepeat,
}
impl Into<wgpu::AddressMode> for AddressMode {
#[inline]
fn into(self) -> wgpu::AddressMode {
match self {
Self::Clamp => wgpu::AddressMode::ClampToEdge,
Self::Repeat => wgpu::AddressMode::Repeat,
Self::MirrorRepeat => wgpu::AddressMode::MirrorRepeat,
}
}
}
impl AddressMode {
pub const VARIANTS: [Self; 3] = [Self::Clamp, Self::Repeat, Self::MirrorRepeat];
}
#[derive(
Debug,
Default,
Copy,
Clone,
Eq,
PartialEq,
Ord,
PartialOrd,
Hash,
Serialize,
Deserialize,
FromRepr,
)]
pub enum FilterMode {
#[default]
Nearest,
Linear,
}
impl Into<wgpu::FilterMode> for FilterMode {
#[inline]
fn into(self) -> wgpu::FilterMode {
match self {
Self::Nearest => wgpu::FilterMode::Nearest,
Self::Linear => wgpu::FilterMode::Linear,
}
}
}
impl FilterMode {
pub const VARIANTS: [Self; 2] = [Self::Nearest, Self::Linear];
}