diff options
author | natrixaeria <janng@gmx.de> | 2019-05-26 20:59:02 +0200 |
---|---|---|
committer | natrixaeria <janng@gmx.de> | 2019-05-26 20:59:02 +0200 |
commit | 5f74e093a4679cdc0fe9fa42822a14fecc7b1cbb (patch) | |
tree | 4137b6523f97e3b8e4ac3ecef3cdc07ae3f16bb9 /WebInterface/wasm/asm-paint/src | |
parent | 9f0f87a772743ce67e37700516cae0ead17cced9 (diff) |
Compile webgl shader program
Diffstat (limited to 'WebInterface/wasm/asm-paint/src')
-rw-r--r-- | WebInterface/wasm/asm-paint/src/canvas.rs | 6 | ||||
-rw-r--r-- | WebInterface/wasm/asm-paint/src/shader.rs | 13 |
2 files changed, 18 insertions, 1 deletions
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()) } } |