webgl_rs/
vertex_array_object.rs1use rendering_context::WebGL2RenderingContext;
3use wasm_bindgen::prelude::*;
4
5impl WebGL2RenderingContext {
6 pub fn create_vertex_array(&self) -> WebGLRSVertexArrayObject {
9 WebGLRSVertexArrayObject {
10 context: self,
11 inner: self._create_vertex_array(),
12 }
13 }
14}
15
16#[derive(Clone)]
21pub struct WebGLRSVertexArrayObject<'ctx> {
22 context: &'ctx WebGL2RenderingContext,
23 inner: WebGLVertexArrayObject,
24}
25
26impl<'ctx> WebGLRSVertexArrayObject<'ctx> {
27 pub fn delete(self) {
29 self.context._delete_vertex_array(self.inner);
30 }
31
32 pub fn is_valid(&self) -> bool {
34 self.context._is_vertex_array(&self.inner)
35 }
36
37 pub fn bind(&self) {
39 self.context._bind_vertex_array(&self.inner);
40 }
41}
42
43#[wasm_bindgen]
45extern "C" {
46 #[derive(Clone)]
47 type WebGLVertexArrayObject;
48 #[wasm_bindgen(method, js_name = createVertexArray)]
50 fn _create_vertex_array(this: &WebGL2RenderingContext) -> WebGLVertexArrayObject;
51
52 #[wasm_bindgen(method, js_name = deleteVertexArray)]
54 fn _delete_vertex_array(this: &WebGL2RenderingContext, vertex_array: WebGLVertexArrayObject);
55
56 #[wasm_bindgen(method, js_name = isVertexArray)]
58 fn _is_vertex_array(
59 this: &WebGL2RenderingContext,
60 vertex_array: &WebGLVertexArrayObject,
61 ) -> bool;
62
63 #[wasm_bindgen(method, js_name = bindVertexArray)]
65 fn _bind_vertex_array(this: &WebGL2RenderingContext, vertex_array: &WebGLVertexArrayObject);
66}