diff --git a/rendering/src/raytracer/external.rs b/rendering/src/raytracer/external.rs index 26b57be..9c5470b 100644 --- a/rendering/src/raytracer/external.rs +++ b/rendering/src/raytracer/external.rs @@ -5,7 +5,7 @@ use crate::raytracer::Image; use ndarray::arr1; use std::time::Instant; -type Frame = Image; +pub type Frame = Image; #[no_mangle] pub extern "C" fn get_frame() -> Box { diff --git a/rendering_wasm/src/lib.rs b/rendering_wasm/src/lib.rs index 51efbb7..688b41c 100644 --- a/rendering_wasm/src/lib.rs +++ b/rendering_wasm/src/lib.rs @@ -1,6 +1,6 @@ extern crate rendering; -//use rendering::raytracer::external::{get_frame, Frame}; +use rendering::raytracer::external::get_frame; use wasm_bindgen::prelude::*; mod utils; @@ -21,7 +21,44 @@ pub fn greet() { alert("Hello, {{project-name}}!"); } -//#[wasm_bindgen] -//pub fn render() -> Box { -// get_frame() -//} +#[wasm_bindgen] +pub fn render() -> ByteStream { + let frame = get_frame(); + ByteStream::new(&frame.data, frame.width, frame.height) +} + +#[wasm_bindgen] +pub struct ByteStream { + data: *const u8, + width: u32, + height: u32, + size: usize, +} + +#[wasm_bindgen] +impl ByteStream { + pub fn new(bytes: &[u8], width: u32, height: u32) -> ByteStream { + ByteStream { + data: bytes.as_ptr(), + size: bytes.len(), + width, + height, + } + } + + pub fn data(&self) -> *const u8 { + self.data + } + + pub fn size(&self) -> usize { + self.size + } + + pub fn width(&self) -> u32 { + self.width + } + + pub fn height(&self) -> u32 { + self.height + } +}