diff options
author | Dennis Kobert <d-kobert@web.de> | 2019-06-02 16:10:54 +0200 |
---|---|---|
committer | Dennis Kobert <d-kobert@web.de> | 2019-06-02 16:10:54 +0200 |
commit | 91d732d490fb59979f0c940bdb1e6e295b0b1c52 (patch) | |
tree | c27b970b7eb9d925b3c1cc7ac5acfc14e48cf55f /WebInterface/wasm/webhogg/src/canvas.rs | |
parent | 483418d90d2167c1908315b603f2de676ec0f0aa (diff) | |
parent | 0835c281ed1c6bdccca2412b71a8bdec4d03a620 (diff) |
Merge branch 'webhogg' of github.com:TrueDoctor/DiscoBot into webhogg
Diffstat (limited to 'WebInterface/wasm/webhogg/src/canvas.rs')
-rw-r--r-- | WebInterface/wasm/webhogg/src/canvas.rs | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/WebInterface/wasm/webhogg/src/canvas.rs b/WebInterface/wasm/webhogg/src/canvas.rs index a0ef7d1..5f819e9 100644 --- a/WebInterface/wasm/webhogg/src/canvas.rs +++ b/WebInterface/wasm/webhogg/src/canvas.rs @@ -1,32 +1,26 @@ use web_sys::WebGl2RenderingContext as WebGl2; use wasm_bindgen::JsCast; use crate::webhogg_exception::WebhoggException; -use crate::page::Page; +use web_sys::OffscreenCanvas as ECanvas; pub struct Canvas { ctx: WebGl2, } impl Canvas { - pub fn from_existing(id: &str, page: &Page) -> Result<Self, WebhoggException> { - let canvas_element = page.get_element(id) - .ok_or(WebhoggException::DomError( - "could not obtain canvas element (id=canvas)" - .to_string()))?; - let canvas_element = canvas_element - .dyn_into::<web_sys::HtmlCanvasElement>() - .map_err(|_| WebhoggException::DomError( - "id=canvas is not a canvas element".to_string()))?; - debug!("successfully obtained canvas element"); - let ctx = canvas_element.get_context("webgl2") - .map_err(|_| WebhoggException::WebGlContextError( - "obtained invalid webgl2 context js value".to_string()))? + pub fn from_existing(canvas: &ECanvas) -> Result<Self, WebhoggException> { + info!("messages lol"); + let ctx = canvas.get_context("webgl2") + .map_err(|x| WebhoggException::WebGlContextError( + format!("obtained invalid webgl2 context js value: {:?}", x)))? .ok_or(WebhoggException::WebGlContextError( "could not obtaine webgl2 context".to_string()))? .dyn_into::<WebGl2>() .map_err(|_| WebhoggException::WebGlContextError( "obtained invalid webgl2 context js object".to_string()))?; - debug!("successfully obtained webgl2 context"); + info!("successfully obtained webgl2 context"); + ctx.clear_color(1.0, 0.0, 0.0, 1.0); + ctx.clear(WebGl2::COLOR_BUFFER_BIT); Ok(Self { ctx, }) |