Skip to content

Commit c6a41cd

Browse files
committed
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)
1 parent be19c69 commit c6a41cd

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

crates/bevy_render/src/texture/image.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,20 @@ pub enum ImageSampler {
125125
}
126126

127127
impl ImageSampler {
128+
/// Returns an image sampler with `Linear` min and mag filters
129+
#[inline]
130+
pub fn linear() -> ImageSampler {
131+
ImageSampler::Descriptor(Self::linear_descriptor())
132+
}
133+
134+
/// Returns an image sampler with `nearest` min and mag filters
135+
#[inline]
136+
pub fn nearest() -> ImageSampler {
137+
ImageSampler::Descriptor(Self::nearest_descriptor())
138+
}
139+
128140
/// Returns a sampler descriptor with `Linear` min and mag filters
141+
#[inline]
129142
pub fn linear_descriptor() -> wgpu::SamplerDescriptor<'static> {
130143
wgpu::SamplerDescriptor {
131144
mag_filter: wgpu::FilterMode::Linear,
@@ -135,6 +148,7 @@ impl ImageSampler {
135148
}
136149

137150
/// Returns a sampler descriptor with `Nearest` min and mag filters
151+
#[inline]
138152
pub fn nearest_descriptor() -> wgpu::SamplerDescriptor<'static> {
139153
wgpu::SamplerDescriptor {
140154
mag_filter: wgpu::FilterMode::Nearest,

0 commit comments

Comments
 (0)