wrend/uniforms/
uniform_context_js.rs

1use crate::{IntoJsWrapper, UniformContext};
2use std::ops::{Deref, DerefMut};
3use wasm_bindgen::prelude::wasm_bindgen;
4use web_sys::{WebGl2RenderingContext, WebGlUniformLocation};
5
6pub type UniformContextJsInner = UniformContext;
7
8#[wasm_bindgen(inspectable, js_name = UniformContext)]
9pub struct UniformContextJs(UniformContextJsInner);
10
11#[wasm_bindgen(js_class = UniformContext)]
12impl UniformContextJs {
13    pub fn gl(&self) -> WebGl2RenderingContext {
14        self.deref().gl().to_owned()
15    }
16
17    pub fn now(&self) -> f64 {
18        self.deref().now()
19    }
20
21    #[wasm_bindgen(js_name = uniformLocation)]
22    pub fn uniform_location(&self) -> WebGlUniformLocation {
23        self.deref().uniform_location().to_owned()
24    }
25}
26
27impl UniformContextJs {
28    pub fn into_inner(self) -> UniformContextJsInner {
29        self.0
30    }
31}
32
33impl Deref for UniformContextJs {
34    type Target = UniformContextJsInner;
35
36    fn deref(&self) -> &Self::Target {
37        &self.0
38    }
39}
40
41impl DerefMut for UniformContextJs {
42    fn deref_mut(&mut self) -> &mut UniformContextJsInner {
43        &mut self.0
44    }
45}
46
47impl From<UniformContext> for UniformContextJs {
48    fn from(attribute_create_context: UniformContext) -> Self {
49        UniformContextJs(attribute_create_context)
50    }
51}
52
53impl IntoJsWrapper for UniformContext {
54    type Result = UniformContextJs;
55
56    fn into_js_wrapper(self) -> Self::Result {
57        self.into()
58    }
59}
60
61impl From<&UniformContext> for UniformContextJs {
62    fn from(attribute_create_context: &UniformContext) -> Self {
63        UniformContextJs(attribute_create_context.to_owned())
64    }
65}
66
67impl IntoJsWrapper for &UniformContext {
68    type Result = UniformContextJs;
69
70    fn into_js_wrapper(self) -> Self::Result {
71        self.into()
72    }
73}