From 5f74e093a4679cdc0fe9fa42822a14fecc7b1cbb Mon Sep 17 00:00:00 2001 From: natrixaeria Date: Sun, 26 May 2019 20:59:02 +0200 Subject: Compile webgl shader program --- WebInterface/wasm/asm-paint/src/canvas.rs | 6 ++++++ WebInterface/wasm/asm-paint/src/shader.rs | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'WebInterface/wasm/asm-paint/src') diff --git a/WebInterface/wasm/asm-paint/src/canvas.rs b/WebInterface/wasm/asm-paint/src/canvas.rs index ddf6d51..54691e8 100644 --- a/WebInterface/wasm/asm-paint/src/canvas.rs +++ b/WebInterface/wasm/asm-paint/src/canvas.rs @@ -39,3 +39,9 @@ impl Canvas { .map_err(|e| error!("webgl2 shader: {}", e)) } } + +impl Drop for Canvas { + fn drop(&mut self) { + self.shaders.remove(&self.ctx); + } +} diff --git a/WebInterface/wasm/asm-paint/src/shader.rs b/WebInterface/wasm/asm-paint/src/shader.rs index ac7c767..3311b6a 100644 --- a/WebInterface/wasm/asm-paint/src/shader.rs +++ b/WebInterface/wasm/asm-paint/src/shader.rs @@ -57,6 +57,17 @@ impl Shaders { } pub fn compile(&mut self, ctx: &WebGl2RenderingContext) -> Result<(), String> { - Ok(()) + let program = self.program.as_ref().ok_or("could not find created program")?; + ctx.link_program(program); + let status = ctx.get_program_parameter(program, WebGl2RenderingContext::LINK_STATUS); + if status == wasm_bindgen::JsValue::TRUE { + Ok(()) + } else { + Err(format!("\n{}", ctx.get_program_info_log(program).unwrap_or_default())) + } + } + + pub fn remove(&mut self, ctx: &WebGl2RenderingContext) { + ctx.delete_program(self.program.as_ref()) } } -- cgit v1.3.1