diff --git a/wgpu-types/src/texture.rs b/wgpu-types/src/texture.rs index ae8e44848af..1dc91c1221c 100644 --- a/wgpu-types/src/texture.rs +++ b/wgpu-types/src/texture.rs @@ -37,6 +37,7 @@ pub enum TextureDimension { /// Order in which texture data is laid out in memory. #[derive(Clone, Copy, Default, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum TextureDataOrder { /// The texture is laid out densely in memory as: /// @@ -447,6 +448,7 @@ pub enum StorageTextureAccess { #[doc = link_to_wgpu_item!(struct TextureView)] #[doc = link_to_wgpu_docs!(["`Texture::create_view()`"]: "struct.Texture.html#method.create_view")] #[derive(Clone, Debug, Default, Eq, PartialEq)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct TextureViewDescriptor { /// Debug label of the texture view. This will show up in graphics debuggers for easy identification. pub label: L, @@ -475,6 +477,24 @@ pub struct TextureViewDescriptor { pub array_layer_count: Option, } +impl TextureViewDescriptor { + /// Takes a closure and maps the label of the texture view descriptor into another. + #[must_use] + pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor { + TextureViewDescriptor { + label: fun(&self.label), + format: self.format, + dimension: self.dimension, + usage: self.usage, + aspect: self.aspect, + base_mip_level: self.base_mip_level, + mip_level_count: self.mip_level_count, + base_array_layer: self.base_array_layer, + array_layer_count: self.array_layer_count, + } + } +} + /// Describes a [`Texture`](../wgpu/struct.Texture.html). /// /// Corresponds to [WebGPU `GPUTextureDescriptor`]( @@ -683,6 +703,27 @@ impl Default for SamplerDescriptor { } } +impl SamplerDescriptor { + /// Takes a closure and maps the label of the sampler descriptor into another. + #[must_use] + pub fn map_label(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor { + SamplerDescriptor { + label: fun(&self.label), + address_mode_u: self.address_mode_u, + address_mode_v: self.address_mode_v, + address_mode_w: self.address_mode_w, + mag_filter: self.mag_filter, + min_filter: self.min_filter, + mipmap_filter: self.mipmap_filter, + lod_min_clamp: self.lod_min_clamp, + lod_max_clamp: self.lod_max_clamp, + compare: self.compare, + anisotropy_clamp: self.anisotropy_clamp, + border_color: self.border_color, + } + } +} + /// How edges should be handled in texture addressing. /// /// Corresponds to [WebGPU `GPUAddressMode`](