Struct wgpu_types::Extent3d
source · Expand description
Extent of a texture related operation.
Fields§
§width: u32§height: u32§depth_or_array_layers: u32Implementations§
source§impl Extent3d
impl Extent3d
sourcepub fn physical_size(&self, format: TextureFormat) -> Self
pub fn physical_size(&self, format: TextureFormat) -> Self
Calculates the physical size is backing an texture of the given format and extent. This includes padding to the block width and height of the format.
This is the texture extent that you must upload at when uploading to mipmaps of compressed textures.
let format = wgpu::TextureFormat::Bc1RgbaUnormSrgb; // 4x4 blocks
assert_eq!(
wgpu::Extent3d { width: 7, height: 7, depth_or_array_layers: 1 }.physical_size(format),
wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 }
);
// Doesn't change, already aligned
assert_eq!(
wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 }.physical_size(format),
wgpu::Extent3d { width: 8, height: 8, depth_or_array_layers: 1 }
);
let format = wgpu::TextureFormat::Astc8x5RgbaUnorm; // 8x5 blocks
assert_eq!(
wgpu::Extent3d { width: 7, height: 7, depth_or_array_layers: 1 }.physical_size(format),
wgpu::Extent3d { width: 8, height: 10, depth_or_array_layers: 1 }
);sourcepub fn max_mips(&self) -> u8
pub fn max_mips(&self) -> u8
Calculates the maximum possible count of mipmaps.
Treats the depth as part of the mipmaps. If calculating for a 2DArray texture, which does not mipmap depth, set depth to 1.
assert_eq!(wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 }.max_mips(), 1);
assert_eq!(wgpu::Extent3d { width: 60, height: 60, depth_or_array_layers: 1 }.max_mips(), 6);
assert_eq!(wgpu::Extent3d { width: 240, height: 1, depth_or_array_layers: 1 }.max_mips(), 8);sourcepub fn at_mip_level(&self, level: u8) -> Option<Self>
pub fn at_mip_level(&self, level: u8) -> Option<Self>
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 extent = wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 };
assert_eq!(extent.at_mip_level(0), Some(wgpu::Extent3d { width: 100, height: 60, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(1), Some(wgpu::Extent3d { width: 50, height: 30, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(2), Some(wgpu::Extent3d { width: 25, height: 15, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(3), Some(wgpu::Extent3d { width: 12, height: 7, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(4), Some(wgpu::Extent3d { width: 6, height: 3, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(5), Some(wgpu::Extent3d { width: 3, height: 1, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(6), Some(wgpu::Extent3d { width: 1, height: 1, depth_or_array_layers: 1 }));
assert_eq!(extent.at_mip_level(7), None);