Skip to main content

pebble/wgpu/
samplers.rs

1#[derive(Clone, Copy, PartialEq, Eq, Hash)]
2pub enum SamplerKind {
3    LinearRepeat,
4    LinearClamp,
5    /// Like `LinearClamp`, but clamped to mip 0 only (`lod_min_clamp`/
6    /// `lod_max_clamp` both 0.0). Use this when you need to force sampling
7    /// the base level regardless of how many mips the texture actually
8    /// has — e.g. an environment-map capture pass where blending across
9    /// mips would introduce blur you don't want in the baked result.
10    LinearClampNoMip,
11    Nearest,
12}
13
14impl SamplerKind {
15    /// Pure conversion to a wgpu descriptor. You still call
16    /// `device.create_sampler(&kind.descriptor())` yourself, in your own
17    /// `LazyResource::construct` — this only fixes the handful of
18    /// address-mode/filter combinations so you don't re-derive them.
19    pub fn descriptor(&self) -> wgpu::SamplerDescriptor<'static> {
20        match self {
21            SamplerKind::LinearRepeat => wgpu::SamplerDescriptor {
22                address_mode_u: wgpu::AddressMode::Repeat,
23                address_mode_v: wgpu::AddressMode::Repeat,
24                address_mode_w: wgpu::AddressMode::Repeat,
25                mag_filter: wgpu::FilterMode::Linear,
26                min_filter: wgpu::FilterMode::Linear,
27                mipmap_filter: wgpu::MipmapFilterMode::Linear,
28                ..Default::default()
29            },
30            SamplerKind::LinearClamp => wgpu::SamplerDescriptor {
31                address_mode_u: wgpu::AddressMode::ClampToEdge,
32                address_mode_v: wgpu::AddressMode::ClampToEdge,
33                address_mode_w: wgpu::AddressMode::ClampToEdge,
34                mag_filter: wgpu::FilterMode::Linear,
35                min_filter: wgpu::FilterMode::Linear,
36                mipmap_filter: wgpu::MipmapFilterMode::Linear,
37                ..Default::default()
38            },
39            SamplerKind::LinearClampNoMip => wgpu::SamplerDescriptor {
40                address_mode_u: wgpu::AddressMode::ClampToEdge,
41                address_mode_v: wgpu::AddressMode::ClampToEdge,
42                address_mode_w: wgpu::AddressMode::ClampToEdge,
43                mag_filter: wgpu::FilterMode::Linear,
44                min_filter: wgpu::FilterMode::Linear,
45                mipmap_filter: wgpu::MipmapFilterMode::Linear,
46                lod_min_clamp: 0.0,
47                lod_max_clamp: 0.0,
48                ..Default::default()
49            },
50            SamplerKind::Nearest => wgpu::SamplerDescriptor {
51                mag_filter: wgpu::FilterMode::Nearest,
52                min_filter: wgpu::FilterMode::Nearest,
53                mipmap_filter: wgpu::MipmapFilterMode::Linear,
54                ..Default::default()
55            },
56        }
57    }
58}