gl46/lib.rs
1#![no_std]
2#![allow(bad_style)]
3
4//! Makes the OpenGL 4.6 Core API (plus some extensions) available for use.
5//!
6//! The crate's interface is provided as a "struct" style loader. Construct a
7//! [`GlFns`] using an appropriate "gl_get_proc_address" function and then call
8//! its methods.
9//!
10//! ## Extensions
11//!
12//! * [GL_ARB_texture_filter_anisotropic](https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_texture_filter_anisotropic.txt)
13//! * [GL_ARB_bindless_texture](https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_bindless_texture.txt)
14//! * [GL_ARB_sparse_texture](https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_sparse_texture.txt)
15//! * [GL_ARB_pipeline_statistics_query](https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_pipeline_statistics_query.txt)
16//!
17//! ## Cargo Features
18//!
19//! * `track_caller`: Enables the [track_caller][track_caller_reference]
20//! attribute on any function that can panic. Specifically, the extension
21//! functions of the struct loader might not be loaded, and if you call them
22//! when they're not loaded you'll get a panic.
23//!
24//! [track_caller_reference]:
25//! https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute
26//!
27//! ## `gl_get_proc_address`
28//!
29//! GL must generally be dynamically loaded at runtime. This is done via a
30//! function which we'll call "gl_get_proc_address". The expected operation of
31//! this function is very simple: The caller passes in the pointer to a
32//! null-terminated string with the name of a GL function, and
33//! `gl_get_proc_address` returns the pointer to that function.
34//!
35//! The way that you get an appropriate `gl_get_proc_address` function is
36//! platform dependent.
37//! * With Win32 you'd use [wglGetProcAddress][wglGetProcAddress] for any
38//! function from *after* OpenGL 1.1, and [GetProcAddress][GetProcAddress] on
39//! an open `HMODULE` to "OpenGL.dll" for any OpenGL function from either 1.1
40//! or 1.0. That sounds silly, but it's true.
41//! * With SDL2 you'd call [SDL_GL_GetProcAddress][SDL_GL_GetProcAddress], or
42//! the equivalent function within your SDL2 bindings.
43//! * With [glutin][glutin] you'd call [Context::get_proc_address][glutin-gpa]
44//!
45//! The function to create a `GLFns` takes a `&dyn Fn(*const u8) -> *const
46//! c_void`. Note the `&dyn` part on the front. In addition to passing a closure
47//! to the constructor (`|x| { ... }`), you generally need to prefix your
48//! closure with a `&` to make it be a `&dyn` value. Like this:
49//! ```no_run
50//! use gl46::*;
51//! # let SDL_GL_GetProcAddress: fn(*const u8) -> *mut core::ffi::c_void = unimplemented!();
52//! let gl = unsafe { GlFns::load_from(&|u8_ptr| SDL_GL_GetProcAddress(u8_ptr.cast())).unwrap() };
53//! ```
54//! It might seem a little silly, but it genuinely helps keep re-compile times
55//! down, and it's just one extra `&` to write.
56//!
57//! [wglGetProcAddress]:
58//! https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-wglgetprocaddress
59//!
60//! [GetProcAddress]:
61//! https://docs.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-getprocaddress
62//!
63//! [SDL_GL_GetProcAddress]: https://wiki.libsdl.org/SDL_GL_GetProcAddress
64//!
65//! [glutin]: https://docs.rs/glutin/0.26.0/glutin
66//!
67//! [glutin-gpa]:
68//! https://docs.rs/glutin/0.26.0/glutin/struct.Context.html#method.get_proc_address
69//!
70//! ## Inlining
71//!
72//! This crate does **not** use the `#[inline]` attribute. If you want full
73//! inlining just turn on Link-Time Optimization in your cargo profile:
74//!
75//! ```toml
76//! [profile.release]
77//! lto = "thin"
78//! ```
79
80use chlorine::*;
81
82// TODO: make the gl_command_types module pub(crate), but it's a breaking
83// change.
84pub mod gl_command_types;
85pub(crate) use gl_command_types::*;
86
87pub mod gl_core_types;
88pub use gl_core_types::*;
89
90pub mod gl_enumerations;
91pub use gl_enumerations::*;
92
93pub mod gl_groups;
94pub use gl_groups::*;
95
96pub(crate) mod struct_loader;
97pub use struct_loader::*;