graphics lib update

This commit is contained in:
Able 2023-05-06 04:35:44 -05:00
parent a2bca6f901
commit 824697aa7c
13 changed files with 171 additions and 184 deletions

91
Cargo.lock generated
View file

@ -6,6 +6,7 @@ version = 3
name = "able_graphics_library" name = "able_graphics_library"
version = "0.1.2" version = "0.1.2"
dependencies = [ dependencies = [
"embedded-graphics",
"versioning", "versioning",
] ]
@ -35,7 +36,7 @@ dependencies = [
name = "aidl" name = "aidl"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"logos 0.13.0", "logos",
] ]
[[package]] [[package]]
@ -76,6 +77,12 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
name = "axel2wat" name = "axel2wat"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "az"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973"
[[package]] [[package]]
name = "base64" name = "base64"
version = "0.13.1" version = "0.13.1"
@ -98,6 +105,12 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]] [[package]]
name = "cfg-if" name = "cfg-if"
version = "1.0.0" version = "1.0.0"
@ -139,6 +152,38 @@ dependencies = [
name = "derelict_microarchitecture" name = "derelict_microarchitecture"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "embedded-graphics"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "750082c65094fbcc4baf9ba31583ce9a8bb7f52cadfb96f6164b1bc7f922f32b"
dependencies = [
"az",
"byteorder",
"embedded-graphics-core",
"float-cmp",
"micromath",
]
[[package]]
name = "embedded-graphics-core"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8b1239db5f3eeb7e33e35bd10bd014e7b2537b17e071f726a09351431337cfa"
dependencies = [
"az",
"byteorder",
]
[[package]]
name = "float-cmp"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1267f4ac4f343772758f7b1bdcbe767c218bbab93bb432acbf5162bbf85a6c4"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "fnv" name = "fnv"
version = "1.0.7" version = "1.0.7"
@ -225,22 +270,13 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "logos"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf8b031682c67a8e3d5446840f9573eb7fe26efe7ec8d195c9ac4c0647c502f1"
dependencies = [
"logos-derive 0.12.1",
]
[[package]] [[package]]
name = "logos" name = "logos"
version = "0.13.0" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1" checksum = "c000ca4d908ff18ac99b93a062cb8958d331c3220719c52e77cb19cc6ac5d2c1"
dependencies = [ dependencies = [
"logos-derive 0.13.0", "logos-derive",
] ]
[[package]] [[package]]
@ -257,20 +293,6 @@ dependencies = [
"syn 2.0.15", "syn 2.0.15",
] ]
[[package]]
name = "logos-derive"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d849148dbaf9661a6151d1ca82b13bb4c4c128146a88d05253b38d4e2f496c"
dependencies = [
"beef",
"fnv",
"proc-macro2",
"quote",
"regex-syntax",
"syn 1.0.105",
]
[[package]] [[package]]
name = "logos-derive" name = "logos-derive"
version = "0.13.0" version = "0.13.0"
@ -295,10 +317,25 @@ dependencies = [
"versioning", "versioning",
] ]
[[package]]
name = "micromath"
version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc4010833aea396656c2f91ee704d51a6f1329ec2ab56ffd00bfd56f7481ea94"
[[package]] [[package]]
name = "no_video" name = "no_video"
version = "0.1.0" version = "0.1.0"
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "number_prefix" name = "number_prefix"
version = "0.4.0" version = "0.4.0"
@ -590,7 +627,7 @@ checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3"
name = "uri" name = "uri"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"logos 0.13.0", "logos",
] ]
[[package]] [[package]]
@ -631,7 +668,7 @@ dependencies = [
name = "wat2wasm" name = "wat2wasm"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"logos 0.12.1", "logos",
] ]
[[package]] [[package]]

View file

@ -7,3 +7,4 @@ edition = "2021"
[dependencies] [dependencies]
versioning = { path = "../versioning" } versioning = { path = "../versioning" }
embedded-graphics = "0.7.1"

View file

