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                #[allow(unused_imports)]
36                use $crate::wgpu::{
37                    AddressMode::*,
38                    FilterMode::*,
39                    CompareFunction::*,
40                    SamplerBorderColor::*,
41                };
42                $crate::wgpu::SamplerDescriptor {
43                    label: Some(concat!(stringify!($struct), " Sampler")),
44                    $( $field : $value, )*
45                    ..Default::default()
46                }
47            }
48
49            fn as_binding<'a>(&'a self) -> $crate::wgpu::BindingResource<'a> {
50                $crate::wgpu::BindingResource::Sampler(&self.sampler)
51            }
52        }
53    }
54}
55pub use sampler;
56
57
58pub trait MewSampler {
59    fn new(buffer: wgpu::Sampler) -> Self;
60    fn binding_type() -> wgpu::BindingType;
61    fn buffer_desc() -> wgpu::SamplerDescriptor<'static>;
62    fn as_binding<'a>(&'a self) -> wgpu::BindingResource<'a>;
63}