use crate as wgpu;
#[derive(Debug)]
pub struct SamplerBuilder {
pub descriptor: wgpu::SamplerDescriptor<'static>,
}
impl<'b> SamplerBuilder {
pub const DEFAULT_ADDRESS_MODE_U: wgpu::AddressMode = wgpu::AddressMode::ClampToEdge;
pub const DEFAULT_ADDRESS_MODE_V: wgpu::AddressMode = wgpu::AddressMode::ClampToEdge;
pub const DEFAULT_ADDRESS_MODE_W: wgpu::AddressMode = wgpu::AddressMode::ClampToEdge;
pub const DEFAULT_MAG_FILTER: wgpu::FilterMode = wgpu::FilterMode::Linear;
pub const DEFAULT_MIN_FILTER: wgpu::FilterMode = wgpu::FilterMode::Linear;
pub const DEFAULT_MIPMAP_FILTER: wgpu::FilterMode = wgpu::FilterMode::Nearest;
pub const DEFAULT_LOD_MIN_CLAMP: f32 = 0.0;
pub const DEFAULT_LOD_MAX_CLAMP: f32 = 100.0;
pub const DEFAULT_COMPARE: Option<wgpu::CompareFunction> = None;
pub const DEFAULT_ANISOTROPY_CLAMP: u16 = 1;
pub const DEFAULT_LABEL: &'static str = "nannou-sampler";
pub const DEFAULT_BORDER_COLOR: Option<wgpu::SamplerBorderColor> = None;
pub const DEFAULT_DESCRIPTOR: wgpu::SamplerDescriptor<'static> = wgpu::SamplerDescriptor {
address_mode_u: Self::DEFAULT_ADDRESS_MODE_U,
address_mode_v: Self::DEFAULT_ADDRESS_MODE_V,
address_mode_w: Self::DEFAULT_ADDRESS_MODE_W,
mag_filter: Self::DEFAULT_MAG_FILTER,
min_filter: Self::DEFAULT_MIN_FILTER,
mipmap_filter: Self::DEFAULT_MIPMAP_FILTER,
lod_min_clamp: Self::DEFAULT_LOD_MIN_CLAMP,
lod_max_clamp: Self::DEFAULT_LOD_MAX_CLAMP,
compare: Self::DEFAULT_COMPARE,
anisotropy_clamp: Self::DEFAULT_ANISOTROPY_CLAMP,
label: Some(Self::DEFAULT_LABEL),
border_color: Self::DEFAULT_BORDER_COLOR,
};
pub fn new() -> Self {
Self::default()
}
pub fn address_mode_u(mut self, mode: wgpu::AddressMode) -> Self {
self.descriptor.address_mode_u = mode;
self
}
pub fn address_mode_v(mut self, mode: wgpu::AddressMode) -> Self {
self.descriptor.address_mode_v = mode;
self
}
pub fn address_mode_w(mut self, mode: wgpu::AddressMode) -> Self {
self.descriptor.address_mode_w = mode;
self
}
pub fn address_mode(self, mode: wgpu::AddressMode) -> Self {
self.address_mode_u(mode)
.address_mode_v(mode)
.address_mode_w(mode)
}
pub fn mag_filter(mut self, filter: wgpu::FilterMode) -> Self {
self.descriptor.mag_filter = filter;
self
}
pub fn min_filter(mut self, filter: wgpu::FilterMode) -> Self {
self.descriptor.min_filter = filter;
self
}
pub fn mipmap_filter(mut self, filter: wgpu::FilterMode) -> Self {
self.descriptor.mipmap_filter = filter;
self
}
pub fn lod_min_clamp(mut self, min: f32) -> Self {
self.descriptor.lod_min_clamp = min;
self
}
pub fn lod_max_clamp(mut self, max: f32) -> Self {
self.descriptor.lod_max_clamp = max;
self
}
pub fn compare(mut self, f: Option<wgpu::CompareFunction>) -> Self {
self.descriptor.compare = f;
self
}
pub fn anisotropy_clamp(mut self, clamp: u16) -> Self {
self.descriptor.anisotropy_clamp = clamp;
self
}
pub fn label(mut self, label: Option<&'static str>) -> Self {
self.descriptor.label = label;
self
}
pub fn build(&self, device: &wgpu::Device) -> wgpu::Sampler {
device.create_sampler(&self.descriptor)
}
pub fn into_descriptor(self) -> wgpu::SamplerDescriptor<'static> {
self.into()
}
}
impl Default for SamplerBuilder {
fn default() -> Self {
SamplerBuilder {
descriptor: Self::DEFAULT_DESCRIPTOR,
}
}
}
impl Into<wgpu::SamplerDescriptor<'static>> for SamplerBuilder {
fn into(self) -> wgpu::SamplerDescriptor<'static> {
self.descriptor
}
}
impl From<wgpu::SamplerDescriptor<'static>> for SamplerBuilder {
fn from(descriptor: wgpu::SamplerDescriptor<'static>) -> Self {
SamplerBuilder { descriptor }
}
}