mew/
sampler.rs

1#[macro_export]
2macro_rules! sampler {
3    { $struct:ident as $filtering:ident } => {
4        $crate::sampler! { $struct as $filtering {} }
5    };
6    { $struct:ident as $filtering:ident {
7        $( $field:ident : $value:expr ),* $(,)?
8    } } => {
9        #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
10        pub struct $struct {
11            sampler: $crate::wgpu::Sampler,
12        }
13
14        impl ::std::ops::Deref for $struct {
15            type Target = $crate::wgpu::Sampler;
16            fn deref(&self) -> &Self::Target {
17                &self.sampler
18            }
19        }
20
21        impl $crate::sampler::MewSampler for $struct {
22            fn new(sampler: $crate::wgpu::Sampler) -> Self {
23                Self {
24                    sampler,
25                }
26            }
27
28            fn binding_type() -> $crate::wgpu::BindingType {
29                $crate::wgpu::BindingType::Sampler(
30                    $crate::wgpu::SamplerBindingType::$filtering
31                )
32            }
33
34            fn buffer_desc() -> $crate::wgpu::SamplerDescriptor<'static> {
35                use $crate::wgpu::{
36                    AddressMode::*,
37                    FilterMode::*,
38                    CompareFunction::*,
39                    SamplerBorderColor::*,
40                };
41                $crate::wgpu::SamplerDescriptor {
42                    label: Some(concat!(stringify!($struct), " Sampler")),
43                    $( $field : $value, )*
44                    ..Default::default()
45                }
46            }
47
48            fn as_binding<'a>(&'a self) -> $crate::wgpu::BindingResource<'a> {
49                $crate::wgpu::BindingResource::Sampler(&self.sampler)
50            }
51        }
52    }
53}
54pub use sampler;
55
56
57pub trait MewSampler {
58    fn new(buffer: wgpu::Sampler) -> Self;
59    fn binding_type() -> wgpu::BindingType;
60    fn buffer_desc() -> wgpu::SamplerDescriptor<'static>;
61    fn as_binding<'a>(&'a self) -> wgpu::BindingResource<'a>;
62}