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
pub use offhand::*;

pub mod event;
pub mod window;

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

mod offhand;

use crate::lib::*;