@ -6,8 +6,6 @@ use alloc::vec::Vec;
use super::error::GPUError; use super::error::GPUError;
pub type VertexBuffer = Vec<u8>;
#[repr(C)] #[repr(C)]
pub struct XYZ { pub struct XYZ {
x: f64, x: f64,
@ -22,28 +20,3 @@ pub struct XYZW {
z: f64, z: f64,
w: f64, w: f64,
} }
pub struct GraphicsEngine {
vertex_buffer_attributes_editable: bool,
vertex_buffer: VertexBuffer,
vertex_size: usize,
}
impl GraphicsEngine {
pub fn new() -> Self {
Self {
vertex_buffer_attributes_editable: true,
vertex_buffer: Vec::new(),
vertex_size: 0,
}
}
pub fn append_vertex(&mut self, mut vertex: Vec<u8>) -> Result<(), GPUError> {
if self.vertex_buffer_attributes_editable {
return Err(GPUError::EngineNotInitialized);
}
if !vertex.len() == self.vertex_size {
return Err(GPUError::ImproperVertexSize);
}
self.vertex_buffer.append(&mut vertex);
Ok(())
}
}

View file

@ -1,21 +0,0 @@
pub struct Color3 {
pub r: u8,
pub g: u8,
pub b: u8,
}
impl Color3 {
/// Usage
/// The alpha value is a number between 0.0 and 1.0, which represents the transparency
/// or translucency of the other color.
pub fn blend(&self, other: &Self, alpha: f32) -> Self {
let r = (1.0 - alpha) * f32::from(self.r) + alpha * f32::from(other.r);
let g = (1.0 - alpha) * f32::from(self.g) + alpha * f32::from(other.g);
let b = (1.0 - alpha) * f32::from(self.b) + alpha * f32::from(other.b);
Self {
r: r as u8,
g: g as u8,
b: b as u8,
}
}
}

View file

@ -1,35 +0,0 @@
use alloc::vec::Vec;
pub enum DisplayError {
InvalidFormat,
InvalidWidth,
InvalidHeight,
InvalidBPP,
InvalidFPS,
}
pub fn parse_display_string(s: &str) -> Result<(u32, u32, u32, u32), DisplayError> {
let parts: Vec<&str> = s.split('x').collect();
if parts.len() != 3 {
return Err(DisplayError::InvalidFormat);
}
let width = parts[0]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidWidth)?;
let height = parts[1]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidHeight)?;
let bits: Vec<&str> = parts[2].split('@').collect();
if bits.len() != 2 {
return Err(DisplayError::InvalidFormat);
}
let bpp = bits[0]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidBPP)?;
let fps = bits[1]
.parse::<u32>()
.map_err(|_| DisplayError::InvalidFPS)?;
Ok((width, height, bpp, fps))
}

View file

@ -1,4 +0,0 @@
pub enum GPUError {
ImproperVertexSize = 10,
EngineNotInitialized = 100,
}

View file

@ -1,54 +0,0 @@
use core::ptr;
use alloc::vec::Vec;
use super::color::Color3;
/// NOTE: Assumes the layout of RGBA
pub struct FrameBuffer {
pub width: u32,
pub height: u32,
pub data: Vec<u32>,
}
impl FrameBuffer {
pub fn new(width: u32, height: u32) -> Self {
let data = vec![0; (width * height) as usize];
FrameBuffer {
width,
height,
data,
}
}
/// WARNING: Slow
pub fn set_pixel(&mut self, x: u32, y: u32, color: u32) {
let index = (y * self.width + x) as usize;
self.data[index] = color;
}
/// WARNING: Slow
pub fn get_pixel(&self, x: u32, y: u32) -> u32 {
let index = (y * self.width + x) as usize;
self.data[index]
}
/// Quickly writes the provided color to the whole framebuffer
pub fn clear(&mut self, color: Color3) {
unsafe {
// TODO: properly clear instead of only copying red
ptr::write_bytes(self.data.as_mut_ptr(), color.r, self.data.len());
}
}
// TODO(Able): Test preformance of clear2
#[allow(dead_code)]
fn clear2(&mut self, color: u32) {
self.data.fill(color);
}
/// Check the size of one framebuffer vs the other.
/// NOTE: Just because this returns false does not mean that something is wrong
/// there are cases that this makes sense
pub fn check_size(&self, other: &FrameBuffer) -> bool {
self.width == other.width && self.height == other.height
}
}

