forked from AbleOS/ableos_userland
add in other sections of the AGL that will be supported in ableOS
This commit is contained in:
parent
450a22b05c
commit
441cb4cf81
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "able_graphics_library"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
dependencies = [
|
||||
"versioning",
|
||||
]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "able_graphics_library"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
|
|
@ -1,21 +1 @@
|
|||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub trait Color {}
|
||||
|
|
21
libraries/able_graphics_library/src/engine3d/color.rs
Normal file
21
libraries/able_graphics_library/src/engine3d/color.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
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,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use crate::{
|
||||
use super::{
|
||||
color::Color3,
|
||||
framebuffer::FrameBuffer,
|
||||
types::{BufferID, Position2},
|
|
@ -2,7 +2,7 @@ use core::ptr;
|
|||
|
||||
use alloc::vec::Vec;
|
||||
|
||||
use crate::color::Color3;
|
||||
use super::color::Color3;
|
||||
/// NOTE: Assumes the layout of RGBA
|
||||
pub struct FrameBuffer {
|
||||
pub width: u32,
|
7
libraries/able_graphics_library/src/engine3d/mod.rs
Normal file
7
libraries/able_graphics_library/src/engine3d/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub mod buffer;
|
||||
pub mod color;
|
||||
pub mod commands;
|
||||
pub mod display;
|
||||
pub mod framebuffer;
|
||||
pub mod types;
|
||||
pub mod vertex;
|
|
@ -1,6 +1,6 @@
|
|||
use alloc::vec::Vec;
|
||||
|
||||
use crate::{
|
||||
use super::{
|
||||
color::Color3,
|
||||
types::{Float2Array, Float3Array, Position3},
|
||||
};
|
|
@ -3,16 +3,33 @@
|
|||
#[macro_use]
|
||||
extern crate alloc;
|
||||
|
||||
pub mod buffer;
|
||||
pub mod color;
|
||||
pub mod commands;
|
||||
pub mod display;
|
||||
pub mod framebuffer;
|
||||
pub mod types;
|
||||
pub mod vertex;
|
||||
pub mod engine3d;
|
||||
pub mod ptmode;
|
||||
|
||||
pub const VERSION: versioning::Version = versioning::Version {
|
||||
major: 0,
|
||||
minor: 1,
|
||||
patch: 1,
|
||||
patch: 2,
|
||||
};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub enum GraphicsMode {
|
||||
// A simple single or double buffer
|
||||
RawPixels,
|
||||
// The 3D engine will be the ableOS equivelent of OpenGL or Vulkan
|
||||
Engine3D,
|
||||
// The PTMode is a simple tile graphics mode similar to the Nintendo Entertainment System or Super Nintendo Entertainment System
|
||||
// as well as providing a freeform 'Limitless' (within reason) mode
|
||||
PTMode,
|
||||
}
|
||||
|
||||
pub struct GraphicsSettings {
|
||||
mode: GraphicsMode,
|
||||
}
|
||||
|
||||
impl GraphicsSettings {
|
||||
pub fn get_mode(&self) -> GraphicsMode {
|
||||
self.mode
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
pub struct FreeFormColor {}
|
19
libraries/able_graphics_library/src/ptmode/mod.rs
Normal file
19
libraries/able_graphics_library/src/ptmode/mod.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
pub mod freeform;
|
||||
pub mod true_nes;
|
||||
pub mod true_snes;
|
||||
|
||||
use self::{freeform::FreeFormColor, true_nes::TrueNesColor, true_snes::TrueSnesColor};
|
||||
|
||||
pub struct NesColor(TrueNesColor);
|
||||
pub struct SnesColor(TrueSnesColor);
|
||||
pub struct FFColor(FreeFormColor);
|
||||
|
||||
// TODO Remake sprite data enum AFTER all sprite types are made
|
||||
pub enum SpriteData {
|
||||
NesSprite([[NesColor; 8]; 8]),
|
||||
SnesSprite([[SnesColor; 8]; 8]),
|
||||
FFSprite([[FFColor; 8]; 8]),
|
||||
}
|
||||
pub struct Sprite {
|
||||
pub sprite_data: SpriteData,
|
||||
}
|
99
libraries/able_graphics_library/src/ptmode/true_nes/mod.rs
Normal file
99
libraries/able_graphics_library/src/ptmode/true_nes/mod.rs
Normal file
|
@ -0,0 +1,99 @@
|
|||
/// Nes colors
|
||||
pub enum TrueNesColor {
|
||||
Gray = 0x00,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Tile;
|
||||
impl Tile {
|
||||
pub fn blank() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Nintendo is wrong and this is the closest approximation I will make to the scrolling logic for the NES.
|
||||
#[allow(non_camel_case_types)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct u9 {
|
||||
pub upper_bit: bool,
|
||||
pub lower_byte: u8,
|
||||
}
|
||||
//TODO impl a new() that takes various types
|
||||
impl u9 {
|
||||
pub fn new(id: u16) -> Self {
|
||||
let high_byte: u8 = ((id >> 8) << 7) as u8;
|
||||
let lower_byte: u8 = (id >> 8) as u8;
|
||||
|
||||
let high_bit = match high_byte {
|
||||
0 => false,
|
||||
_ => true,
|
||||
};
|
||||
|
||||
Self {
|
||||
upper_bit: high_bit,
|
||||
lower_byte,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type TileID = u9;
|
||||
|
||||
/// An NES accurate tilemap.
|
||||
pub type TileMap = [[TileID; 64]; 60];
|
||||
|
||||
pub struct PatternTable {
|
||||
tile_data: [Tile; 256],
|
||||
}
|
||||
impl PatternTable {
|
||||
pub fn blank() -> Self {
|
||||
Self {
|
||||
tile_data: [Tile; 256],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BackgroundMap {
|
||||
tilemap: TileMap,
|
||||
// scroll_offsets: [u9; 2],
|
||||
}
|
||||
impl BackgroundMap {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
tilemap: [[u9::new(0); 64]; 60],
|
||||
}
|
||||
}
|
||||
}
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Sprite {
|
||||
x: u8,
|
||||
y: u8,
|
||||
tile_id_a: TileID,
|
||||
/// Used to make 8x16 sprites
|
||||
tile_id_b: Option<TileID>,
|
||||
}
|
||||
impl Sprite {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
x: 0,
|
||||
y: 0,
|
||||
tile_id_a: TileID::new(0),
|
||||
tile_id_b: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub struct NesData {
|
||||
sprites: [Sprite; 64],
|
||||
background_map: BackgroundMap,
|
||||
pattern_table_a: PatternTable,
|
||||
pattern_table_b: PatternTable,
|
||||
}
|
||||
impl NesData {
|
||||
pub fn new() -> Self {
|
||||
NesData {
|
||||
sprites: [Sprite::new(); 64],
|
||||
background_map: BackgroundMap::new(),
|
||||
pattern_table_a: PatternTable::blank(),
|
||||
pattern_table_b: PatternTable::blank(),
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub struct TrueSnesColor {}
|
1
libraries/able_graphics_library/src/raw_pixel/lib.rs
Normal file
1
libraries/able_graphics_library/src/raw_pixel/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
Loading…
Reference in a new issue