use super::ConstBuffer;
impl<const WIDTH: usize, const HEIGHT: usize> ConstBuffer<WIDTH, HEIGHT>
where
[(); WIDTH * HEIGHT]:,
{
#[must_use]
pub const fn new(data: [u32; WIDTH * HEIGHT]) -> Self {
Self {
data,
}
}
#[must_use]
pub const fn new_empty() -> Self {
Self {
data: [0; WIDTH * HEIGHT],
}
}
#[must_use]
pub const fn new_empty_with_color(color: u32) -> Self {
Self {
data: [color; WIDTH * HEIGHT],
}
}
#[must_use]
#[allow(clippy::missing_panics_doc)]
pub fn generate_fallback(squares: usize) -> Self {
let mut data = [0; WIDTH * HEIGHT];
let square_size = WIDTH.midpoint(HEIGHT) / squares;
let purple = crate::graphics::rgba_to_u32(128, 0, 128, 255);
let black = crate::graphics::rgba_to_u32(0, 0, 0, 255);
for y in 0..HEIGHT {
for x in 0..WIDTH {
let square_x = x / square_size;
let square_y = y / square_size;
let color = if (square_x + square_y).is_multiple_of(2) {
purple
} else {
black
};
data[y * WIDTH + x] = color;
}
}
Self::new(data)
}
}