Skip to main content

TextureDescriptor

Struct TextureDescriptor 

Source
#[repr(C)]
pub struct TextureDescriptor<L, V> { pub label: L, pub size: Extent3d, pub mip_level_count: u32, pub sample_count: u32, pub dimension: TextureDimension, pub format: TextureFormat, pub usage: TextureUsages, pub view_formats: V, pub texture_binding_view_dimension: Option<TextureViewDimension>, }
Expand description

Describes a Texture.

Corresponds to WebGPU GPUTextureDescriptor.

Fields§

§label: L

Debug label of the texture. This will show up in graphics debuggers for easy identification.

§size: Extent3d

Size of the texture. All components must be greater than zero. For a regular 1D/2D texture, the unused sizes will be 1. For 2DArray textures, Z is the number of 2D textures in that array.

§mip_level_count: u32

Mip count of texture. For a texture with no extra mips, this must be 1.

§sample_count: u32

Sample count of texture. If this is not 1, texture must have BindingType::Texture::multisampled set to true.

§dimension: TextureDimension

Dimensions of the texture.

§format: TextureFormat

Format of the texture.

§usage: TextureUsages

Allowed usages of the texture. If used in other ways, the operation will panic.

§view_formats: V

Specifies what view formats will be allowed when calling Texture::create_view on this texture.

View formats of the same format as the texture are always allowed.

Note: currently, only the srgb-ness is allowed to change. (ex: Rgba8Unorm texture + Rgba8UnormSrgb view)

§texture_binding_view_dimension: Option<TextureViewDimension>

For devices without ARBITRARY_BINDING_VIEW_DIMENSIONS: views of this texture used as bindings must have this as their dimension. Pass it explicitly, or pass None to have it inferred from the texture’s dimension and layer count. Otherwise it is ignored.

Implementations§

Source§

impl<L, V> TextureDescriptor<L, V>

Source

pub fn map_label<'a, K>( &'a self, fun: impl FnOnce(&'a L) -> K, ) -> TextureDescriptor<K, V>
where V: Clone,

Takes a closure and maps the label of the texture descriptor into another.

Source

pub fn map_label_and_view_formats<'a, K, M>( &'a self, l_fun: impl FnOnce(&'a L) -> K, v_fun: impl FnOnce(&'a V) -> M, ) -> TextureDescriptor<K, M>

Maps the label and view formats of the texture descriptor into another.

Source

pub fn mip_level_size(&self, level: u32) -> Option<Extent3d>

Calculates the extent at a given mip level.

If the given mip level is larger than possible, returns None.

Treats the depth as part of the mipmaps. If calculating for a 2DArray texture, which does not mipmap depth, set depth to 1.

let desc  = TextureDescriptor {
  label: (),
  size: wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 },
  mip_level_count: 7,
  sample_count: 1,
  dimension: wgpu::TextureDimension::D3,
  format: wgpu::TextureFormat::Rgba8Sint,
  usage: wgpu::TextureUsages::empty(),
  view_formats: &[],
  texture_binding_view_dimension: None,
};

assert_eq!(desc.mip_level_size(0), Some(wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(1), Some(wgpu::Extent3d { width: 50, height: 30, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(2), Some(wgpu::Extent3d { width: 25, height: 15, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(3), Some(wgpu::Extent3d { width: 12, height: 7, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(4), Some(wgpu::Extent3d { width: 6, height: 3, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(5), Some(wgpu::Extent3d { width: 3, height: 1, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(6), Some(wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 }));
assert_eq!(desc.mip_level_size(7), None);
Source

pub fn array_layer_count(&self) -> u32

Source

pub fn theoretical_memory_footprint(&self) -> u64

Returns the theoretical memory footprint of a texture.

Actual memory usage may greatly exceed this value due to alignment and padding.

Source

pub fn default_view_dimension(&self) -> TextureViewDimension

Infer the view dimension from a given descriptor.

This is used when ARBITRARY_BINDING_VIEW_DIMENSIONS is not set. See https://gpuweb.github.io/gpuweb/#dom-gpudevice-createtexture

Trait Implementations§

Source§

impl<L: Clone, V: Clone> Clone for TextureDescriptor<L, V>

Source§

fn clone(&self) -> TextureDescriptor<L, V>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Debug, V: Debug> Debug for TextureDescriptor<L, V>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, L, V> Deserialize<'de> for TextureDescriptor<L, V>
where L: Deserialize<'de>, V: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<L: Hash, V: Hash> Hash for TextureDescriptor<L, V>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<L: PartialEq, V: PartialEq> PartialEq for TextureDescriptor<L, V>

Source§

fn eq(&self, other: &TextureDescriptor<L, V>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<L, V> Serialize for TextureDescriptor<L, V>
where L: Serialize, V: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<L: Eq, V: Eq> Eq for TextureDescriptor<L, V>

Source§

impl<L, V> StructuralPartialEq for TextureDescriptor<L, V>

Auto Trait Implementations§

§

impl<L, V> Freeze for TextureDescriptor<L, V>
where L: Freeze, V: Freeze,

§

impl<L, V> RefUnwindSafe for TextureDescriptor<L, V>

§

impl<L, V> Send for TextureDescriptor<L, V>
where L: Send, V: Send,

§

impl<L, V> Sync for TextureDescriptor<L, V>
where L: Sync, V: Sync,

§

impl<L, V> Unpin for TextureDescriptor<L, V>
where L: Unpin, V: Unpin,

§

impl<L, V> UnsafeUnpin for TextureDescriptor<L, V>
where L: UnsafeUnpin, V: UnsafeUnpin,

§

impl<L, V> UnwindSafe for TextureDescriptor<L, V>
where L: UnwindSafe, V: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,