ImageSampler linear/nearest constructors (#5466)

# Objective

I found this small ux hiccup when writing the 0.8 blog post:

```rust
image.sampler = ImageSampler::Descriptor(ImageSampler::nearest_descriptor());
```

Not good!

## Solution

```rust
image.sampler = ImageSampler::nearest();
```

(there are Good Reasons to keep around the nearest_descriptor() constructor and I think it belongs on this type)
This commit is contained in:
Carter Anderson 2022-07-27 06:49:37 +00:00
parent be19c696bd
commit c6a41cdd10

View file

@ -125,7 +125,20 @@ pub enum ImageSampler {
} }
impl ImageSampler { impl ImageSampler {
/// Returns an image sampler with `Linear` min and mag filters
#[inline]
pub fn linear() -> ImageSampler {
ImageSampler::Descriptor(Self::linear_descriptor())
}
/// Returns an image sampler with `nearest` min and mag filters
#[inline]
pub fn nearest() -> ImageSampler {
ImageSampler::Descriptor(Self::nearest_descriptor())
}
/// Returns a sampler descriptor with `Linear` min and mag filters /// Returns a sampler descriptor with `Linear` min and mag filters
#[inline]
pub fn linear_descriptor() -> wgpu::SamplerDescriptor<'static> { pub fn linear_descriptor() -> wgpu::SamplerDescriptor<'static> {
wgpu::SamplerDescriptor { wgpu::SamplerDescriptor {
mag_filter: wgpu::FilterMode::Linear, mag_filter: wgpu::FilterMode::Linear,
@ -135,6 +148,7 @@ impl ImageSampler {
} }
/// Returns a sampler descriptor with `Nearest` min and mag filters /// Returns a sampler descriptor with `Nearest` min and mag filters
#[inline]
pub fn nearest_descriptor() -> wgpu::SamplerDescriptor<'static> { pub fn nearest_descriptor() -> wgpu::SamplerDescriptor<'static> {
wgpu::SamplerDescriptor { wgpu::SamplerDescriptor {
mag_filter: wgpu::FilterMode::Nearest, mag_filter: wgpu::FilterMode::Nearest,