use super::Error;
use num_enum::{IntoPrimitive, TryFromPrimitive};
#[derive(TryFromPrimitive, IntoPrimitive, Clone, Copy, Debug, Hash, PartialEq, Eq)]
#[repr(u8)]
pub enum Format {
Etc1 = 1,
#[num_enum(alternatives = [3])]
Etc2Eac = 2,
#[num_enum(alternatives = [11])]
Bc1 = 10,
Bc3 = 12,
Bc7 = 13,
Bc5Snorm = 14,
Bgra8 = 20,
Rgba16Float = 21,
Rgba32Float = 22,
}
impl Format {
pub fn from_u8(format: u8) -> Result<Self, Error> {
Self::try_from(format).map_err(|_| Error::UnknownTextureFormat(format))
}
pub fn to_u8(&self) -> u8 {
(*self).into()
}
pub fn block_size(&self) -> (usize, usize) {
match self {
Format::Bgra8 | Format::Rgba16Float | Format::Rgba32Float => (1, 1),
_ => (4, 4),
}
}
pub fn bytes_per_block(&self) -> usize {
match self {
Format::Etc1 => 8,
Format::Etc2Eac => 16,
Format::Bc1 => 8,
Format::Bc3 => 16,
Format::Bc7 => 16,
Format::Bc5Snorm => 16,
Format::Bgra8 => 4,
Format::Rgba16Float => 8,
Format::Rgba32Float => 16,
}
}
}