From 95ef9331e5dac2cd1d8dc2087c4535a87addb216 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 Feb 2023 22:15:04 +0100 Subject: feat: add project & bindings --- src/lib.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/lib.rs (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..9568b6c --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,61 @@ +//! OpenGL bindings. +#![deny(clippy::all, clippy::pedantic, missing_docs)] + +use opengl_registry_macros::for_each_opengl_command; + +for_each_opengl_command! { + #[doc = stringify!(_gl_command_)] + #[allow(non_snake_case, clippy::too_many_arguments)] + pub unsafe fn _gl_command_(_gl_command_args_) -> _gl_command_ret_type_ { + type GLFunc = + unsafe extern "C" fn(_gl_command_arg_types_) -> _gl_command_ret_type_; + + let gl_func = std::mem::transmute::<_, GLFunc>(functions::_gl_command_); + + gl_func(_gl_command_arg_names_) + } +} + +mod ffi +{ + #![allow( + non_upper_case_globals, + non_camel_case_types, + non_snake_case, + unused, + missing_docs, + clippy::unreadable_literal + )] + + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} + +pub use ffi::*; + +/// Loads OpenGL function pointers using the given function address retriever function. +pub fn load_with(get_proc_addr: GetProcAddrFn) +where + GetProcAddrFn: Fn(&str) -> unsafe extern "C" fn(), +{ + for_each_opengl_command! { + unsafe { + functions::_gl_command_ = get_proc_addr(stringify!(_gl_command_)); + } + }; +} + +mod functions +{ + use opengl_registry_macros::for_each_opengl_command; + + for_each_opengl_command!( + #[doc = stringify!(_gl_command_)] + #[allow(non_upper_case_globals)] + pub static mut _gl_command_: unsafe extern "C" fn() = function_not_loaded; + ); + + extern "C" fn function_not_loaded() + { + panic!("OpenGL function not loaded"); + } +} -- cgit v1.2.3-18-g5258