diff --git a/crates/bevy_render/src/texture/image.rs b/crates/bevy_render/src/texture/image.rs index 4eca33b20fa62..8d92395b63c09 100644 --- a/crates/bevy_render/src/texture/image.rs +++ b/crates/bevy_render/src/texture/image.rs @@ -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