#[derive(Clone, Debug, PartialEq, Eq, thiserror::Error)]
pub enum Error {
#[error("CellGcmTexture requires 24 bytes, got {0}")]
DescriptorLength(usize),
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CellGcmTexture {
pub format: u8,
pub mipmap: u8,
pub dimension: u8,
pub cubemap: u8,
pub remap: u32,
pub width: u16,
pub height: u16,
pub depth: u16,
pub location: u8,
pub pad: u8,
pub pitch: u32,
pub offset: u32,
}
impl CellGcmTexture {
pub fn parse(data: &[u8]) -> Result<Self, Error> {
let &[
format,
mipmap,
dimension,
cubemap,
r0,
r1,
r2,
r3,
w0,
w1,
h0,
h1,
d0,
d1,
location,
pad,
p0,
p1,
p2,
p3,
o0,
o1,
o2,
o3,
] = <&[u8; 24]>::try_from(data).map_err(|_| Error::DescriptorLength(data.len()))?;
Ok(Self {
format,
mipmap,
dimension,
cubemap,
remap: u32::from_be_bytes([r0, r1, r2, r3]),
width: u16::from_be_bytes([w0, w1]),
height: u16::from_be_bytes([h0, h1]),
depth: u16::from_be_bytes([d0, d1]),
location,
pad,
pitch: u32::from_be_bytes([p0, p1, p2, p3]),
offset: u32::from_be_bytes([o0, o1, o2, o3]),
})
}
pub fn linear(self) -> bool {
self.format & 0x20 != 0
}
pub fn unnormalized_coordinates(self) -> bool {
self.format & 0x40 != 0
}
}