Enum DataLayout

Source
pub enum DataLayout {
    Texture(Texture),
    Volume(Volume),
    TextureArray(TextureArray),
}
Expand description

The type and layout of the surfaces/volumes in the data section of a DDS file.

DDS is a container format and supports a few different data types (e.g. images, volumes, cube maps). While varied, the data section of a DDS file is always a contiguous block of data and its layout is 100% determined by the header. There are no gaps, padding, or markers in the data section, just the raw data of the surfaces/volumes. This makes it necessary for readers to know the layout of the data in order to read it correctly.

DataLayout contains all of this information while providing a simple interface to iterate over the surfaces/volumes.

Note: DataLayout provides no methods to read the data itself. Use crate::Decoder or crate::Encoder to read/write the data section.

Variants§

§

Texture(Texture)

A single texture with mipmaps (if any).

Example:

let header = Header::new_image(123, 345, Format::BC1_UNORM).with_mipmaps();
let layout = DataLayout::from_header(&header).unwrap();
let texture = layout.texture().unwrap();
assert_eq!(texture.main().size(), Size::new(123, 345));

// iterate over all mipmaps
for (level, mipmap) in texture.iter_mips().enumerate() {
    println!("Mipmap {}: {}x{}", level, mipmap.width(), mipmap.height());
}
§

Volume(Volume)

A 3D texture with mipmaps (if any).

DDS uses depth slices to represent 3D textures.

Example:

let header = Header::new_volume(123, 345, 678, Format::BC1_UNORM).with_mipmaps();
let layout = DataLayout::from_header(&header).unwrap();
let volume = layout.volume().unwrap();
assert_eq!(volume.main().size(), Size::new(123, 345));
assert_eq!(volume.main().depth(), 678);

// iterate over all mipmaps
for (level, mipmap) in volume.iter_mips().enumerate() {
    println!("Mipmap {}: {}x{}x{}", level, mipmap.width(), mipmap.height(), mipmap.depth());
}
§

TextureArray(TextureArray)

A simply array of 2D textures.

All textures within the array have the same size, mipmap count, and pixel format.

Example:

let mut header = Dx10Header::new_image(123, 345, DxgiFormat::BC1_UNORM);
header.array_size = 10;
let layout = DataLayout::from_header(&header.into()).unwrap();
let array = layout.texture_array().unwrap();
assert_eq!(array.len(), 10);
assert_eq!(array.size(), Size::new(123, 345));

// iterate over all textures in the array
for texture in array.iter() {
    for (level, mipmap) in texture.iter_mips().enumerate() {
        println!("Mipmap {}: {}x{}", level, mipmap.width(), mipmap.height());
    }
}
§Cube maps

Cube maps are a special case of texture arrays. You can differentiate between normal texture arrays and cube maps using TextureArray::kind().

The faces of a cube map are always stored in the order:

  1. Positive X
  2. Negative X
  3. Positive Y
  4. Negative Y
  5. Positive Z
  6. Negative Z

Note that cube maps come in 2 flavors: full cube maps and partial cube maps. Partial cube maps are cube maps with fewer than 6 faces (see TextureArrayKind::PartialCubeMap) and are not supported by DX10+. In practice, partial cube maps are rarely used. This library only supports them for completeness.

Example:

let mut header = Header::new_cube_map(256, 256, Format::BC1_UNORM).with_mipmaps();
let layout = DataLayout::from_header(&header).unwrap();
let array = layout.texture_array().unwrap();
assert_eq!(array.kind(), TextureArrayKind::CubeMaps);
assert_eq!(array.len(), 6); // 6 faces
assert_eq!(array.size(), Size::new(256, 256));

let positive_x = array.get(0).unwrap();
let negative_x = array.get(1).unwrap();
let positive_y = array.get(2).unwrap();
let negative_y = array.get(3).unwrap();
let positive_z = array.get(4).unwrap();
let negative_z = array.get(5).unwrap();

DX10 also supports arrays of cube maps. Example:

let mut header = Dx10Header::new_cube_map(256, 256, DxgiFormat::BC1_UNORM);
header.array_size = 3;
let layout = DataLayout::from_header(&header.into()).unwrap();
let array = layout.texture_array().unwrap();
assert_eq!(array.kind(), TextureArrayKind::CubeMaps);
assert_eq!(array.len(), 18); // 6 faces * 3 cube maps

Implementations§

Source§

impl DataLayout

Source

pub fn from_header(header: &Header) -> Result<Self, DecodingError>

Source

pub fn from_header_with( header: &Header, pixel_info: PixelInfo, ) -> Result<Self, LayoutError>

Source

pub fn main_size(&self) -> Size

The size of the level 0 object.

For single textures and texture arrays, this will return the size of the texture (mipmap level 0). For cube maps, this will return the size of the individual faces (mipmap level 0). For volume textures, this will return the size of the first depth slice (mipmap level 0).

Source

pub fn texture(&self) -> Option<Texture>

If this layout is a DataLayout::Texture, returns the texture.

Source

pub fn volume(&self) -> Option<Volume>

If this layout is a DataLayout::Volume, returns the volume.

Source

pub fn texture_array(&self) -> Option<TextureArray>

If this layout is a DataLayout::TextureArray, returns the texture array.

Source

pub fn is_cube_map(&self) -> bool

Whether this layout is a cube map or partial cube map.

If true is returned, this layout is guaranteed to be a DataLayout::TextureArray. The TextureArray::kind() will be either TextureArrayKind::CubeMaps or TextureArrayKind::PartialCubeMap.

The texture array is not guaranteed to be contain exactly one (partial) cube map.

Source

pub fn pixel_info(&self) -> PixelInfo

Trait Implementations§

Source§

impl Clone for DataLayout

Source§

fn clone(&self) -> DataLayout

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl DataRegion for DataLayout

Source§

fn data_len(&self) -> u64

The number of bytes this object occupies in the data section of a DDS file. Read more
Source§

fn data_offset(&self) -> u64

The byte offset of this object in the data section of a DDS file.
Source§

fn data_end(&self) -> u64

The byte offset of the byte after this object in the data section of a DDS file. Read more
Source§

impl Debug for DataLayout

Source§

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

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

impl Hash for DataLayout

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 PartialEq for DataLayout

Source§

fn eq(&self, other: &DataLayout) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const 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 Copy for DataLayout

Source§

impl Eq for DataLayout

Source§

impl StructuralPartialEq for DataLayout

Auto Trait Implementations§

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
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.