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
#[allow(unused_imports)]
use crate::uses::*;
#[derive(Debug)]
pub struct Fence {
obj: gl::types::GLsync,
}
impl Fence {
pub fn new() -> Self {
let obj = GLCheck!(gl::FenceSync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0));
DEBUG!("Created GL Fence {obj:?}");
GLCheck!(gl::Flush());
Self { obj }
}
pub fn Block(&self) {
loop {
let state = GLCheck!(gl::ClientWaitSync(self.obj, 0, 16000000));
if state != gl::TIMEOUT_EXPIRED {
return;
}
}
}
pub fn BlockFor(&self, nanoseconds: u64) {
GLCheck!(gl::ClientWaitSync(self.obj, 0, nanoseconds));
DEBUG!("Synced GL Fence {:?}", self.obj);
}
}
impl Default for Fence {
fn default() -> Self {
Self::new()
}
}
impl Drop for Fence {
fn drop(&mut self) {
DEBUG!("Deleting GL Fence {:?}", self.obj);
GLCheck!(gl::DeleteSync(self.obj));
}
}
unsafe impl Send for Fence {}