refactoring
This commit is contained in:
parent
387893cd55
commit
09bdaed3f5
3 changed files with 48 additions and 22 deletions
35
raytracer/Cargo.lock
generated
35
raytracer/Cargo.lock
generated
|
|
@ -2,6 +2,21 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "approx"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278"
|
||||||
|
dependencies = [
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "autocfg"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.3"
|
version = "0.10.3"
|
||||||
|
|
@ -20,6 +35,16 @@ version = "1.0.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cgmath"
|
||||||
|
version = "0.18.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1a98d30140e3296250832bbaaff83b27dcd6fa3cc70fb6f1f3e5c9c0023b5317"
|
||||||
|
dependencies = [
|
||||||
|
"approx",
|
||||||
|
"num-traits",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.176"
|
version = "0.2.176"
|
||||||
|
|
@ -32,6 +57,15 @@ version = "0.4.28"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "num-traits"
|
||||||
|
version = "0.2.19"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||||
|
dependencies = [
|
||||||
|
"autocfg",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro2"
|
name = "proc-macro2"
|
||||||
version = "1.0.101"
|
version = "1.0.101"
|
||||||
|
|
@ -74,6 +108,7 @@ dependencies = [
|
||||||
name = "raytracer"
|
name = "raytracer"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"cgmath",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"uefi",
|
"uefi",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cgmath = "0.18.0"
|
||||||
libc = "0.2.176"
|
libc = "0.2.176"
|
||||||
log = "0.4.28"
|
log = "0.4.28"
|
||||||
uefi = { version = "0.35.0", features = ["logger", "panic_handler"] }
|
uefi = { version = "0.35.0", features = ["logger", "panic_handler"] }
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ mod buffer;
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use uefi::allocator::Allocator;
|
use uefi::allocator::Allocator;
|
||||||
|
use uefi::boot::ScopedProtocol;
|
||||||
use uefi::prelude::*;
|
use uefi::prelude::*;
|
||||||
use uefi::proto::console::gop::GraphicsOutput;
|
use uefi::proto::console::gop::GraphicsOutput;
|
||||||
use uefi::{boot, Result};
|
use uefi::{boot, Result};
|
||||||
|
|
@ -14,36 +15,25 @@ use crate::buffer::Buffer;
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: Allocator = uefi::allocator::Allocator;
|
static ALLOCATOR: Allocator = uefi::allocator::Allocator;
|
||||||
|
|
||||||
|
fn init_gop() -> Result<ScopedProtocol<GraphicsOutput>> {
|
||||||
fn clear_buffer() -> Result<()>{
|
// Open graphics output protocol.
|
||||||
// Open graphics output protocol.
|
|
||||||
let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>()?;
|
let gop_handle = boot::get_handle_for_protocol::<GraphicsOutput>()?;
|
||||||
let mut gop = boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle)?;
|
boot::open_protocol_exclusive::<GraphicsOutput>(gop_handle)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fn init_buffer(gop: &GraphicsOutput) -> Buffer{
|
||||||
// Create a buffer to draw into.
|
// Create a buffer to draw into.
|
||||||
let (width, height) = gop.current_mode_info().resolution();
|
let (width, height) = gop.current_mode_info().resolution();
|
||||||
let mut buffer = Buffer::new(width, height);
|
Buffer::new(width, height)
|
||||||
|
|
||||||
// Initialize the buffer with a simple gradient background.
|
|
||||||
for y in 0..height {
|
|
||||||
let r = ((y as f32) / ((height - 1) as f32)) * 255.0;
|
|
||||||
for x in 0..width {
|
|
||||||
let g = ((x as f32) / ((width - 1) as f32)) * 255.0;
|
|
||||||
let pixel = buffer.pixel(x, y).unwrap();
|
|
||||||
pixel.red = r as u8;
|
|
||||||
pixel.green = g as u8;
|
|
||||||
pixel.blue = r as u8;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw background.
|
|
||||||
buffer.blit(&mut gop)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> Status {
|
fn main() -> Status {
|
||||||
uefi::helpers::init().unwrap();
|
uefi::helpers::init().unwrap();
|
||||||
clear_buffer().unwrap();
|
let mut gop = init_gop().unwrap();
|
||||||
|
let buffer = init_buffer(&gop);
|
||||||
|
buffer.blit(&mut gop).unwrap();
|
||||||
Status::SUCCESS
|
Status::SUCCESS
|
||||||
}
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue