pub trait Dimensionable {
    type Size: Copy;
    type Offset: Copy;

    const ZERO_OFFSET: Self::Offset;

    fn dim() -> Dim;
    fn width(size: Self::Size) -> u32;
    fn x_offset(offset: Self::Offset) -> u32;
    fn count(size: Self::Size) -> usize;

    fn height(Self::Size) -> u32 { ... }
    fn depth(Self::Size) -> u32 { ... }
    fn y_offset(Self::Offset) -> u32 { ... }
    fn z_offset(Self::Offset) -> u32 { ... }
}
Expand description

Class of Texture dimensions.

This trait provides a simple mapping between the implementor and the Dim type, which represents a Texture dimension. This allows to heavily type Texture so that their dimension is indexed-tracked in the type-system. This trait is then used to reify the implementors into Dim so that the runtime can work with them.

Associated Types

Size type of a dimension (used to caracterize dimensions’ areas).

Offset type of a dimension (used to caracterize addition and subtraction of sizes, mostly).

Associated Constants

Zero offset.

Any size added with ZERO_OFFSET must remain the size itself.

Required methods

Reified Dim.

Implementors must ensure they map to the right variant of Dim.

Width of the associated Dimensionable::Size.

X offset.

Amount of pixels this size represents.

For 2D sizes, it represents the area; for 3D sizes, the volume; etc. For cubemaps, it represents the side length of the cube.

Provided methods

Height of the associated Dimensionable::Size. If it doesn’t have one, set it to 1.

Depth of the associated Dimensionable::Size. If it doesn’t have one, set it to 1.

Y offset. If it doesn’t have one, set it to 0.

Z offset. If it doesn’t have one, set it to 0.

Implementors