render to framebuffer
This commit is contained in:
parent
3953ef2bfb
commit
ad6722fd3c
4 changed files with 102 additions and 3 deletions
55
raytracer/src/buffer.rs
Normal file
55
raytracer/src/buffer.rs
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
use uefi::proto::console::gop::{BltOp, BltPixel, BltRegion, GraphicsOutput};
|
||||
|
||||
extern crate alloc;
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use uefi::Error;
|
||||
|
||||
pub struct Buffer {
|
||||
width: usize,
|
||||
height: usize,
|
||||
pixels: Vec<BltPixel>,
|
||||
}
|
||||
|
||||
impl Buffer {
|
||||
/// Create a new `Buffer`.
|
||||
pub fn new(width: usize, height: usize) -> Self {
|
||||
Buffer {
|
||||
width,
|
||||
height,
|
||||
pixels: vec![BltPixel::new(0, 0, 0); width * height],
|
||||
}
|
||||
}
|
||||
|
||||
/// Get a single pixel.
|
||||
pub fn pixel(&mut self, x: usize, y: usize) -> Option<&mut BltPixel> {
|
||||
self.pixels.get_mut(y * self.width + x)
|
||||
}
|
||||
|
||||
/// Blit the buffer to the framebuffer.
|
||||
pub fn blit(&self, gop: &mut GraphicsOutput) -> Result<(), Error> {
|
||||
gop.blt(BltOp::BufferToVideo {
|
||||
buffer: &self.pixels,
|
||||
src: BltRegion::Full,
|
||||
dest: (0, 0),
|
||||
dims: (self.width, self.height),
|
||||
})
|
||||
}
|
||||
|
||||
/// Update only a pixel to the framebuffer.
|
||||
fn blit_pixel(
|
||||
&self,
|
||||
gop: &mut GraphicsOutput,
|
||||
coords: (usize, usize),
|
||||
) -> Result<(), Error> {
|
||||
gop.blt(BltOp::BufferToVideo {
|
||||
buffer: &self.pixels,
|
||||
src: BltRegion::SubRectangle {
|
||||
coords,
|
||||
px_stride: self.width,
|
||||
},
|
||||
dest: coords,
|
||||
dims: (1, 1),
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue