Skip to main content

grafix_toolbox/kit/opengl/
context.rs

1pub use offhand::*;
2
3pub mod event;
4pub mod window;
5
6fn load_gl(loader: impl FnMut(STR) -> *const std::ffi::c_void) {
7	gl::load_with(loader);
8
9	let version = unsafe { std::ffi::CStr::from_ptr(gl::GetString(gl::VERSION) as *const i8) }.to_str().fail();
10	PRINT!("Initialized OpenGL, {version}");
11	*GL::macro_uses::gl_was_initialized() = true;
12	if GL::unigl::IS_DEBUG {
13		GL::EnableDebugContext(GL::DebugLevel::All);
14	}
15	crate::GL!(gl::Disable(gl::DITHER));
16}
17
18#[derive(Debug)]
19pub struct Fence {
20	obj: gl::types::GLsync,
21}
22impl Fence {
23	pub fn new() -> Self {
24		let obj = GL!(gl::FenceSync(gl::SYNC_GPU_COMMANDS_COMPLETE, 0));
25		DEBUG!("Created GL Fence {obj:?}");
26		GL!(gl::Flush());
27		Self { obj }
28	}
29	pub fn Block(&self) {
30		while !self.BlockFor(16000000) {}
31	}
32	pub fn BlockFor(&self, nanoseconds: u64) -> bool {
33		(gl::TIMEOUT_EXPIRED != GL!(gl::ClientWaitSync(self.obj, 0, nanoseconds))).tap(|_| DEBUG!("Synced GL Fence {:?}", self.obj))
34	}
35}
36impl Default for Fence {
37	fn default() -> Self {
38		Self::new()
39	}
40}
41impl Drop for Fence {
42	fn drop(&mut self) {
43		DEBUG!("Deleting GL Fence {:?}", self.obj);
44		GL!(gl::DeleteSync(self.obj));
45	}
46}
47unsafe impl Send for Fence {}
48
49mod offhand;
50
51//mod glfw_impl;
52mod sdl2_impl;
53use sdl2_impl as win_impl;
54
55use crate::{GL::FrameInfo, lib::*, math::*};