ImageSampler::init_descriptor (#11113)

Shortcut to avoid repetition in code like
https://github.com/bevyengine/bevy/pull/11109.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
This commit is contained in:
Stepan Koltsov 2024-08-26 18:56:37 +01:00 committed by GitHub
parent 6cc96f4c1f
commit 2e36b2719c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -202,6 +202,23 @@ impl ImageSampler {
pub fn nearest() -> ImageSampler {
ImageSampler::Descriptor(ImageSamplerDescriptor::nearest())
}
/// Initialize the descriptor if it is not already initialized.
///
/// Descriptor is typically initialized by Bevy when the image is loaded,
/// so this is convenient shortcut for updating the descriptor.
pub fn get_or_init_descriptor(&mut self) -> &mut ImageSamplerDescriptor {
match self {
ImageSampler::Default => {
*self = ImageSampler::Descriptor(ImageSamplerDescriptor::default());
match self {
ImageSampler::Descriptor(descriptor) => descriptor,
_ => unreachable!(),
}
}
ImageSampler::Descriptor(descriptor) => descriptor,
}
}
}
/// A rendering resource for the default image sampler which is set during renderer