@@ -108,16 +108,18 @@ pub struct Image {
108
108
pub data : Vec < u8 > ,
109
109
// TODO: this nesting makes accessing Image metadata verbose. Either flatten out descriptor or add accessors
110
110
pub texture_descriptor : wgpu:: TextureDescriptor < ' static > ,
111
+ /// The [`ImageSampler`] to use during rendering.
111
112
pub sampler_descriptor : ImageSampler ,
112
113
}
113
114
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`].
118
118
#[ derive( Debug , Clone ) ]
119
119
pub enum ImageSampler {
120
+ /// Default image sampler, derived from the [`ImageSettings`] resource.
120
121
Default ,
122
+ /// Custom sampler for this image which will override global default.
121
123
Descriptor ( wgpu:: SamplerDescriptor < ' static > ) ,
122
124
}
123
125
impl Default for ImageSampler {
@@ -146,8 +148,41 @@ impl ImageSampler {
146
148
}
147
149
}
148
150
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.
151
186
#[ derive( Debug , Clone , Deref , DerefMut ) ]
152
187
pub struct DefaultImageSampler ( pub ( crate ) Sampler ) ;
153
188
0 commit comments