use super::TextureDataError;
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct TextureRegion {
x: u32,
y: u32,
width: u32,
height: u32,
}
impl TextureRegion {
pub const fn new(x: u32, y: u32, width: u32, height: u32) -> Result<Self, TextureDataError> {
if width == 0 || height == 0 {
return Err(TextureDataError::InvalidRegionDimensions { width, height });
}
Ok(Self {
x,
y,
width,
height,
})
}
#[must_use]
pub const fn x(self) -> u32 {
self.x
}
#[must_use]
pub const fn y(self) -> u32 {
self.y
}
#[must_use]
pub const fn width(self) -> u32 {
self.width
}
#[must_use]
pub const fn height(self) -> u32 {
self.height
}
pub(crate) const fn from_validated_dimensions(x: u32, y: u32, width: u32, height: u32) -> Self {
debug_assert!(width > 0 && height > 0);
Self {
x,
y,
width,
height,
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct TextureSubresource<'pixels> {
region: TextureRegion,
row_pitch: usize,
pixels: &'pixels [u8],
}
impl<'pixels> TextureSubresource<'pixels> {
#[must_use]
pub const fn new(region: TextureRegion, row_pitch: usize, pixels: &'pixels [u8]) -> Self {
Self {
region,
row_pitch,
pixels,
}
}
#[must_use]
pub const fn region(self) -> TextureRegion {
self.region
}
#[must_use]
pub const fn row_pitch(self) -> usize {
self.row_pitch
}
#[must_use]
pub const fn pixels(self) -> &'pixels [u8] {
self.pixels
}
}