mewgpu 3.7.1

Maybe Easier Wgpu (mew), a thin abstraction over wgpu's chaos
Documentation
//! Wrapper over a
//! [`wgpu::Sampler`](https://docs.rs/wgpu/latest/wgpu/struct.Sampler.html).
//!
//! See [`sampler`] for details.


use crate::wgpu;


/// Define a sampler.
///
/// You can change the
/// [`wgpu::SamplerDescriptor`](https://docs.rs/wgpu/latest/wgpu/type.SamplerDescriptor.html)
/// properties if you want, the fields you omit will just be the default.
///
/// ```
/// sampler! { Sampler as Filtering {
///     address_mode_u: Repeat,
///     mag_filter: Nearest,
/// } }
///
/// let sampler: Sampler = context.new_sampler();
/// ```
#[macro_export]
macro_rules! sampler {
    { $struct:ident as $filtering:ident } => {
        $crate::sampler! { $struct as $filtering {} }
    };
    { $struct:ident as $filtering:ident {
        $( $field:ident: $value:expr ),* $(,)?
    } } => {
        #[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
        pub struct $struct {
            sampler: $crate::wgpu::Sampler,
        }

        impl ::std::ops::Deref for $struct {
            type Target = $crate::wgpu::Sampler;
            fn deref(&self) -> &Self::Target {
                &self.sampler
            }
        }

        impl $crate::sampler::MewSampler for $struct {
            fn new(sampler: $crate::wgpu::Sampler) -> Self {
                Self {
                    sampler,
                }
            }

            fn binding_type() -> $crate::wgpu::BindingType {
                $crate::wgpu::BindingType::Sampler(
                    $crate::wgpu::SamplerBindingType::$filtering
                )
            }

            fn buffer_desc() -> $crate::wgpu::SamplerDescriptor<'static> {
                #[allow(unused_imports)]
                use $crate::wgpu::{
                    AddressMode::*,
                    FilterMode::*,
                    CompareFunction::*,
                    SamplerBorderColor::*,
                };
                $crate::wgpu::SamplerDescriptor {
                    label: Some(concat!(stringify!($struct), " Sampler")),
                    $( $field : $value, )*
                    ..Default::default()
                }
            }

            fn as_binding(&self) -> $crate::wgpu::BindingResource<'_> {
                $crate::wgpu::BindingResource::Sampler(&self.sampler)
            }
        }
    }
}
pub use sampler;


/// Trait for internal use to work with samplers.
pub trait MewSampler {
    /// Build this sampler type from a
    /// [`wgpu::Sampler`](https://docs.rs/wgpu/latest/wgpu/struct.Sampler.html).
    fn new(buffer: wgpu::Sampler) -> Self;
    /// Get a [`wgpu::BindingType`](https://docs.rs/wgpu/latest/wgpu/enum.BindingType.html)
    /// to use for this type of sampler.
    fn binding_type() -> wgpu::BindingType;
    /// Get a [`wgpu::SamplerDescriptor`](https://docs.rs/wgpu/latest/wgpu/type.SamplerDescriptor.html)
    /// to build this type of sampler.
    fn buffer_desc() -> wgpu::SamplerDescriptor<'static>;
    /// Get this sampler's [`wgpu::BindingResource`](https://docs.rs/wgpu/latest/wgpu/enum.BindingResource.html)
    /// to bind it in a bind group.
    fn as_binding(&self) -> wgpu::BindingResource<'_>;
}