1
0
Fork 0
forked from AbleOS/ableos
ableos/shadeable/src/lib.rs

69 lines
1.4 KiB
Rust
Raw Normal View History

2022-01-16 19:42:11 -06:00
#![no_std]
extern crate alloc;
use alloc::{boxed::Box, vec, vec::Vec};
use engine_internals::engine_startup;
use pixel_format::RGBA;
// use core::fmt::Result;
use core::result::Result;
use rhai::{EvalAltResult, Scope};
mod engine_internals;
mod pixel_format;
pub const SHADER: &str = include_str!("../shaders/simple.shade");
pub fn rhai_test() -> Result<Vec<RGBA>, Box<EvalAltResult>>
// ^^^^^^^^^^^^^^^^^^
// Rhai API error type
{
// Create an 'Engine'
let engine = engine_startup();
let ast = engine.compile(SHADER)?;
let mut scope = Scope::new();
let a = vec![
RGBA {
r: 255,
g: 0,
b: 0,
a: 0,
},
RGBA {
r: 0,
g: 255,
b: 0,
a: 0,
},
RGBA {
r: 0,
g: 0,
b: 255,
a: 0,
},
RGBA {
r: 0,
g: 0,
b: 0,
a: 255,
},
];
let mut result_rgba = vec![];
for pixel in a {
/*
scope.push("PIXEL_X", 0);
scope.push("PIXEL_Y", index);
*/
scope.push("PIXEL_RGBA", pixel);
let result: RGBA = engine.call_fn(&mut scope, &ast, "main", ())?;
result_rgba.push(result);
}
// Done!
Ok(result_rgba)
}