webgl_rs/
vertex_array_object.rs

1//! VertextArrayObject and methods
2use rendering_context::WebGL2RenderingContext;
3use wasm_bindgen::prelude::*;
4
5impl WebGL2RenderingContext {
6    /// Creates and initializes a WebGLRSVertexArrayObject object that represents a vertex array object
7    /// (VAO) pointing to vertex array data and which provides names for different sets of vertex data.
8    pub fn create_vertex_array(&self) -> WebGLRSVertexArrayObject {
9        WebGLRSVertexArrayObject {
10            context: self,
11            inner: self._create_vertex_array(),
12        }
13    }
14}
15
16/// VertexArrayObject
17///
18/// The WebGLVertexArrayObject interface is part of the WebGL 2 API, represents vertex array objects (VAOs)
19/// pointing to vertex array data, and provides names for different sets of vertex data.
20#[derive(Clone)]
21pub struct WebGLRSVertexArrayObject<'ctx> {
22    context: &'ctx WebGL2RenderingContext,
23    inner: WebGLVertexArrayObject,
24}
25
26impl<'ctx> WebGLRSVertexArrayObject<'ctx> {
27    /// Deletes the `WebGLRSVertexArrayObject` on the gpu and consumes itself.
28    pub fn delete(self) {
29        self.context._delete_vertex_array(self.inner);
30    }
31
32    /// Return true if this is a valid `WebGLRSVertexArrayObject` object.
33    pub fn is_valid(&self) -> bool {
34        self.context._is_vertex_array(&self.inner)
35    }
36
37    /// Binds this `WebGLRSVertexArrayObject` to the buffer.
38    pub fn bind(&self) {
39        self.context._bind_vertex_array(&self.inner);
40    }
41}
42
43/// WebGLVerterArrayObject bindings
44#[wasm_bindgen]
45extern "C" {
46    #[derive(Clone)]
47    type WebGLVertexArrayObject;
48    /// Binding for `WebGL2RenderingContext.createVertexArray()`
49    #[wasm_bindgen(method, js_name = createVertexArray)]
50    fn _create_vertex_array(this: &WebGL2RenderingContext) -> WebGLVertexArrayObject;
51
52    /// Binding for `WebGL2RenderingContext.deleteVertexArray()`
53    #[wasm_bindgen(method, js_name = deleteVertexArray)]
54    fn _delete_vertex_array(this: &WebGL2RenderingContext, vertex_array: WebGLVertexArrayObject);
55
56    /// Binding for `WebGL2RenderingContext.isVertexArray()`
57    #[wasm_bindgen(method, js_name = isVertexArray)]
58    fn _is_vertex_array(
59        this: &WebGL2RenderingContext,
60        vertex_array: &WebGLVertexArrayObject,
61    ) -> bool;
62
63    /// Binding for `WebGL2RenderingContext.bindVertexArray()`
64    #[wasm_bindgen(method, js_name = bindVertexArray)]
65    fn _bind_vertex_array(this: &WebGL2RenderingContext, vertex_array: &WebGLVertexArrayObject);
66}