ableos/shadeable/src/lib.rs

27 lines
649 B
Rust
Raw Normal View History

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