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
//! WebGLSync and methods
use glenum::{GPUState, SyncParameter, SyncStatus, WaitStatus};
use rendering_context::WebGL2RenderingContext;
use wasm_bindgen::prelude::*;
impl WebGL2RenderingContext {
/// Creates a new `WebGLRSSync` object and inserts it into the GL command stream.
///
/// # Arguments
/// * `conditions` - specifying the condition that must be met to set the sync object's state to.
/// * `flags` - specifying a bitwise combination of flags controlling the behavior of the sync object.
/// Must be 0 (exists for extensions only).
pub fn fence_sync(&self, conditions: GPUState, flags: u32) -> WebGLRSSync {
WebGLRSSync {
context: self,
inner: self._fence_sync(conditions, flags),
}
}
}
#[derive(Clone)]
pub struct WebGLRSSync<'ctx> {
context: &'ctx WebGL2RenderingContext,
inner: WebGLSync,
}
impl<'ctx> WebGLRSSync<'ctx> {
/// Deletes this `WebGLRSSync` object
pub fn delete(self) {
self.context._delete_sync(self.inner);
}
/// Returns true if this is a valid `WebGLRSSync` object.
pub fn is_valid(&self) -> bool {
self.context._is_sync(&self.inner)
}
/// Blocks and waits for this `WebGLRSSync` object to become signaled or a given timeout to be passed.
///
/// # Arguments
/// * `flags` - specifying a bitwise combination of flags controlling the flushing behavior. May be gl.SYNC_FLUSH_COMMANDS_BIT.
/// * `timeout` - specifying a timeout (in nanoseconds) for which to wait for the sync object to become signaled. Must not be larger than gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL.
pub fn client_wait(&self, flags: u32, timeout: i64) -> WaitStatus {
self.context._client_wait_sync(&self.inner, flags, timeout)
}
/// Returns immediately, but waits on the GL server until the `WebGLRSSync` object is signaled.
///
/// The method is a no-op in the absence of the possibility of synchronizing between multiple GL contexts.
/// # Arguments
/// * `flags` - specifying a bitwise combination of flags controlling the flushing behavior. May be gl.SYNC_FLUSH_COMMANDS_BIT.
/// * `timeout` - specifying a timeout (in nanoseconds) for which to wait for the sync object to become signaled. Must not be larger than gl.MAX_CLIENT_WAIT_TIMEOUT_WEBGL.
// FIXME: timeout must be gl.TIMEOUT_IGNORED.
pub fn wait(&self, flags: u32, timeout: i64) {
self.context._wait_sync(&self.inner, flags, timeout);
}
/// Returns the status of this `WebGLRSSync` object.
pub fn status(&self) -> SyncStatus {
self.context
._get_sync_parameter_status(&self.inner, SyncParameter::Status)
}
}
/// Bindings for WebGLSync
#[wasm_bindgen]
#[derive(Clone, Copy)]
extern "C" {
#[derive(Clone)]
pub type WebGLSync;
/// Binding for `WebGL2RenderingContext.fenceSync()`
#[wasm_bindgen(method, js_name = fenceSync)]
fn _fence_sync(this: &WebGL2RenderingContext, conditions: GPUState, flags: u32) -> WebGLSync;
/// Binding for `WebGL2RenderingContext.isSync()` method of the WebGL 2 API
#[wasm_bindgen(method, js_name = isSync)]
fn _is_sync(this: &WebGL2RenderingContext, sync: &WebGLSync) -> bool;
/// Binding for `WebGL2RenderingContext.deleteSync()`
#[wasm_bindgen(method, js_name = deleteSync)]
fn _delete_sync(this: &WebGL2RenderingContext, sync: WebGLSync);
/// Binding for `WebGL2RenderingContext.clientWaitSync()`
#[wasm_bindgen(method, js_name = clientWaitSync)]
fn _client_wait_sync(
this: &WebGL2RenderingContext,
sync: &WebGLSync,
flags: u32,
timeout: i64,
) -> WaitStatus;
/// Binding for `WebGL2RenderingContext.waitSync()`
#[wasm_bindgen(method, js_name = waitSync)]
fn _wait_sync(this: &WebGL2RenderingContext, sync: &WebGLSync, flags: u32, timeout: i64);
/// Binding for `WebGL2RenderingContext.getSyncParameter()` when asking for status
#[wasm_bindgen(method, js_name = getSyncParameter)]
fn _get_sync_parameter_status(
this: &WebGL2RenderingContext,
sync: &WebGLSync,
pname: SyncParameter,
) -> SyncStatus;
}