- Notifications
You must be signed in to change notification settings - Fork118
gl
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
parent directory.. | ||||
An OpenGL function pointer loader for the Rust Programming Language.
[dependencies]gl ="0.14.0"
You can import the pointer style loader and type aliases like so:
externcrate gl;// include the OpenGL type aliasesuse gl::types::*;
You must load the function pointers into their respective function pointersusing theload_with
function. You must supply a loader function from yourcontext library. This is how it would look usingglfw-rs:
// the supplied function must be of the type:// `&fn(symbol: &'static str) -> *const std::os::raw::c_void`// `window` is a glfw::Windowgl::load_with(|s| window.get_proc_address(s)as*const_);// loading a specific function pointergl::Viewport::load_with(|s| window.get_proc_address(s)as*const_);
Calling a function that has not been loaded will result in a failure like:panic!("gl::Viewport was not loaded")
, which avoids a segfault. This featuredoes not cause any run time overhead because the failing functions areassigned only whenload_with
is called.
All OpenGL function calls areunsafe
.
// accessing an enumgl::TEXTURE_2D;// calling a functionunsafe{ gl::DrawArrays(gl::TRIANGLES,0,3)};
Each function pointer has an associated boolean value allowing you tocheck if a function has been loaded at run time. The function accesses acorresponding global boolean that is set whenload_with
is called, so thereshouldn't be much overhead.
if gl::Viewport::is_loaded(){// do something...}