Skip to content

Commit 1bd33ca

Browse files
committed
Default image sampler doc fix (#5047)
# Objective Attempt to more clearly document `ImageSettings` and setting a default sampler for new images, as per #5046 ## Changelog - Moved ImageSettings into image.rs, image::* is already exported. Makes it simpler for linking docs. - Renamed "DefaultImageSampler" to "RenderDefaultImageSampler". Not a great name, but more consistent with other render resources. - Added/updated related docs
1 parent 92eec47 commit 1bd33ca

File tree

2 files changed

+41
-34
lines changed

2 files changed

+41
-34
lines changed

crates/bevy_render/src/texture/image.rs

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,18 @@ pub struct Image {
108108
pub data: Vec<u8>,
109109
// TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors
110110
pub texture_descriptor: wgpu::TextureDescriptor<'static>,
111+
/// The [`ImageSampler`] to use during rendering.
111112
pub sampler_descriptor: ImageSampler,
112113
}
113114

114-
/// Used in `Image`, this determines what image sampler to use when rendering. The default setting,
115-
/// [`ImageSampler::Default`], will result in reading the sampler set in the [`DefaultImageSampler`]
116-
/// resource - the global default sampler - at runtime. Setting this to [`ImageSampler::Descriptor`]
117-
/// will override the global default descriptor for this [`Image`].
115+
/// Used in [`Image`], this determines what image sampler to use when rendering. The default setting,
116+
/// [`ImageSampler::Default`], will read the sampler from the [`ImageSettings`] resource at runtime.
117+
/// Setting this to [`ImageSampler::Descriptor`] will override the global default descriptor for this [`Image`].
118118
#[derive(Debug, Clone)]
119119
pub enum ImageSampler {
120+
/// Default image sampler, derived from the [`ImageSettings`] resource.
120121
Default,
122+
/// Custom sampler for this image which will override global default.
121123
Descriptor(wgpu::SamplerDescriptor<'static>),
122124
}
123125
impl Default for ImageSampler {
@@ -146,8 +148,41 @@ impl ImageSampler {
146148
}
147149
}
148150

149-
/// Resource used as the global default image sampler for [`Image`]s with their `sampler_descriptor`
150-
/// set to [`ImageSampler::Default`].
151+
/// Global resource for [`Image`] settings.
152+
///
153+
/// Can be set via `insert_resource` during app initialization to change the default settings.
154+
pub struct ImageSettings {
155+
/// The default image sampler to use when [`ImageSampler`] is set to `Default`.
156+
pub default_sampler: wgpu::SamplerDescriptor<'static>,
157+
}
158+
159+
impl Default for ImageSettings {
160+
fn default() -> Self {
161+
ImageSettings::default_linear()
162+
}
163+
}
164+
165+
impl ImageSettings {
166+
/// Creates image settings with linear sampling by default.
167+
pub fn default_linear() -> ImageSettings {
168+
ImageSettings {
169+
default_sampler: ImageSampler::linear_descriptor(),
170+
}
171+
}
172+
173+
/// Creates image settings with nearest sampling by default.
174+
pub fn default_nearest() -> ImageSettings {
175+
ImageSettings {
176+
default_sampler: ImageSampler::nearest_descriptor(),
177+
}
178+
}
179+
}
180+
181+
/// A rendering resource for the default image sampler which is set during renderer
182+
/// intialization.
183+
///
184+
/// The [`ImageSettings`] resource can be set during app initialization to change the default
185+
/// image sampler.
151186
#[derive(Debug, Clone, Deref, DerefMut)]
152187
pub struct DefaultImageSampler(pub(crate) Sampler);
153188

crates/bevy_render/src/texture/mod.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,6 @@ impl Plugin for ImagePlugin {
8282
}
8383
}
8484

85-
/// [`ImagePlugin`] settings.
86-
pub struct ImageSettings {
87-
/// The default image sampler to use when [`ImageSampler`] is set to `Default`.
88-
pub default_sampler: wgpu::SamplerDescriptor<'static>,
89-
}
90-
91-
impl Default for ImageSettings {
92-
fn default() -> Self {
93-
ImageSettings::default_linear()
94-
}
95-
}
96-
97-
impl ImageSettings {
98-
/// Creates image settings with default linear sampling.
99-
pub fn default_linear() -> ImageSettings {
100-
ImageSettings {
101-
default_sampler: ImageSampler::linear_descriptor(),
102-
}
103-
}
104-
105-
/// Creates image settings with default nearest sampling.
106-
pub fn default_nearest() -> ImageSettings {
107-
ImageSettings {
108-
default_sampler: ImageSampler::nearest_descriptor(),
109-
}
110-
}
111-
}
112-
11385
pub trait BevyDefault {
11486
fn bevy_default() -> Self;
11587
}

0 commit comments

Comments
 (0)