#opengl #gl #graphics #gamedev

no-std gl46

Bindings to OpenGL 4.6 (plus some extensions)

12 releases

0.2.1 Mar 8, 2021
0.2.0 Feb 21, 2021
0.1.3 Sep 17, 2020
0.1.2 Aug 9, 2020
0.0.2 Jul 19, 2020

#914 in Graphics APIs

Download history 16/week @ 2024-06-16 16/week @ 2024-06-23 12/week @ 2024-06-30 93/week @ 2024-07-07 13/week @ 2024-07-14 15/week @ 2024-07-21 19/week @ 2024-07-28 12/week @ 2024-08-04 13/week @ 2024-08-11 9/week @ 2024-08-18 10/week @ 2024-08-25 10/week @ 2024-09-01 12/week @ 2024-09-08 5/week @ 2024-09-15 17/week @ 2024-09-22 66/week @ 2024-09-29

102 downloads per month

Zlib OR Apache-2.0 OR MIT

615KB
6.5K SLoC

License:Zlib min-rust-1.34 crates.io docs.rs

This Is A Generated Crate

This crate is hand-tuned output from running one of the scripts in the phosphorus repo.

Because of this, PRs to this crate about anything other than the top level crate doucmentation cannot generally be accepted. Instead you should make changes to how phosphorus does its thing.

gl46

Bindings to OpenGL 4.6 (plus some extensions)

See the crate documentation for an explanation of the crate's operation.


lib.rs:

Makes the OpenGL 4.6 Core API (plus some extensions) available for use.

The crate's interface is provided as a "struct" style loader. Construct a GlFns using an appropriate "gl_get_proc_address" function and then call its methods.

Extensions

Cargo Features

  • track_caller: Enables the track_caller attribute on any function that can panic. Specifically, the extension functions of the struct loader might not be loaded, and if you call them when they're not loaded you'll get a panic.

gl_get_proc_address

GL must generally be dynamically loaded at runtime. This is done via a function which we'll call "gl_get_proc_address". The expected operation of this function is very simple: The caller passes in the pointer to a null-terminated string with the name of a GL function, and gl_get_proc_address returns the pointer to that function.

The way that you get an appropriate gl_get_proc_address function is platform dependent.

The function to create a GLFns takes a &dyn Fn(*const u8) -> *const c_void. Note the &dyn part on the front. In addition to passing a closure to the constructor (|x| { ... }), you generally need to prefix your closure with a & to make it be a &dyn value. Like this:

use gl46::*;
let gl = unsafe { GlFns::load_from(&|u8_ptr| SDL_GL_GetProcAddress(u8_ptr.cast())).unwrap() };

It might seem a little silly, but it genuinely helps keep re-compile times down, and it's just one extra & to write.

Inlining

This crate does not use the #[inline] attribute. If you want full inlining just turn on Link-Time Optimization in your cargo profile:

[profile.release]
lto = "thin"

Dependencies