Skip to content

Commit

Permalink
ImageSampler::init_descriptor (#11113)
Browse files Browse the repository at this point in the history
Shortcut to avoid repetition in code like
#11109.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
  • Loading branch information
stepancheg and alice-i-cecile authored Aug 26, 2024
1 parent 6cc96f4 commit 2e36b27
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions crates/bevy_render/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2e36b27

Please sign in to comment.