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

29 lines
713 B
Rust
Raw Normal View History

2022-01-16 19:42:11 -06:00
#![no_std]
extern crate alloc;
2022-01-22 00:01:16 -06:00
use alloc::boxed::Box;
2022-01-16 19:42:11 -06:00
use engine_internals::engine_startup;
2022-01-22 00:01:16 -06:00
use pixel_format::Rgba64;
2022-01-16 19:42:11 -06:00
// use core::fmt::Result;
use core::result::Result;
use rhai::{EvalAltResult, Scope};
mod engine_internals;
2022-01-18 06:15:51 -06:00
pub mod pixel_format;
2022-01-16 19:42:11 -06:00
pub const SHADER: &str = include_str!("../shaders/simple.shade");
2022-01-22 00:01:16 -06:00
pub fn evaluate_shader(x: usize, y: usize, pixel: Rgba64) -> Result<Rgba64, Box<EvalAltResult>> {
2022-01-18 06:15:51 -06:00
let engine = engine_startup();
let ast = engine.compile(SHADER)?;
let mut scope = Scope::new();
scope.push("PIXEL_RGBA", pixel);
2022-01-22 00:01:16 -06:00
scope.push("PIXEL_X", x);
scope.push("PIXEL_Y", y);
2022-01-18 06:15:51 -06:00
2022-01-22 00:01:16 -06:00
let result: Rgba64 = engine.call_fn(&mut scope, &ast, "main", ())?;
2022-01-18 06:15:51 -06:00
2022-01-22 00:01:16 -06:00
Ok(result)
2022-01-18 06:15:51 -06:00
}