2022-01-18 06:15:51 -06:00
|
|
|
use alloc::{boxed::Box, vec, vec::Vec};
|
|
|
|
use shadeable::pixel_format::{new_rgba64, Rgba64};
|
|
|
|
use vga::{colors::Color16, writers::GraphicsWriter};
|
|
|
|
|
|
|
|
use crate::vga_e::VGAE;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ScreenSize {
|
|
|
|
pub x: usize,
|
|
|
|
pub y: usize,
|
|
|
|
}
|
|
|
|
impl ScreenSize {
|
|
|
|
pub fn new(x: usize, y: usize) -> Self {
|
|
|
|
Self { x, y }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum GraphicsReturn {
|
|
|
|
Ok,
|
|
|
|
ImproperScreenSize,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct ScreenBuffer {
|
|
|
|
pub size: ScreenSize,
|
|
|
|
pub clear_color: Rgba64,
|
|
|
|
pub buff: Box<[Rgba64]>, // Vec<Rgba64>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ScreenBuffer {
|
|
|
|
// Add optional size later
|
|
|
|
pub fn new(x: usize, y: usize) -> Self {
|
|
|
|
Self {
|
|
|
|
size: ScreenSize::new(x, y),
|
|
|
|
clear_color: 0,
|
|
|
|
buff: vec![0u64; x * y].into_boxed_slice(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[inline]
|
|
|
|
pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) {
|
2022-01-18 08:30:09 -06:00
|
|
|
self.buff[y * self.size.x + x] = color;
|
2022-01-18 06:15:51 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn clear(&mut self) {
|
|
|
|
self.buff = vec![0u64; self.buff.len()].into_boxed_slice();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn blit(&mut self, _width: usize, _height: usize) {}
|
|
|
|
}
|
|
|
|
pub trait VgaBuffer {
|
|
|
|
fn copy_to_buffer(&self) -> GraphicsReturn;
|
|
|
|
}
|
|
|
|
impl VgaBuffer for ScreenBuffer {
|
|
|
|
fn copy_to_buffer(&self) -> GraphicsReturn {
|
|
|
|
let mode = VGAE.lock();
|
|
|
|
for y in 0..self.size.y {
|
|
|
|
for x in 0..self.size.x {
|
2022-01-18 08:30:09 -06:00
|
|
|
use shadeable::pixel_format::{get_color16, into_vga_16};
|
|
|
|
let vga_color = get_color16(self.buff[y * self.size.x + x]);
|
|
|
|
// let vga_color = into_vga_16(self.buff[y * self.size.x + x]);
|
2022-01-18 06:15:51 -06:00
|
|
|
mode.set_pixel(x, y, vga_color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GraphicsReturn::Ok
|
|
|
|
}
|
|
|
|
}
|