View file

@ -1,5 +1 @@
pub mod buffer; pub mod vertex;
pub mod color;
pub mod display;
pub mod error;
pub mod framebuffer;

View file

@ -0,0 +1,48 @@
use alloc::vec::Vec;
pub type VertexBuffer = Vec<u8>;
pub struct GraphicsEngine {
vertex_buffer_attributes_editable: bool,
vertex_buffer: VertexBuffer,
vertex_size: usize,
}
impl GraphicsEngine {
pub fn new() -> Self {
Self {
vertex_buffer_attributes_editable: true,
vertex_buffer: Vec::new(),
vertex_size: 0,
}
}
pub fn append_vertex(&mut self, mut vertex: Vec<u8>) -> Result<(), GPUError> {
if self.vertex_buffer_attributes_editable {
return Err(GPUError::EngineNotInitialized);
}
if !vertex.len() == self.vertex_size {
return Err(GPUError::ImproperVertexSize);
}
self.vertex_buffer.append(&mut vertex);
Ok(())
}
}
#[repr(C)]
pub struct XYZ {
x: f64,
y: f64,
z: f64,
}
#[repr(C)]
pub struct XYZW {
x: f64,
y: f64,
z: f64,
w: f64,
}
pub enum GPUError {
ImproperVertexSize,
EngineNotInitialized,
}

View file

@ -0,0 +1 @@
pub mod x86;

View file

@ -0,0 +1,52 @@
use embedded_graphics::{
pixelcolor::Rgb888,
prelude::{DrawTarget, IntoStorage, OriginDimensions, Size},
Pixel,
};
pub struct Display {
fb: *mut u32,
size: Size,
}
unsafe impl Send for Display {}
impl DrawTarget for Display {
type Color = Rgb888;
type Error = BlitOutOfBoundsError;
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where
I: IntoIterator<Item = Pixel<Self::Color>>,
{
for Pixel(pos, rgb) in pixels {
let pos_x = u32::try_from(pos.x).map_err(|_| BlitOutOfBoundsError)?;
let pos_y = u32::try_from(pos.y).map_err(|_| BlitOutOfBoundsError)?;
unsafe {
if pos_x >= self.size.width || pos_y >= self.size.height {
return Err(BlitOutOfBoundsError);
}
self.fb
.add(
(pos_y * self.size.width + pos_x)
.try_into()
.map_err(|_| BlitOutOfBoundsError)?,
)
.write_volatile(rgb.into_storage());
}
}
Ok(())
}
}
impl OriginDimensions for Display {
#[inline]
fn size(&self) -> Size {
self.size
}
}
#[derive(Debug)]
pub struct BlitOutOfBoundsError;

View file

@ -1,18 +1,12 @@
mod arch;
use alloc::vec::Vec; use alloc::vec::Vec;
use arch::x86::Display;
pub struct Color { pub struct Color {
r: u8, r: u8,
g: u8, g: u8,
b: u8, b: u8,
a: u8, a: u8,
} }
pub struct PixelBuffer {
width: usize,
height: usize,
data: Vec<Color>,
}
impl PixelBuffer {
pub fn xy_calc(x: usize, y: isize) {}
pub fn blit(&mut self, x: isize, y: isize, buff: PixelBuffer) {}
}

View file

@ -25,7 +25,6 @@ userspace = "https://git.ablecorp.us/AbleOS/ableos_userland"
version = "0.1.1" version = "0.1.1"
hash = "" hash = ""
repo = "userspace" repo = "userspace"
authors = []
[packages.list_files.configuration] [packages.list_files.configuration]