#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub enum TextureViewDimension {
D1,
D2,
D2Array,
Cube,
CubeArray,
D3,
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)]
pub enum TextureDimension {
D1,
D2,
D3,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct Extent3d {
pub width: u32,
pub height: u32,
pub depth: u32,
}
#[derive(Copy, Hash, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
pub enum TextureComponentType {
Float,
Sint,
Uint,
}
pub struct PixelInfo {
pub type_size: usize,
pub num_components: usize,
}
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub enum TextureFormat {
R8Unorm = 0,
R8Snorm = 1,
R8Uint = 2,
R8Sint = 3,
R16Uint = 4,
R16Sint = 5,
R16Float = 6,
Rg8Unorm = 7,
Rg8Snorm = 8,
Rg8Uint = 9,
Rg8Sint = 10,
R32Uint = 11,
R32Sint = 12,
R32Float = 13,
Rg16Uint = 14,
Rg16Sint = 15,
Rg16Float = 16,
Rgba8Unorm = 17,
Rgba8UnormSrgb = 18,
Rgba8Snorm = 19,
Rgba8Uint = 20,
Rgba8Sint = 21,
Bgra8Unorm = 22,
Bgra8UnormSrgb = 23,
Rgb10a2Unorm = 24,
Rg11b10Float = 25,
Rg32Uint = 26,
Rg32Sint = 27,
Rg32Float = 28,
Rgba16Uint = 29,
Rgba16Sint = 30,
Rgba16Float = 31,
Rgba32Uint = 32,
Rgba32Sint = 33,
Rgba32Float = 34,
Depth32Float = 35,
Depth24Plus = 36,
Depth24PlusStencil8 = 37,
}
impl TextureFormat {
pub fn pixel_info(&self) -> PixelInfo {
let type_size = match self {
TextureFormat::R8Unorm
| TextureFormat::R8Snorm
| TextureFormat::R8Uint
| TextureFormat::R8Sint
| TextureFormat::Rg8Unorm
| TextureFormat::Rg8Snorm
| TextureFormat::Rg8Uint
| TextureFormat::Rg8Sint
| TextureFormat::Rgba8Unorm
| TextureFormat::Rgba8UnormSrgb
| TextureFormat::Rgba8Snorm
| TextureFormat::Rgba8Uint
| TextureFormat::Rgba8Sint
| TextureFormat::Bgra8Unorm
| TextureFormat::Bgra8UnormSrgb => 1,
TextureFormat::R16Uint
| TextureFormat::R16Sint
| TextureFormat::R16Float
| TextureFormat::Rg16Uint
| TextureFormat::Rg16Sint
| TextureFormat::Rg16Float
| TextureFormat::Rgba16Uint
| TextureFormat::Rgba16Sint
| TextureFormat::Rgba16Float => 2,
TextureFormat::R32Uint
| TextureFormat::R32Sint
| TextureFormat::R32Float
| TextureFormat::Rg32Uint
| TextureFormat::Rg32Sint
| TextureFormat::Rg32Float
| TextureFormat::Rgba32Uint
| TextureFormat::Rgba32Sint
| TextureFormat::Rgba32Float
| TextureFormat::Depth32Float => 4,
TextureFormat::Rgb10a2Unorm => 4,
TextureFormat::Rg11b10Float => 4,
TextureFormat::Depth24Plus => 3,
TextureFormat::Depth24PlusStencil8 => 4,
};
let components = match self {
TextureFormat::R8Unorm
| TextureFormat::R8Snorm
| TextureFormat::R8Uint
| TextureFormat::R8Sint
| TextureFormat::R16Uint
| TextureFormat::R16Sint
| TextureFormat::R16Float
| TextureFormat::R32Uint
| TextureFormat::R32Sint
| TextureFormat::R32Float => 1,
TextureFormat::Rg8Unorm
| TextureFormat::Rg8Snorm
| TextureFormat::Rg8Uint
| TextureFormat::Rg8Sint
| TextureFormat::Rg16Uint
| TextureFormat::Rg16Sint
| TextureFormat::Rg16Float
| TextureFormat::Rg32Uint
| TextureFormat::Rg32Sint
| TextureFormat::Rg32Float => 2,
TextureFormat::Rgba8Unorm
| TextureFormat::Rgba8UnormSrgb
| TextureFormat::Rgba8Snorm
| TextureFormat::Rgba8Uint
| TextureFormat::Rgba8Sint
| TextureFormat::Bgra8Unorm
| TextureFormat::Bgra8UnormSrgb
| TextureFormat::Rgba16Uint
| TextureFormat::Rgba16Sint
| TextureFormat::Rgba16Float
| TextureFormat::Rgba32Uint
| TextureFormat::Rgba32Sint
| TextureFormat::Rgba32Float => 4,
TextureFormat::Rgb10a2Unorm
| TextureFormat::Rg11b10Float
| TextureFormat::Depth32Float
| TextureFormat::Depth24Plus
| TextureFormat::Depth24PlusStencil8 => 1,
};
PixelInfo {
type_size,
num_components: components,
}
}
pub fn pixel_size(&self) -> usize {
let info = self.pixel_info();
info.type_size * info.num_components
}
}
bitflags::bitflags! {
#[repr(transparent)]
pub struct TextureUsage: u32 {
const COPY_SRC = 1;
const COPY_DST = 2;
const SAMPLED = 4;
const STORAGE = 8;
const OUTPUT_ATTACHMENT = 16;
const NONE = 0;
const READ_ALL = Self::COPY_SRC.bits | Self::SAMPLED.bits;
const WRITE_ALL = Self::COPY_DST.bits | Self::STORAGE.bits | Self::OUTPUT_ATTACHMENT.bits;
const ORDERED = Self::READ_ALL.bits | Self::OUTPUT_ATTACHMENT.bits;
const UNINITIALIZED = 0xFFFF;
}
}