GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git
examples/probe3d_web.rs (1.5K)
1 //! The 3D probe (`probe3d/scene.rs`) on the WebGPU renderer, in a browser:
2 //! the browser shell runs it (`web::run`), and `capture()` reads a frame
3 //! back. A cdylib for wasm-bindgen, served by `scripts/web-probe/probe3d`;
4 //! natively it is empty.
5
6 #[cfg(target_arch = "wasm32")]
7 #[path = "probe3d/scene.rs"]
8 mod scene;
9
10 #[cfg(target_arch = "wasm32")]
11 mod web {
12 use cce_ui::web::{Fonts, Sizing};
13 use wasm_bindgen::prelude::*;
14
15 fn fonts(fonts: js_sys::Array) -> Fonts {
16 std::panic::set_hook(Box::new(|info| web_sys::console::error_1(&info.to_string().into())));
17 Fonts::new(fonts.iter().map(|f| js_sys::Uint8Array::new(&f).to_vec()).collect())
18 }
19
20 /// The raster probe.
21 #[wasm_bindgen]
22 pub async fn start(canvas: web_sys::HtmlCanvasElement, fonts: js_sys::Array, _families: String, _fill: bool) -> Result<(), JsValue> {
23 cce_ui::web::run::<super::scene::Raster>(canvas, self::fonts(fonts), Sizing::Page).await
24 }
25
26 /// The traced probe (`demo.html?app=probe3d_web&entry=start_traced`).
27 #[wasm_bindgen]
28 pub async fn start_traced(canvas: web_sys::HtmlCanvasElement, fonts: js_sys::Array, _families: String, _fill: bool) -> Result<(), JsValue> {
29 cce_ui::web::run::<super::scene::Traced>(canvas, self::fonts(fonts), Sizing::Page).await
30 }
31
32 #[wasm_bindgen]
33 pub async fn capture() -> Result<js_sys::Uint8Array, JsValue> {
34 let frame = cce_ui::web::capture().await?;
35 Ok(js_sys::Uint8Array::from(&frame.rgba[..]))
36 }
37 }