mirror of
https://github.com/griffi-gh/hUI.git
synced 2025-04-10 01:46:28 -05:00
wip euc
This commit is contained in:
parent
1049ec1268
commit
6dfebcdc87
|
@ -5,7 +5,10 @@ edition = "2024"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
hui-painter = { version = "=0.1.0-alpha.7", path = "../hui-painter", default-features = false }
|
||||||
euc = { version = "0.5", default-features = false }
|
euc = { version = "0.5", default-features = false }
|
||||||
|
glam = "0.30"
|
||||||
|
# vek = "0.17"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = [ "std" ]
|
default = [ "std" ]
|
||||||
|
|
|
@ -1,34 +1,30 @@
|
||||||
#![cfg_attr(not(feature = "std"), no_std)]
|
#![cfg_attr(not(feature = "std"), no_std)]
|
||||||
|
|
||||||
// TODO
|
use hui_painter::backend::BackendData;
|
||||||
|
|
||||||
use euc::Pipeline;
|
mod pipeline;
|
||||||
|
use pipeline::UiPipeline;
|
||||||
|
|
||||||
struct UiPipeline;
|
pub struct EucUiRenderer {
|
||||||
|
pipeline: UiPipeline,
|
||||||
|
// output: Buffer2d<<UiPipeline as Pipeline>::Pixel>,
|
||||||
|
}
|
||||||
|
|
||||||
impl Pipeline for UiPipeline {
|
impl EucUiRenderer {
|
||||||
type Vertex = [f32; 2];
|
pub fn new() -> Self {
|
||||||
type VsOut = ();
|
Self {
|
||||||
type Pixel = [u8; 4];
|
pipeline: UiPipeline::default(),
|
||||||
|
}
|
||||||
// Vertex shader
|
|
||||||
fn vert(&self, pos: &Self::Vertex) -> ([f32; 4], Self::VsOut) {
|
|
||||||
([pos[0], pos[1], 0.0, 1.0], ())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fragment shader
|
pub fn update(&mut self, data: &BackendData) {
|
||||||
fn frag(&self, _: &Self::VsOut) -> Self::Pixel {
|
|
||||||
[0, 0, 0, 255]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn main() {
|
impl Default for EucUiRenderer {
|
||||||
// let mut color = Buffer2d::new([640, 480], [0; 4]);
|
fn default() -> Self {
|
||||||
// let mut depth = Buffer2d::new([640, 480], 1.0);
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Example.draw::<Triangles<_>, _>(
|
|
||||||
// &[[-1.0, -1.0], [1.0, -1.0], [0.0, 1.0]],
|
|
||||||
// &mut color,
|
|
||||||
// &mut depth,
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
|
|
67
hui-euc/src/pipeline.rs
Normal file
67
hui-euc/src/pipeline.rs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
|
||||||
|
use euc::{buffer::Buffer2d, Interpolate, Pipeline, Target};
|
||||||
|
use glam::{Vec2, Vec4};
|
||||||
|
use hui_painter::paint::buffer::Vertex;
|
||||||
|
|
||||||
|
pub struct UiPipeline {
|
||||||
|
atlas: Buffer2d<[u8; 4]>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct VsOut {
|
||||||
|
position: Vec2,
|
||||||
|
color: Vec4,
|
||||||
|
uv: Vec2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Interpolate for VsOut {
|
||||||
|
fn lerp2(a: Self, b: Self, x: f32, y: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
position: a.position.mul_add(Vec2::splat(x), y * b.position),
|
||||||
|
color: a.color.mul_add(Vec4::splat(x), y * b.color),
|
||||||
|
uv: a.uv.mul_add(Vec2::splat(x), y * b.uv),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn lerp3(a: Self, b: Self, c: Self, x: f32, y: f32, z: f32) -> Self {
|
||||||
|
Self {
|
||||||
|
position: a.position.mul_add(Vec2::splat(x), b.position.mul_add(Vec2::splat(y), z * c.position)),
|
||||||
|
color: a.color.mul_add(Vec4::splat(x), b.color.mul_add(Vec4::splat(y), z * c.color)),
|
||||||
|
uv: a.uv.mul_add(Vec2::splat(x), b.uv.mul_add(Vec2::splat(y), z * c.uv)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for UiPipeline {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
atlas: Buffer2d::new([0, 0], [0; 4]),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pipeline for UiPipeline {
|
||||||
|
type Vertex = Vertex;
|
||||||
|
type VsOut = VsOut;
|
||||||
|
type Pixel = [u8; 4];
|
||||||
|
|
||||||
|
// Vertex shader
|
||||||
|
fn vert(&self, vtx: &Self::Vertex) -> ([f32; 4], Self::VsOut) {
|
||||||
|
([vtx.position.x, vtx.position.y, 0.0, 0.0], VsOut {
|
||||||
|
position: vtx.position,
|
||||||
|
color: vtx.color,
|
||||||
|
uv: vtx.uv,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fragment shader
|
||||||
|
fn frag(&self, vs: &Self::VsOut) -> Self::Pixel {
|
||||||
|
let color = vs.color.to_array().map(|x| (x * 255.).round() as u8);
|
||||||
|
color //TODO sampling
|
||||||
|
// match vs.uv != Vec2::ZERO {
|
||||||
|
// true => color * self.atlas.get(),
|
||||||
|
// false => color,
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ hui-winit = { path = "../hui-winit" }
|
||||||
kubi-logging = { git = "https://github.com/griffi-gh/kubi", rev = "1e051c47b64c967305e4bbbd464ef5da2cc56bbb" }
|
kubi-logging = { git = "https://github.com/griffi-gh/kubi", rev = "1e051c47b64c967305e4bbbd464ef5da2cc56bbb" }
|
||||||
glium = "0.36"
|
glium = "0.36"
|
||||||
winit = "0.30"
|
winit = "0.30"
|
||||||
|
minifb = "0.28"
|
||||||
glam = "0.30"
|
glam = "0.30"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
image = { version = "0.25", features = ["jpeg", "png"] }
|
image = { version = "0.25", features = ["jpeg", "png"] }
|
||||||
|
|
17
hui-examples/examples/test_hui_euc.rs
Normal file
17
hui-examples/examples/test_hui_euc.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
use minifb::{Window, WindowOptions};
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
let mut window = Window::new(
|
||||||
|
"hUI minfb (hui-euc)",
|
||||||
|
800, 600,
|
||||||
|
WindowOptions::default()
|
||||||
|
).unwrap();
|
||||||
|
|
||||||
|
window.set_target_fps(60);
|
||||||
|
|
||||||
|
// while window.is_open() {
|
||||||
|
// window
|
||||||
|
// .update_with_buffer(&buffer, WIDTH, HEIGHT)
|
||||||
|
// .unwrap();
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in a new issue