@@ -87,17 +87,6 @@ pub enum ColorMapper {
87
87
Texture ( GpuTexture2DHandle ) ,
88
88
}
89
89
90
- impl Default for ColormappedTexture {
91
- fn default ( ) -> Self {
92
- Self {
93
- texture : GpuTexture2DHandle :: invalid ( ) ,
94
- range : [ 0.0 , 1.0 ] ,
95
- gamma : 1.0 ,
96
- color_mapper : None ,
97
- }
98
- }
99
- }
100
-
101
90
impl ColormappedTexture {
102
91
pub fn from_unorm_srgba ( texture : GpuTexture2DHandle ) -> Self {
103
92
Self {
@@ -122,6 +111,10 @@ pub struct TexturedRect {
122
111
/// Texture that fills the rectangle
123
112
pub colormapped_texture : ColormappedTexture ,
124
113
114
+ pub options : RectangleOptions ,
115
+ }
116
+
117
+ pub struct RectangleOptions {
125
118
pub texture_filter_magnification : TextureFilterMag ,
126
119
pub texture_filter_minification : TextureFilterMin ,
127
120
@@ -134,13 +127,9 @@ pub struct TexturedRect {
134
127
pub outline_mask : OutlineMaskPreference ,
135
128
}
136
129
137
- impl Default for TexturedRect {
130
+ impl Default for RectangleOptions {
138
131
fn default ( ) -> Self {
139
132
Self {
140
- top_left_corner_position : glam:: Vec3 :: ZERO ,
141
- extent_u : glam:: Vec3 :: ZERO ,
142
- extent_v : glam:: Vec3 :: ZERO ,
143
- colormapped_texture : Default :: default ( ) ,
144
133
texture_filter_magnification : TextureFilterMag :: Nearest ,
145
134
texture_filter_minification : TextureFilterMin :: Linear ,
146
135
multiplicative_tint : Rgba :: WHITE ,
@@ -179,7 +168,7 @@ pub enum RectangleError {
179
168
mod gpu_data {
180
169
use crate :: wgpu_buffer_types;
181
170
182
- use super :: { ColorMapper , RectangleError } ;
171
+ use super :: { ColorMapper , RectangleError , TexturedRect } ;
183
172
184
173
// Keep in sync with mirror in rectangle.wgsl
185
174
@@ -231,12 +220,28 @@ mod gpu_data {
231
220
) -> Result < Self , RectangleError > {
232
221
let texture_info = texture_format. describe ( ) ;
233
222
223
+ let TexturedRect {
224
+ top_left_corner_position,
225
+ extent_u,
226
+ extent_v,
227
+ colormapped_texture,
228
+ options,
229
+ } = rectangle;
230
+
234
231
let super :: ColormappedTexture {
235
232
texture : _,
236
233
range,
237
234
gamma,
238
235
color_mapper,
239
- } = & rectangle. colormapped_texture ;
236
+ } = colormapped_texture;
237
+
238
+ let super :: RectangleOptions {
239
+ texture_filter_magnification : _,
240
+ texture_filter_minification : _,
241
+ multiplicative_tint,
242
+ depth_offset,
243
+ outline_mask,
244
+ } = options;
240
245
241
246
let sample_type = match texture_info. sample_type {
242
247
wgpu:: TextureSampleType :: Float { .. } => {
@@ -281,24 +286,24 @@ mod gpu_data {
281
286
}
282
287
}
283
288
284
- let minification_filter = match rectangle. texture_filter_minification {
289
+ let minification_filter = match rectangle. options . texture_filter_minification {
285
290
super :: TextureFilterMin :: Linear => FILTER_BILINEAR ,
286
291
super :: TextureFilterMin :: Nearest => FILTER_NEAREST ,
287
292
} ;
288
- let magnification_filter = match rectangle. texture_filter_magnification {
293
+ let magnification_filter = match rectangle. options . texture_filter_magnification {
289
294
super :: TextureFilterMag :: Linear => FILTER_BILINEAR ,
290
295
super :: TextureFilterMag :: Nearest => FILTER_NEAREST ,
291
296
} ;
292
297
293
298
Ok ( Self {
294
- top_left_corner_position : rectangle . top_left_corner_position . into ( ) ,
299
+ top_left_corner_position : ( * top_left_corner_position) . into ( ) ,
295
300
colormap_function,
296
- extent_u : rectangle . extent_u . into ( ) ,
301
+ extent_u : ( * extent_u) . into ( ) ,
297
302
sample_type,
298
- extent_v : rectangle . extent_v . into ( ) ,
299
- depth_offset : rectangle . depth_offset as f32 ,
300
- multiplicative_tint : rectangle . multiplicative_tint ,
301
- outline_mask : rectangle . outline_mask . 0 . unwrap_or_default ( ) . into ( ) ,
303
+ extent_v : ( * extent_v) . into ( ) ,
304
+ depth_offset : * depth_offset as f32 ,
305
+ multiplicative_tint : * multiplicative_tint,
306
+ outline_mask : outline_mask. 0 . unwrap_or_default ( ) . into ( ) ,
302
307
range_min_max : ( * range) . into ( ) ,
303
308
color_mapper : color_mapper_int,
304
309
gamma : * gamma,
@@ -346,15 +351,15 @@ impl RectangleDrawData {
346
351
} ) ;
347
352
}
348
353
349
- // TODO(emilk): continue on error (skipping just that rectangle)?
350
354
let textures: Vec < _ > = rectangles
351
355
. iter ( )
352
356
. map ( |rectangle| {
353
357
ctx. texture_manager_2d
354
358
. get ( & rectangle. colormapped_texture . texture )
355
359
} )
356
- . try_collect ( ) ? ;
360
+ . collect ( ) ;
357
361
362
+ // TODO(emilk): continue on error (skipping just that rectangle)?
358
363
let uniform_buffers: Vec < _ > = izip ! ( rectangles, & textures)
359
364
. map ( |( rect, texture) | {
360
365
gpu_data:: UniformBuffer :: from_textured_rect ( rect, & texture. creation_desc . format )
@@ -371,20 +376,20 @@ impl RectangleDrawData {
371
376
for ( rectangle, uniform_buffer, texture) in
372
377
izip ! ( rectangles, uniform_buffer_bindings, textures)
373
378
{
379
+ let options = & rectangle. options ;
374
380
let sampler = ctx. gpu_resources . samplers . get_or_create (
375
381
& ctx. device ,
376
382
& SamplerDesc {
377
383
label : format ! (
378
384
"rectangle sampler mag {:?} min {:?}" ,
379
- rectangle. texture_filter_magnification,
380
- rectangle. texture_filter_minification
385
+ options. texture_filter_magnification, options. texture_filter_minification
381
386
)
382
387
. into ( ) ,
383
- mag_filter : match rectangle . texture_filter_magnification {
388
+ mag_filter : match options . texture_filter_magnification {
384
389
TextureFilterMag :: Linear => wgpu:: FilterMode :: Linear ,
385
390
TextureFilterMag :: Nearest => wgpu:: FilterMode :: Nearest ,
386
391
} ,
387
- min_filter : match rectangle . texture_filter_minification {
392
+ min_filter : match options . texture_filter_minification {
388
393
TextureFilterMin :: Linear => wgpu:: FilterMode :: Linear ,
389
394
TextureFilterMin :: Nearest => wgpu:: FilterMode :: Nearest ,
390
395
} ,
@@ -430,7 +435,7 @@ impl RectangleDrawData {
430
435
let colormap_texture = if let Some ( ColorMapper :: Texture ( handle) ) =
431
436
& rectangle. colormapped_texture . color_mapper
432
437
{
433
- let colormap_texture = ctx. texture_manager_2d . get ( handle) ? ;
438
+ let colormap_texture = ctx. texture_manager_2d . get ( handle) ;
434
439
if colormap_texture. creation_desc . format != wgpu:: TextureFormat :: Rgba8UnormSrgb {
435
440
return Err ( RectangleError :: UnsupportedColormapTextureFormat (
436
441
colormap_texture. creation_desc . format ,
@@ -459,7 +464,7 @@ impl RectangleDrawData {
459
464
layout : rectangle_renderer. bind_group_layout ,
460
465
} ,
461
466
) ,
462
- draw_outline_mask : rectangle. outline_mask . is_some ( ) ,
467
+ draw_outline_mask : rectangle. options . outline_mask . is_some ( ) ,
463
468
} ) ;
464
469
}
465
470
0 commit comments