Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions wgpu-types/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
///
Expand Down Expand Up @@ -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<L> {
/// Debug label of the texture view. This will show up in graphics debuggers for easy identification.
pub label: L,
Expand Down Expand Up @@ -475,6 +477,24 @@ pub struct TextureViewDescriptor<L> {
pub array_layer_count: Option<u32>,
}

impl<L> TextureViewDescriptor<L> {
/// Takes a closure and maps the label of the texture view descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> TextureViewDescriptor<K> {
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,
}
}
}
Comment on lines +480 to +496
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't understand why this has to live in wgpu? Can't bevy take this code themself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not really necessary. I added it only because other types have this function.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@beicause Other types have this usually because it is used in wgpu code. For example I believe on the texture descriptor, the wgpu public API maps it to a wgpu-core-friendly generic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But users would need to map TextureViewDescriptor and SamplerDescriptor to references when creating TextureView/Sampler, too.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorta of the opinion that wgpu itself doesn't need this, since its a minor helper function that likely only bevy would use and it wouldn't hurt to have it live in bevy. But I also don't really care

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a reasonable helper to provide. We already have it for quite a few of the descriptor types.


/// Describes a [`Texture`](../wgpu/struct.Texture.html).
///
/// Corresponds to [WebGPU `GPUTextureDescriptor`](
Expand Down Expand Up @@ -683,6 +703,27 @@ impl<L: Default> Default for SamplerDescriptor<L> {
}
}

impl<L> SamplerDescriptor<L> {
/// Takes a closure and maps the label of the sampler descriptor into another.
#[must_use]
pub fn map_label<K>(&self, fun: impl FnOnce(&L) -> K) -> SamplerDescriptor<K> {
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`](
Expand Down