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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//! WebGLTexture and methods
use glenum::{Attachment, FramebufferKind, TextureBindPoint, TextureKind};
use rendering_context::WebGL2RenderingContext;
use wasm_bindgen::prelude::*;
impl WebGL2RenderingContext {
/// Creates and initializes a WebGLRSTexture
pub fn create_texture(&self) -> WebGLRSTexture {
WebGLRSTexture {
context: self,
inner: self._create_texture(),
}
}
}
/// The WebGLTexture interface is part of the WebGL API and represents an opaque texture object providing
/// storage and state for texturing operations.
#[derive(Clone)]
pub struct WebGLRSTexture<'ctx> {
context: &'ctx WebGL2RenderingContext,
inner: WebGLTexture,
}
impl<'ctx> WebGLRSTexture<'ctx> {
/// Deletes the `WebGLRSTexture` object.
pub fn delete(self) {
self.context._delete_texture(self.inner);
}
/// Binds the `WebGLRSTexture` to a target
///
/// # Arguments
/// * `target` - specifying the binding point.
pub fn bind(&self, target: TextureKind) {
self.context._bind_texture(target, &self.inner);
}
/// Returns true if the `WebGLRSTexture` is valid and false otherwise.
pub fn is_valid(&self) -> bool {
self.context._is_texture(&self.inner)
}
/// Attaches this `WebGLRSTexture` object to a framebuffer.
///
/// # Arguments
/// * `target` - specifying the binding point.
/// * `attachment` - specifying the attachment point for the texture.
/// * `tex_target` - specifying the texture target.
/// * `level` - specifying the mipmap level of the texture image to attach.
pub fn attach_framebuffer(
&self,
target: FramebufferKind,
attachment: Attachment,
tex_target: TextureBindPoint,
level: i32,
) {
self.context
._framebuffer_texture_2d(target, attachment, tex_target, &self.inner, level);
}
/// Attaches a single layer of this `WebGLRSTexture` object to a framebuffer.TextureBindPoint
///
/// # Arguments
/// * `target` - specifying the binding point.
/// * `attachment` - specifying the attachment point for the texture.
/// * `level` - specifying the mipmap level of the texture image to attach.
/// * `layer` - specifying the layer of the texture image to attach.
pub fn attach_layer_framebuffer(
&self,
target: FramebufferKind,
attachment: Attachment,
level: i32,
layer: i32,
) {
self.context
._framebuffer_texture_layer(target, attachment, &self.inner, level, layer);
}
}
/// Bindings for WebGLTexture
#[wasm_bindgen]
#[derive(Clone, Copy)]
extern "C" {
#[derive(Clone)]
type WebGLTexture;
/// Binding for `WebGLRenderingContext.createTexture()`.
#[wasm_bindgen(method, js_name = createTexture)]
fn _create_texture(this: &WebGL2RenderingContext) -> WebGLTexture;
/// Binding for `WebGLRenderingContext.bindTexture()`
#[wasm_bindgen(method, js_name = bindTexture)]
fn _bind_texture(this: &WebGL2RenderingContext, target: TextureKind, texture: &WebGLTexture);
/// Binding for `WebGLRenderingContext.deleteTexture()`
#[wasm_bindgen(method, js_name = deleteTexture)]
fn _delete_texture(this: &WebGL2RenderingContext, texture: WebGLTexture);
/// Binding for `WebGLRenderingContext.isTexture()`
#[wasm_bindgen(method, js_name = isTexture)]
fn _is_texture(this: &WebGL2RenderingContext, texture: &WebGLTexture) -> bool;
/// Binding for `WebGLRenderingContext.framebufferTexture2D()`
#[wasm_bindgen(method, js_name = framebufferTexture2D)]
fn _framebuffer_texture_2d(
this: &WebGL2RenderingContext,
target: FramebufferKind,
attachment: Attachment,
textarget: TextureBindPoint,
texture: &WebGLTexture,
level: i32,
);
/// Binding for `WebGL2RenderingContext.framebufferTextureLayer()`
#[wasm_bindgen(method, js_name = framebufferTextureLayer)]
fn _framebuffer_texture_layer(
this: &WebGL2RenderingContext,
target: FramebufferKind,
attachment: Attachment,
texture: &WebGLTexture,
level: i32,
layer: i32,
);
}