1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! WebGLBuffer and methods
use glenum::{BufferBase, BufferKind};
use rendering_context::WebGL2RenderingContext;
use wasm_bindgen::prelude::*;
impl WebGL2RenderingContext {
/// Creates a new `WebGLRSBuffer` object which is used for storing data such as vertices or colors.
pub fn create_buffer(&self) -> WebGLRSBuffer {
WebGLRSBuffer {
context: self,
inner: self._create_buffer(),
}
}
}
/// Buffer which is used for storing data
///
/// The `WebGLBuffer` interface is part of the WebGL API and represents an opaque buffer object
/// storing data such as vertices or colors.
#[derive(Clone)]
pub struct WebGLRSBuffer<'ctx> {
context: &'ctx WebGL2RenderingContext,
inner: WebGLBuffer,
}
impl<'ctx> WebGLRSBuffer<'ctx> {
/// Deletes this `WebGLRSBuffer`
pub fn delete(self) {
self.context._delete_buffer(self.inner);
}
/// Returns true is the `WebGLRSBuffer` object is valid.
pub fn is_valid(&self) -> bool {
self.context._is_buffer(&self.inner)
}
/// Binds the buffer to a given target
///
/// # Arguments
/// * `target` - an enum specifying the binding point.
pub fn bind(&self, target: BufferKind) {
self.context._bind_buffer(target, &self.inner);
}
/// Binds the `WebGLRSBuffer` to a given binding point (target) at a given index.
///
/// # Arguments
/// * `target` - an enum specifying the target for the bind operation.
/// * `index` - the index of the target.
pub fn bind_base(&self, target: BufferBase, index: u32) {
self.context._bind_buffer_base(target, index, &self.inner);
}
/// Binds a range of the `WebGLRSBuffer` to a given binding point (target) at a given index.
///
/// # Arguments
/// * `target` - an enum specifying the target for the bind operation.
/// * `index` - the index of the target.
/// * `offset` - the starting offset.
/// * `size` - the amount of data that can be read from the buffer.
pub fn bind_range(&self, target: BufferBase, index: u32, offset: u32, size: u32) {
self.context
._bind_buffer_range(target, index, &self.inner, offset, size);
}
}
/// WebGLBuffer bindings
#[wasm_bindgen]
#[derive(Clone, Copy)]
extern "C" {
#[derive(Clone)]
type WebGLBuffer;
/// Binding for `WebGLRenderingContext.createBuffer()`
#[wasm_bindgen(method, js_name = createBuffer)]
fn _create_buffer(this: &WebGL2RenderingContext) -> WebGLBuffer;
/// Binding for `WebGLRenderingContext.deleteBuffer()`
#[wasm_bindgen(method, js_name = deleteBuffer)]
fn _delete_buffer(this: &WebGL2RenderingContext, buffer: WebGLBuffer);
/// Binding for `WebGLRenderingContext.isBuffer()`
#[wasm_bindgen(method, js_name = isBuffer)]
fn _is_buffer(this: &WebGL2RenderingContext, buffer: &WebGLBuffer) -> bool;
/// Binding for `WebGLRenderingContext.bindBuffer()`
#[wasm_bindgen(method, js_name = bindBuffer)]
fn _bind_buffer(this: &WebGL2RenderingContext, target: BufferKind, buffer: &WebGLBuffer);
/// Binding for `WebGL2RenderingContext.bindBufferBase()`
#[wasm_bindgen(method, js_name = bindBufferBase)]
fn _bind_buffer_base(
this: &WebGL2RenderingContext,
target: BufferBase,
index: u32,
buffer: &WebGLBuffer,
);
/// Binding `WebGL2RenderingContext.bindBufferRange()`
#[wasm_bindgen(method, js_name = bindBufferRange)]
fn _bind_buffer_range(
this: &WebGL2RenderingContext,
target: BufferBase,
index: u32,
buffer: &WebGLBuffer,
offset: u32,
size: u32,
);
}