From cbdfe82cda974fbdc8227c9f9cb193ad6b4d58c3 Mon Sep 17 00:00:00 2001 From: Gabriel Nigro Date: Tue, 4 Mar 2025 14:26:36 -0300 Subject: [PATCH 1/3] Add no-std support and CStr symbols feature --- gl/Cargo.toml | 4 + gl/src/lib.rs | 1 + gl_generator/Cargo.toml | 1 + gl_generator/generators/debug_struct_gen.rs | 30 ++--- gl_generator/generators/global_gen.rs | 40 +++--- gl_generator/generators/mod.rs | 16 +++ gl_generator/generators/static_gen.rs | 4 +- gl_generator/generators/static_struct_gen.rs | 7 +- gl_generator/generators/struct_gen.rs | 30 ++--- .../generators/templates/types/egl.rs | 44 +++---- gl_generator/generators/templates/types/gl.rs | 56 ++++----- .../generators/templates/types/glx.rs | 116 +++++++++--------- .../generators/templates/types/wgl.rs | 42 +++---- gl_generator/registry/parse.rs | 60 ++++----- 14 files changed, 240 insertions(+), 211 deletions(-) diff --git a/gl/Cargo.toml b/gl/Cargo.toml index 3d181d4d..bf0fb5a5 100644 --- a/gl/Cargo.toml +++ b/gl/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "gl" version = "0.14.0" +edition = "2021" # c-string literals require Rust 2021 or later authors = [ "Brendan Zabarauskas ", "Corey Richardson", @@ -19,5 +20,8 @@ keywords = ["gl", "egl", "opengl", "khronos"] [build-dependencies] gl_generator = { version = "0.14.0", path = "../gl_generator" } +[features] +cstr_symbols = ["gl_generator/cstr_symbols"] + [dev-dependencies] glutin = "0.24" diff --git a/gl/src/lib.rs b/gl/src/lib.rs index 4e2c8bd6..2f797885 100644 --- a/gl/src/lib.rs +++ b/gl/src/lib.rs @@ -70,6 +70,7 @@ //! ~~~ //! +#![no_std] #![crate_name = "gl"] #![crate_type = "lib"] diff --git a/gl_generator/Cargo.toml b/gl_generator/Cargo.toml index 98f545d3..abc1ab57 100644 --- a/gl_generator/Cargo.toml +++ b/gl_generator/Cargo.toml @@ -21,6 +21,7 @@ path = "lib.rs" [features] unstable_generator_utils = [] +cstr_symbols = [] [dependencies] khronos_api = { version = "3.2.0", path = "../khronos_api" } diff --git a/gl_generator/generators/debug_struct_gen.rs b/gl_generator/generators/debug_struct_gen.rs index 87e57065..4ff181bd 100644 --- a/gl_generator/generators/debug_struct_gen.rs +++ b/gl_generator/generators/debug_struct_gen.rs @@ -44,9 +44,9 @@ where dest, r#" mod __gl_imports {{ - pub use std::mem; - pub use std::marker::Send; - pub use std::os::raw; + pub use core::mem; + pub use core::marker::Send; + pub use core::ffi; }} "# ) @@ -96,17 +96,17 @@ where #[derive(Clone)] pub struct FnPtr {{ /// The function pointer that will be used when calling the function. - f: *const __gl_imports::raw::c_void, + f: *const __gl_imports::ffi::c_void, /// True if the pointer points to a real function, false if points to a `panic!` fn. is_loaded: bool, }} impl FnPtr {{ /// Creates a `FnPtr` from a load attempt. - fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{ + fn new(ptr: *const __gl_imports::ffi::c_void) -> FnPtr {{ if ptr.is_null() {{ FnPtr {{ - f: missing_fn_panic as *const __gl_imports::raw::c_void, + f: missing_fn_panic as *const __gl_imports::ffi::c_void, is_loaded: false }} }} else {{ @@ -185,12 +185,12 @@ where /// let gl = Gl::load_with(|s| glfw.get_proc_address(s)); /// ~~~ #[allow(dead_code, unused_variables)] - pub fn load_with(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{ + pub fn load_with(mut loadfn: F) -> {api} where F: FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void {{ #[inline(never)] - fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void, - symbol: &'static str, - symbols: &[&'static str]) - -> *const __gl_imports::raw::c_void {{ + fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void, + symbol: &'static {s_type}, + symbols: &[&'static {s_type}]) + -> *const __gl_imports::ffi::c_void {{ let mut ptr = loadfn(symbol); if ptr.is_null() {{ for &sym in symbols {{ @@ -200,22 +200,24 @@ where }} ptr }} - let mut metaloadfn = |symbol: &'static str, symbols: &[&'static str]| {{ + let mut metaloadfn = |symbol: &'static {s_type}, symbols: &[&'static {s_type}]| {{ do_metaloadfn(&mut loadfn, symbol, symbols) }}; {api} {{", + s_type = super::SYMBOL_NAME_TYPE, api = super::gen_struct_name(registry.api))?; for cmd in ®istry.cmds { writeln!( dest, - "{name}: FnPtr::new(metaloadfn(\"{symbol}\", &[{fallbacks}])),", + "{name}: FnPtr::new(metaloadfn({s_prefix}\"{symbol}\", &[{fallbacks}])),", name = cmd.proto.ident, + s_prefix = super::SYMBOL_NAME_PREFIX, symbol = super::gen_symbol_name(registry.api, &cmd.proto.ident), fallbacks = match registry.aliases.get(&cmd.proto.ident) { Some(fbs) => fbs .iter() - .map(|name| format!("\"{}\"", super::gen_symbol_name(registry.api, &name))) + .map(|name| format!("{}\"{}\"", super::SYMBOL_NAME_PREFIX, super::gen_symbol_name(registry.api, &name))) .collect::>() .join(", "), None => format!(""), diff --git a/gl_generator/generators/global_gen.rs b/gl_generator/generators/global_gen.rs index 2ed8a059..c8a2cef7 100644 --- a/gl_generator/generators/global_gen.rs +++ b/gl_generator/generators/global_gen.rs @@ -47,8 +47,8 @@ where dest, r#" mod __gl_imports {{ - pub use std::mem; - pub use std::os::raw; + pub use core::mem; + pub use core::ffi; }} "# ) @@ -63,9 +63,9 @@ where dest, r#" #[inline(never)] - fn metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void, - symbol: &'static str, - fallbacks: &[&'static str]) -> *const __gl_imports::raw::c_void {{ + fn metaloadfn(loadfn: &mut dyn FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void, + symbol: &'static {s_type}, + fallbacks: &[&'static {s_type}]) -> *const __gl_imports::ffi::c_void {{ let mut ptr = loadfn(symbol); if ptr.is_null() {{ for &sym in fallbacks {{ @@ -75,8 +75,7 @@ where }} ptr }} - "# - ) + "#, s_type = super::SYMBOL_NAME_TYPE) } /// Creates a `types` module which contains all the type aliases. @@ -156,16 +155,16 @@ where #[allow(missing_copy_implementations)] pub struct FnPtr {{ /// The function pointer that will be used when calling the function. - f: *const __gl_imports::raw::c_void, + f: *const __gl_imports::ffi::c_void, /// True if the pointer points to a real function, false if points to a `panic!` fn. is_loaded: bool, }} impl FnPtr {{ /// Creates a `FnPtr` from a load attempt. - pub fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{ + pub fn new(ptr: *const __gl_imports::ffi::c_void) -> FnPtr {{ if ptr.is_null() {{ - FnPtr {{ f: missing_fn_panic as *const __gl_imports::raw::c_void, is_loaded: false }} + FnPtr {{ f: missing_fn_panic as *const __gl_imports::ffi::c_void, is_loaded: false }} }} else {{ FnPtr {{ f: ptr, is_loaded: true }} }} @@ -184,7 +183,7 @@ where "mod storage {{ #![allow(non_snake_case)] #![allow(non_upper_case_globals)] - use super::__gl_imports::raw; + use super::__gl_imports::ffi; use super::FnPtr;" )?; @@ -192,7 +191,7 @@ where writeln!( dest, "pub static mut {name}: FnPtr = FnPtr {{ - f: super::missing_fn_panic as *const raw::c_void, + f: super::missing_fn_panic as *const ffi::c_void, is_loaded: false }};", name = c.proto.ident @@ -215,7 +214,7 @@ where Some(v) => { let names = v .iter() - .map(|name| format!("\"{}\"", super::gen_symbol_name(registry.api, &name[..]))) + .map(|name| format!("{}\"{}\"", super::SYMBOL_NAME_PREFIX, super::gen_symbol_name(registry.api, &name[..]))) .collect::>(); format!("&[{}]", names.join(", ")) }, @@ -231,7 +230,7 @@ where #[allow(non_snake_case)] pub mod {fnname} {{ use super::{{storage, metaloadfn}}; - use super::__gl_imports::raw; + use super::__gl_imports::ffi; use super::FnPtr; #[inline] @@ -241,14 +240,16 @@ where }} #[allow(dead_code)] - pub fn load_with(mut loadfn: F) where F: FnMut(&'static str) -> *const raw::c_void {{ + pub fn load_with(mut loadfn: F) where F: FnMut(&'static {s_type}) -> *const ffi::c_void {{ unsafe {{ - storage::{fnname} = FnPtr::new(metaloadfn(&mut loadfn, "{symbol}", {fallbacks})) + storage::{fnname} = FnPtr::new(metaloadfn(&mut loadfn, {s_prefix}"{symbol}", {fallbacks})) }} }} }} "##, fnname = fnname, + s_type = super::SYMBOL_NAME_TYPE, + s_prefix = super::SYMBOL_NAME_PREFIX, fallbacks = fallbacks, symbol = symbol )?; @@ -290,10 +291,11 @@ where /// gl::load_with(|s| glfw.get_proc_address(s)); /// ~~~ #[allow(dead_code)] - pub fn load_with(mut loadfn: F) where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{ + pub fn load_with(mut loadfn: F) where F: FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void {{ #[inline(never)] - fn inner(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void) {{ - ")?; + fn inner(loadfn: &mut dyn FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void) {{ + ", + s_type = super::SYMBOL_NAME_TYPE)?; for c in ®istry.cmds { writeln!( diff --git a/gl_generator/generators/mod.rs b/gl_generator/generators/mod.rs index f04c5b05..0fd9af47 100644 --- a/gl_generator/generators/mod.rs +++ b/gl_generator/generators/mod.rs @@ -16,6 +16,22 @@ use registry::{Cmd, Enum, Registry}; use std::io; use Api; +pub const SYMBOL_NAME_TYPE: &'static str = { + #[cfg(not(feature = "cstr_symbols"))] + { "str" } + #[cfg(feature = "cstr_symbols")] + { "core::ffi::CStr" } // NOTE: Im using core::ffi instead of __gl_imports::ffi here on purpose + // there are some files that use this module that don't have the __gl_imports module imported + // and I don't want two variations of the same thing (so we are using the complete core::ffi path) +}; + +pub const SYMBOL_NAME_PREFIX: &'static str = { + #[cfg(not(feature = "cstr_symbols"))] + { "" } + #[cfg(feature = "cstr_symbols")] + { "c" } // https://doc.rust-lang.org/edition-guide/rust-2021/c-string-literals.html +}; + pub mod debug_struct_gen; pub mod global_gen; pub mod static_gen; diff --git a/gl_generator/generators/static_gen.rs b/gl_generator/generators/static_gen.rs index a1d2a91a..598a24ec 100644 --- a/gl_generator/generators/static_gen.rs +++ b/gl_generator/generators/static_gen.rs @@ -41,8 +41,8 @@ where dest, r#" mod __gl_imports {{ - pub use std::mem; - pub use std::os::raw; + pub use core::mem; + pub use core::ffi; }} "# ) diff --git a/gl_generator/generators/static_struct_gen.rs b/gl_generator/generators/static_struct_gen.rs index 0e385cb5..3582850d 100644 --- a/gl_generator/generators/static_struct_gen.rs +++ b/gl_generator/generators/static_struct_gen.rs @@ -43,8 +43,8 @@ where dest, r#" mod __gl_imports {{ - pub use std::mem; - pub use std::os::raw; + pub use core::mem; + pub use core::ffi; }} "# ) @@ -108,9 +108,10 @@ where "impl {api} {{ /// Stub function. #[allow(dead_code)] - pub fn load_with(mut _loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{ + pub fn load_with(mut _loadfn: F) -> {api} where F: FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void {{ {api} }}", + s_type = super::SYMBOL_NAME_TYPE, api = super::gen_struct_name(registry.api), )?; diff --git a/gl_generator/generators/struct_gen.rs b/gl_generator/generators/struct_gen.rs index 55dbd32c..2d3f6378 100644 --- a/gl_generator/generators/struct_gen.rs +++ b/gl_generator/generators/struct_gen.rs @@ -44,9 +44,9 @@ where dest, r#" mod __gl_imports {{ - pub use std::mem; - pub use std::marker::Send; - pub use std::os::raw; + pub use core::mem; + pub use core::marker::Send; + pub use core::ffi; }} "# ) @@ -96,17 +96,17 @@ where #[derive(Clone)] pub struct FnPtr {{ /// The function pointer that will be used when calling the function. - f: *const __gl_imports::raw::c_void, + f: *const __gl_imports::ffi::c_void, /// True if the pointer points to a real function, false if points to a `panic!` fn. is_loaded: bool, }} impl FnPtr {{ /// Creates a `FnPtr` from a load attempt. - fn new(ptr: *const __gl_imports::raw::c_void) -> FnPtr {{ + fn new(ptr: *const __gl_imports::ffi::c_void) -> FnPtr {{ if ptr.is_null() {{ FnPtr {{ - f: missing_fn_panic as *const __gl_imports::raw::c_void, + f: missing_fn_panic as *const __gl_imports::ffi::c_void, is_loaded: false }} }} else {{ @@ -185,12 +185,12 @@ where /// let gl = Gl::load_with(|s| glfw.get_proc_address(s)); /// ~~~ #[allow(dead_code, unused_variables)] - pub fn load_with(mut loadfn: F) -> {api} where F: FnMut(&'static str) -> *const __gl_imports::raw::c_void {{ + pub fn load_with(mut loadfn: F) -> {api} where F: FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void {{ #[inline(never)] - fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static str) -> *const __gl_imports::raw::c_void, - symbol: &'static str, - symbols: &[&'static str]) - -> *const __gl_imports::raw::c_void {{ + fn do_metaloadfn(loadfn: &mut dyn FnMut(&'static {s_type}) -> *const __gl_imports::ffi::c_void, + symbol: &'static {s_type}, + symbols: &[&'static {s_type}]) + -> *const __gl_imports::ffi::c_void {{ let mut ptr = loadfn(symbol); if ptr.is_null() {{ for &sym in symbols {{ @@ -200,22 +200,24 @@ where }} ptr }} - let mut metaloadfn = |symbol: &'static str, symbols: &[&'static str]| {{ + let mut metaloadfn = |symbol: &'static {s_type}, symbols: &[&'static {s_type}]| {{ do_metaloadfn(&mut loadfn, symbol, symbols) }}; {api} {{", + s_type = super::SYMBOL_NAME_TYPE, api = super::gen_struct_name(registry.api))?; for cmd in ®istry.cmds { writeln!( dest, - "{name}: FnPtr::new(metaloadfn(\"{symbol}\", &[{fallbacks}])),", + "{name}: FnPtr::new(metaloadfn({s_prefix}\"{symbol}\", &[{fallbacks}])),", name = cmd.proto.ident, + s_prefix = super::SYMBOL_NAME_PREFIX, symbol = super::gen_symbol_name(registry.api, &cmd.proto.ident), fallbacks = match registry.aliases.get(&cmd.proto.ident) { Some(fbs) => fbs .iter() - .map(|name| format!("\"{}\"", super::gen_symbol_name(registry.api, &name))) + .map(|name| format!("{}\"{}\"", super::SYMBOL_NAME_PREFIX, super::gen_symbol_name(registry.api, &name))) .collect::>() .join(", "), None => format!(""), diff --git a/gl_generator/generators/templates/types/egl.rs b/gl_generator/generators/templates/types/egl.rs index 877638ab..0c3971f6 100644 --- a/gl_generator/generators/templates/types/egl.rs +++ b/gl_generator/generators/templates/types/egl.rs @@ -22,48 +22,48 @@ pub type NativeWindowType = super::NativeWindowType; // EGL alises pub type Bool = EGLBoolean; // TODO: not sure -pub type EGLBoolean = super::__gl_imports::raw::c_uint; -pub type EGLenum = super::__gl_imports::raw::c_uint; +pub type EGLBoolean = super::__gl_imports::ffi::c_uint; +pub type EGLenum = super::__gl_imports::ffi::c_uint; pub type EGLAttribKHR = isize; pub type EGLAttrib = isize; -pub type EGLConfig = *const super::__gl_imports::raw::c_void; -pub type EGLContext = *const super::__gl_imports::raw::c_void; -pub type EGLDeviceEXT = *const super::__gl_imports::raw::c_void; -pub type EGLDisplay = *const super::__gl_imports::raw::c_void; -pub type EGLSurface = *const super::__gl_imports::raw::c_void; -pub type EGLClientBuffer = *const super::__gl_imports::raw::c_void; +pub type EGLConfig = *const super::__gl_imports::ffi::c_void; +pub type EGLContext = *const super::__gl_imports::ffi::c_void; +pub type EGLDeviceEXT = *const super::__gl_imports::ffi::c_void; +pub type EGLDisplay = *const super::__gl_imports::ffi::c_void; +pub type EGLSurface = *const super::__gl_imports::ffi::c_void; +pub type EGLClientBuffer = *const super::__gl_imports::ffi::c_void; pub enum __eglMustCastToProperFunctionPointerType_fn {} pub type __eglMustCastToProperFunctionPointerType = *mut __eglMustCastToProperFunctionPointerType_fn; -pub type EGLImageKHR = *const super::__gl_imports::raw::c_void; -pub type EGLImage = *const super::__gl_imports::raw::c_void; -pub type EGLOutputLayerEXT = *const super::__gl_imports::raw::c_void; -pub type EGLOutputPortEXT = *const super::__gl_imports::raw::c_void; -pub type EGLSyncKHR = *const super::__gl_imports::raw::c_void; -pub type EGLSync = *const super::__gl_imports::raw::c_void; +pub type EGLImageKHR = *const super::__gl_imports::ffi::c_void; +pub type EGLImage = *const super::__gl_imports::ffi::c_void; +pub type EGLOutputLayerEXT = *const super::__gl_imports::ffi::c_void; +pub type EGLOutputPortEXT = *const super::__gl_imports::ffi::c_void; +pub type EGLSyncKHR = *const super::__gl_imports::ffi::c_void; +pub type EGLSync = *const super::__gl_imports::ffi::c_void; pub type EGLTimeKHR = khronos_utime_nanoseconds_t; pub type EGLTime = khronos_utime_nanoseconds_t; -pub type EGLSyncNV = *const super::__gl_imports::raw::c_void; +pub type EGLSyncNV = *const super::__gl_imports::ffi::c_void; pub type EGLTimeNV = khronos_utime_nanoseconds_t; pub type EGLuint64NV = khronos_utime_nanoseconds_t; -pub type EGLStreamKHR = *const super::__gl_imports::raw::c_void; +pub type EGLStreamKHR = *const super::__gl_imports::ffi::c_void; pub type EGLuint64KHR = khronos_uint64_t; -pub type EGLNativeFileDescriptorKHR = super::__gl_imports::raw::c_int; +pub type EGLNativeFileDescriptorKHR = super::__gl_imports::ffi::c_int; pub type EGLsizeiANDROID = khronos_ssize_t; -pub type EGLSetBlobFuncANDROID = extern "system" fn(*const super::__gl_imports::raw::c_void, +pub type EGLSetBlobFuncANDROID = extern "system" fn(*const super::__gl_imports::ffi::c_void, EGLsizeiANDROID, - *const super::__gl_imports::raw::c_void, + *const super::__gl_imports::ffi::c_void, EGLsizeiANDROID) -> (); -pub type EGLGetBlobFuncANDROID = extern "system" fn(*const super::__gl_imports::raw::c_void, +pub type EGLGetBlobFuncANDROID = extern "system" fn(*const super::__gl_imports::ffi::c_void, EGLsizeiANDROID, - *mut super::__gl_imports::raw::c_void, + *mut super::__gl_imports::ffi::c_void, EGLsizeiANDROID) -> EGLsizeiANDROID; #[repr(C)] pub struct EGLClientPixmapHI { - pData: *const super::__gl_imports::raw::c_void, + pData: *const super::__gl_imports::ffi::c_void, iWidth: EGLint, iHeight: EGLint, iStride: EGLint, diff --git a/gl_generator/generators/templates/types/gl.rs b/gl_generator/generators/templates/types/gl.rs index 90e46201..5df1777e 100644 --- a/gl_generator/generators/templates/types/gl.rs +++ b/gl_generator/generators/templates/types/gl.rs @@ -1,31 +1,31 @@ // Common types from OpenGL 1.1 -pub type GLenum = super::__gl_imports::raw::c_uint; -pub type GLboolean = super::__gl_imports::raw::c_uchar; -pub type GLbitfield = super::__gl_imports::raw::c_uint; -pub type GLvoid = super::__gl_imports::raw::c_void; -pub type GLbyte = super::__gl_imports::raw::c_char; -pub type GLshort = super::__gl_imports::raw::c_short; -pub type GLint = super::__gl_imports::raw::c_int; -pub type GLclampx = super::__gl_imports::raw::c_int; -pub type GLubyte = super::__gl_imports::raw::c_uchar; -pub type GLushort = super::__gl_imports::raw::c_ushort; -pub type GLuint = super::__gl_imports::raw::c_uint; -pub type GLsizei = super::__gl_imports::raw::c_int; -pub type GLfloat = super::__gl_imports::raw::c_float; -pub type GLclampf = super::__gl_imports::raw::c_float; -pub type GLdouble = super::__gl_imports::raw::c_double; -pub type GLclampd = super::__gl_imports::raw::c_double; -pub type GLeglImageOES = *const super::__gl_imports::raw::c_void; -pub type GLchar = super::__gl_imports::raw::c_char; -pub type GLcharARB = super::__gl_imports::raw::c_char; +pub type GLenum = super::__gl_imports::ffi::c_uint; +pub type GLboolean = super::__gl_imports::ffi::c_uchar; +pub type GLbitfield = super::__gl_imports::ffi::c_uint; +pub type GLvoid = super::__gl_imports::ffi::c_void; +pub type GLbyte = super::__gl_imports::ffi::c_char; +pub type GLshort = super::__gl_imports::ffi::c_short; +pub type GLint = super::__gl_imports::ffi::c_int; +pub type GLclampx = super::__gl_imports::ffi::c_int; +pub type GLubyte = super::__gl_imports::ffi::c_uchar; +pub type GLushort = super::__gl_imports::ffi::c_ushort; +pub type GLuint = super::__gl_imports::ffi::c_uint; +pub type GLsizei = super::__gl_imports::ffi::c_int; +pub type GLfloat = super::__gl_imports::ffi::c_float; +pub type GLclampf = super::__gl_imports::ffi::c_float; +pub type GLdouble = super::__gl_imports::ffi::c_double; +pub type GLclampd = super::__gl_imports::ffi::c_double; +pub type GLeglImageOES = *const super::__gl_imports::ffi::c_void; +pub type GLchar = super::__gl_imports::ffi::c_char; +pub type GLcharARB = super::__gl_imports::ffi::c_char; #[cfg(target_os = "macos")] -pub type GLhandleARB = *const super::__gl_imports::raw::c_void; +pub type GLhandleARB = *const super::__gl_imports::ffi::c_void; #[cfg(not(target_os = "macos"))] -pub type GLhandleARB = super::__gl_imports::raw::c_uint; +pub type GLhandleARB = super::__gl_imports::ffi::c_uint; -pub type GLhalfARB = super::__gl_imports::raw::c_ushort; -pub type GLhalf = super::__gl_imports::raw::c_ushort; +pub type GLhalfARB = super::__gl_imports::ffi::c_ushort; +pub type GLhalf = super::__gl_imports::ffi::c_ushort; // Must be 32 bits pub type GLfixed = GLint; @@ -52,21 +52,21 @@ pub type GLDEBUGPROC = Option; + userParam: *mut super::__gl_imports::ffi::c_void)>; pub type GLDEBUGPROCARB = Option; + userParam: *mut super::__gl_imports::ffi::c_void)>; pub type GLDEBUGPROCKHR = Option; + userParam: *mut super::__gl_imports::ffi::c_void)>; // GLES 1 types // "pub type GLclampx = i32;", @@ -103,6 +103,6 @@ pub type GLDEBUGPROCAMD = Option; -pub type GLhalfNV = super::__gl_imports::raw::c_ushort; + userParam: *mut super::__gl_imports::ffi::c_void)>; +pub type GLhalfNV = super::__gl_imports::ffi::c_ushort; pub type GLvdpauSurfaceNV = GLintptr; diff --git a/gl_generator/generators/templates/types/glx.rs b/gl_generator/generators/templates/types/glx.rs index b0078da0..fed145b2 100644 --- a/gl_generator/generators/templates/types/glx.rs +++ b/gl_generator/generators/templates/types/glx.rs @@ -1,16 +1,16 @@ -pub type XID = super::__gl_imports::raw::c_ulong; -pub type Bool = super::__gl_imports::raw::c_int; // Not sure if this is correct... +pub type XID = super::__gl_imports::ffi::c_ulong; +pub type Bool = super::__gl_imports::ffi::c_int; // Not sure if this is correct... pub enum Display {} pub type Font = XID; pub type Pixmap = XID; pub enum Visual {} // TODO: not sure -pub type VisualID = super::__gl_imports::raw::c_ulong; // TODO: not sure +pub type VisualID = super::__gl_imports::ffi::c_ulong; // TODO: not sure pub type Window = XID; pub type GLXFBConfigID = XID; -pub type GLXFBConfig = *const super::__gl_imports::raw::c_void; +pub type GLXFBConfig = *const super::__gl_imports::ffi::c_void; pub type GLXContextID = XID; -pub type GLXContext = *const super::__gl_imports::raw::c_void; +pub type GLXContext = *const super::__gl_imports::ffi::c_void; pub type GLXPixmap = XID; pub type GLXDrawable = XID; pub type GLXWindow = XID; @@ -18,51 +18,51 @@ pub type GLXPbuffer = XID; pub enum __GLXextFuncPtr_fn {} pub type __GLXextFuncPtr = *mut __GLXextFuncPtr_fn; pub type GLXVideoCaptureDeviceNV = XID; -pub type GLXVideoDeviceNV = super::__gl_imports::raw::c_int; +pub type GLXVideoDeviceNV = super::__gl_imports::ffi::c_int; pub type GLXVideoSourceSGIX = XID; pub type GLXFBConfigIDSGIX = XID; -pub type GLXFBConfigSGIX = *const super::__gl_imports::raw::c_void; +pub type GLXFBConfigSGIX = *const super::__gl_imports::ffi::c_void; pub type GLXPbufferSGIX = XID; #[repr(C)] pub struct XVisualInfo { pub visual: *mut Visual, pub visualid: VisualID, - pub screen: super::__gl_imports::raw::c_int, - pub depth: super::__gl_imports::raw::c_int, - pub class: super::__gl_imports::raw::c_int, - pub red_mask: super::__gl_imports::raw::c_ulong, - pub green_mask: super::__gl_imports::raw::c_ulong, - pub blue_mask: super::__gl_imports::raw::c_ulong, - pub colormap_size: super::__gl_imports::raw::c_int, - pub bits_per_rgb: super::__gl_imports::raw::c_int, + pub screen: super::__gl_imports::ffi::c_int, + pub depth: super::__gl_imports::ffi::c_int, + pub class: super::__gl_imports::ffi::c_int, + pub red_mask: super::__gl_imports::ffi::c_ulong, + pub green_mask: super::__gl_imports::ffi::c_ulong, + pub blue_mask: super::__gl_imports::ffi::c_ulong, + pub colormap_size: super::__gl_imports::ffi::c_int, + pub bits_per_rgb: super::__gl_imports::ffi::c_int, } #[repr(C)] pub struct GLXPbufferClobberEvent { - pub event_type: super::__gl_imports::raw::c_int, // GLX_DAMAGED or GLX_SAVED - pub draw_type: super::__gl_imports::raw::c_int, // GLX_WINDOW or GLX_PBUFFER - pub serial: super::__gl_imports::raw::c_ulong, // # of last request processed by server + pub event_type: super::__gl_imports::ffi::c_int, // GLX_DAMAGED or GLX_SAVED + pub draw_type: super::__gl_imports::ffi::c_int, // GLX_WINDOW or GLX_PBUFFER + pub serial: super::__gl_imports::ffi::c_ulong, // # of last request processed by server pub send_event: Bool, // true if this came for SendEvent request pub display: *const Display, // display the event was read from pub drawable: GLXDrawable, // XID of Drawable - pub buffer_mask: super::__gl_imports::raw::c_uint, // mask indicating which buffers are affected - pub aux_buffer: super::__gl_imports::raw::c_uint, // which aux buffer was affected - pub x: super::__gl_imports::raw::c_int, - pub y: super::__gl_imports::raw::c_int, - pub width: super::__gl_imports::raw::c_int, - pub height: super::__gl_imports::raw::c_int, - pub count: super::__gl_imports::raw::c_int, // if nonzero, at least this many more + pub buffer_mask: super::__gl_imports::ffi::c_uint, // mask indicating which buffers are affected + pub aux_buffer: super::__gl_imports::ffi::c_uint, // which aux buffer was affected + pub x: super::__gl_imports::ffi::c_int, + pub y: super::__gl_imports::ffi::c_int, + pub width: super::__gl_imports::ffi::c_int, + pub height: super::__gl_imports::ffi::c_int, + pub count: super::__gl_imports::ffi::c_int, // if nonzero, at least this many more } #[repr(C)] pub struct GLXBufferSwapComplete { - pub type_: super::__gl_imports::raw::c_int, - pub serial: super::__gl_imports::raw::c_ulong, // # of last request processed by server + pub type_: super::__gl_imports::ffi::c_int, + pub serial: super::__gl_imports::ffi::c_ulong, // # of last request processed by server pub send_event: Bool, // true if this came from a SendEvent request pub display: *const Display, // Display the event was read from pub drawable: GLXDrawable, // drawable on which event was requested in event mask - pub event_type: super::__gl_imports::raw::c_int, + pub event_type: super::__gl_imports::ffi::c_int, pub ust: i64, pub msc: i64, pub sbc: i64, @@ -76,53 +76,53 @@ pub struct GLXBufferSwapComplete { #[repr(C)] pub struct GLXBufferClobberEventSGIX { - pub type_: super::__gl_imports::raw::c_int, - pub serial: super::__gl_imports::raw::c_ulong, // # of last request processed by server + pub type_: super::__gl_imports::ffi::c_int, + pub serial: super::__gl_imports::ffi::c_ulong, // # of last request processed by server pub send_event: Bool, // true if this came for SendEvent request pub display: *const Display, // display the event was read from pub drawable: GLXDrawable, // i.d. of Drawable - pub event_type: super::__gl_imports::raw::c_int, // GLX_DAMAGED_SGIX or GLX_SAVED_SGIX - pub draw_type: super::__gl_imports::raw::c_int, // GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX - pub mask: super::__gl_imports::raw::c_uint, // mask indicating which buffers are affected - pub x: super::__gl_imports::raw::c_int, - pub y: super::__gl_imports::raw::c_int, - pub width: super::__gl_imports::raw::c_int, - pub height: super::__gl_imports::raw::c_int, - pub count: super::__gl_imports::raw::c_int, // if nonzero, at least this many more + pub event_type: super::__gl_imports::ffi::c_int, // GLX_DAMAGED_SGIX or GLX_SAVED_SGIX + pub draw_type: super::__gl_imports::ffi::c_int, // GLX_WINDOW_SGIX or GLX_PBUFFER_SGIX + pub mask: super::__gl_imports::ffi::c_uint, // mask indicating which buffers are affected + pub x: super::__gl_imports::ffi::c_int, + pub y: super::__gl_imports::ffi::c_int, + pub width: super::__gl_imports::ffi::c_int, + pub height: super::__gl_imports::ffi::c_int, + pub count: super::__gl_imports::ffi::c_int, // if nonzero, at least this many more } #[repr(C)] pub struct GLXHyperpipeNetworkSGIX { - pub pipeName: [super::__gl_imports::raw::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] - pub networkId: super::__gl_imports::raw::c_int, + pub pipeName: [super::__gl_imports::ffi::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] + pub networkId: super::__gl_imports::ffi::c_int, } #[repr(C)] pub struct GLXHyperpipeConfigSGIX { - pub pipeName: [super::__gl_imports::raw::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] - pub channel: super::__gl_imports::raw::c_int, - pub participationType: super::__gl_imports::raw::c_uint, - pub timeSlice: super::__gl_imports::raw::c_int, + pub pipeName: [super::__gl_imports::ffi::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] + pub channel: super::__gl_imports::ffi::c_int, + pub participationType: super::__gl_imports::ffi::c_uint, + pub timeSlice: super::__gl_imports::ffi::c_int, } #[repr(C)] pub struct GLXPipeRect { - pub pipeName: [super::__gl_imports::raw::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] - pub srcXOrigin: super::__gl_imports::raw::c_int, - pub srcYOrigin: super::__gl_imports::raw::c_int, - pub srcWidth: super::__gl_imports::raw::c_int, - pub srcHeight: super::__gl_imports::raw::c_int, - pub destXOrigin: super::__gl_imports::raw::c_int, - pub destYOrigin: super::__gl_imports::raw::c_int, - pub destWidth: super::__gl_imports::raw::c_int, - pub destHeight: super::__gl_imports::raw::c_int, + pub pipeName: [super::__gl_imports::ffi::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] + pub srcXOrigin: super::__gl_imports::ffi::c_int, + pub srcYOrigin: super::__gl_imports::ffi::c_int, + pub srcWidth: super::__gl_imports::ffi::c_int, + pub srcHeight: super::__gl_imports::ffi::c_int, + pub destXOrigin: super::__gl_imports::ffi::c_int, + pub destYOrigin: super::__gl_imports::ffi::c_int, + pub destWidth: super::__gl_imports::ffi::c_int, + pub destHeight: super::__gl_imports::ffi::c_int, } #[repr(C)] pub struct GLXPipeRectLimits { - pub pipeName: [super::__gl_imports::raw::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] - pub XOrigin: super::__gl_imports::raw::c_int, - pub YOrigin: super::__gl_imports::raw::c_int, - pub maxHeight: super::__gl_imports::raw::c_int, - pub maxWidth: super::__gl_imports::raw::c_int, + pub pipeName: [super::__gl_imports::ffi::c_char; 80], // Should be [GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX] + pub XOrigin: super::__gl_imports::ffi::c_int, + pub YOrigin: super::__gl_imports::ffi::c_int, + pub maxHeight: super::__gl_imports::ffi::c_int, + pub maxWidth: super::__gl_imports::ffi::c_int, } diff --git a/gl_generator/generators/templates/types/wgl.rs b/gl_generator/generators/templates/types/wgl.rs index a376d4fa..397d3400 100644 --- a/gl_generator/generators/templates/types/wgl.rs +++ b/gl_generator/generators/templates/types/wgl.rs @@ -1,31 +1,31 @@ // From WinNT.h -pub type CHAR = super::__gl_imports::raw::c_char; +pub type CHAR = super::__gl_imports::ffi::c_char; pub type HANDLE = PVOID; -pub type LONG = super::__gl_imports::raw::c_long; -pub type LPCSTR = *const super::__gl_imports::raw::c_char; +pub type LONG = super::__gl_imports::ffi::c_long; +pub type LPCSTR = *const super::__gl_imports::ffi::c_char; pub type VOID = (); // #define DECLARE_HANDLE(name) struct name##__{int unused;}; typedef struct name##__ *name -pub type HPBUFFERARB = *const super::__gl_imports::raw::c_void; -pub type HPBUFFEREXT = *const super::__gl_imports::raw::c_void; -pub type HVIDEOOUTPUTDEVICENV = *const super::__gl_imports::raw::c_void; -pub type HPVIDEODEV = *const super::__gl_imports::raw::c_void; -pub type HPGPUNV = *const super::__gl_imports::raw::c_void; -pub type HGPUNV = *const super::__gl_imports::raw::c_void; -pub type HVIDEOINPUTDEVICENV = *const super::__gl_imports::raw::c_void; +pub type HPBUFFERARB = *const super::__gl_imports::ffi::c_void; +pub type HPBUFFEREXT = *const super::__gl_imports::ffi::c_void; +pub type HVIDEOOUTPUTDEVICENV = *const super::__gl_imports::ffi::c_void; +pub type HPVIDEODEV = *const super::__gl_imports::ffi::c_void; +pub type HPGPUNV = *const super::__gl_imports::ffi::c_void; +pub type HGPUNV = *const super::__gl_imports::ffi::c_void; +pub type HVIDEOINPUTDEVICENV = *const super::__gl_imports::ffi::c_void; // From Windef.h -pub type BOOL = super::__gl_imports::raw::c_int; -pub type BYTE = super::__gl_imports::raw::c_uchar; +pub type BOOL = super::__gl_imports::ffi::c_int; +pub type BYTE = super::__gl_imports::ffi::c_uchar; pub type COLORREF = DWORD; -pub type FLOAT = super::__gl_imports::raw::c_float; +pub type FLOAT = super::__gl_imports::ffi::c_float; pub type HDC = HANDLE; pub type HENHMETAFILE = HANDLE; -pub type HGLRC = *const super::__gl_imports::raw::c_void; -pub type INT = super::__gl_imports::raw::c_int; -pub type PVOID = *const super::__gl_imports::raw::c_void; -pub type LPVOID = *const super::__gl_imports::raw::c_void; +pub type HGLRC = *const super::__gl_imports::ffi::c_void; +pub type INT = super::__gl_imports::ffi::c_int; +pub type PVOID = *const super::__gl_imports::ffi::c_void; +pub type LPVOID = *const super::__gl_imports::ffi::c_void; pub enum __PROC_fn {} pub type PROC = *mut __PROC_fn; @@ -37,9 +37,9 @@ pub struct RECT { bottom: LONG, } -pub type UINT = super::__gl_imports::raw::c_uint; -pub type USHORT = super::__gl_imports::raw::c_ushort; -pub type WORD = super::__gl_imports::raw::c_ushort; +pub type UINT = super::__gl_imports::ffi::c_uint; +pub type USHORT = super::__gl_imports::ffi::c_ushort; +pub type WORD = super::__gl_imports::ffi::c_ushort; // From BaseTsd.h @@ -48,7 +48,7 @@ pub type INT64 = i64; // From IntSafe.h -pub type DWORD = super::__gl_imports::raw::c_ulong; +pub type DWORD = super::__gl_imports::ffi::c_ulong; // From Wingdi.h diff --git a/gl_generator/registry/parse.rs b/gl_generator/registry/parse.rs index cf5755d0..94ef3693 100644 --- a/gl_generator/registry/parse.rs +++ b/gl_generator/registry/parse.rs @@ -852,8 +852,8 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "GLushort *" => "*mut types::GLushort", "GLvoid *" => "*mut types::GLvoid", "GLvoid **" => "*const *mut types::GLvoid", - "void *" => "*mut __gl_imports::raw::c_void", - "void **" => "*const *mut __gl_imports::raw::c_void", + "void *" => "*mut __gl_imports::ffi::c_void", + "void **" => "*const *mut __gl_imports::ffi::c_void", "const GLboolean *" => "*const types::GLboolean", "const GLbyte *" => "*const types::GLbyte", "const GLchar *" => "*const types::GLchar", @@ -880,9 +880,9 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "const GLushort *" => "*const types::GLushort", "const GLvdpauSurfaceNV *" => "*const types::GLvdpauSurfaceNV", "const GLvoid *" => "*const types::GLvoid", - "const void*" | "const void *" => "*const __gl_imports::raw::c_void", - "const void **" => "*const *const __gl_imports::raw::c_void", - "const void *const*" => "*const *const __gl_imports::raw::c_void", + "const void*" | "const void *" => "*const __gl_imports::ffi::c_void", + "const void **" => "*const *const __gl_imports::ffi::c_void", + "const void *const*" => "*const *const __gl_imports::ffi::c_void", "const GLboolean **" => "*const *const types::GLboolean", "const GLchar **" => "*const *const types::GLchar", "const GLcharARB **" => "*const *const types::GLcharARB", @@ -923,11 +923,11 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "Window" => "types::Window", "__GLXextFuncPtr" => "types::__GLXextFuncPtr", "const GLXContext" => "const types::GLXContext", - "float" => "__gl_imports::raw::c_float", - "int" => "__gl_imports::raw::c_int", + "float" => "__gl_imports::ffi::c_float", + "int" => "__gl_imports::ffi::c_int", "int64_t" => "i64", - "unsigned int" => "__gl_imports::raw::c_uint", - "unsigned long" => "__gl_imports::raw::c_ulong", + "unsigned int" => "__gl_imports::ffi::c_uint", + "unsigned long" => "__gl_imports::ffi::c_ulong", // "void " => "()", "DMparams *" => "*mut types::DMparams", "Display *" => "*mut types::Display", @@ -940,16 +940,16 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { // "GLuint *" => "*mut types::GLuint", "XVisualInfo *" => "*mut types::XVisualInfo", // "const GLubyte *" => "*GLubyte", - "const char *" => "*const __gl_imports::raw::c_char", - "const int *" => "*const __gl_imports::raw::c_int", - // "const void *" => "*const __gl_imports::raw::c_void", - "int *" => "*mut __gl_imports::raw::c_int", + "const char *" => "*const __gl_imports::ffi::c_char", + "const int *" => "*const __gl_imports::ffi::c_int", + // "const void *" => "*const __gl_imports::ffi::c_void", + "int *" => "*mut __gl_imports::ffi::c_int", "int32_t *" => "*mut i32", "int64_t *" => "*mut i64", - "long *" => "*mut __gl_imports::raw::c_long", - "unsigned int *" => "*mut __gl_imports::raw::c_uint", - "unsigned long *" => "*mut __gl_imports::raw::c_ulong", - // "void *" => "*mut __gl_imports::raw::c_void", + "long *" => "*mut __gl_imports::ffi::c_long", + "unsigned int *" => "*mut __gl_imports::ffi::c_uint", + "unsigned long *" => "*mut __gl_imports::ffi::c_ulong", + // "void *" => "*mut __gl_imports::ffi::c_void", // wgl.xml types "BOOL" => "types::BOOL", @@ -982,8 +982,8 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "PROC" => "types::PROC", "UINT" => "types::UINT", "VOID" => "types::VOID", - // "int " => "__gl_imports::raw::c_int", - // "unsigned int " => "__gl_imports::raw::c_uint", + // "int " => "__gl_imports::ffi::c_int", + // "unsigned int " => "__gl_imports::ffi::c_uint", // "void " => "()", "BOOL *" => "*mut types::BOOL", "DWORD *" => "*mut types::DWORD", @@ -1008,12 +1008,12 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "const LPVOID *" => "*const types::LPVOID", "const PIXELFORMATDESCRIPTOR *" => "*const types::IXELFORMATDESCRIPTOR", "const USHORT *" => "*const types::USHORT", - // "const char *" => "*const __gl_imports::raw::c_char", - // "const int *" => "*const __gl_imports::raw::c_int", - "float *" => "*mut __gl_imports::raw::c_float", - // "int *" => "*mut __gl_imports::raw::c_int", - // "unsigned long *" => "*mut __gl_imports::raw::c_ulong", - // "void *" => "*mut __gl_imports::raw::c_void", + // "const char *" => "*const __gl_imports::ffi::c_char", + // "const int *" => "*const __gl_imports::ffi::c_int", + "float *" => "*mut __gl_imports::ffi::c_float", + // "int *" => "*mut __gl_imports::ffi::c_int", + // "unsigned long *" => "*mut __gl_imports::ffi::c_ulong", + // "void *" => "*mut __gl_imports::ffi::c_void", // elx.xml types "khronos_utime_nanoseconds_t" => "types::khronos_utime_nanoseconds_t", @@ -1076,11 +1076,11 @@ pub fn to_rust_ty>(ty: T) -> Cow<'static, str> { "EGLTimeKHR *" => "*mut types::EGLTimeKHR", "EGLOutputPortEXT *" => "*mut types::EGLOutputPortEXT", "EGLuint64KHR *" => "*mut types::EGLuint64KHR", - "const struct AHardwareBuffer *" => "*const __gl_imports::raw::c_void", // humm - "char *" => "*const __gl_imports::raw::c_char", - "struct wl_buffer *" => "*const __gl_imports::raw::c_void", - "struct wl_display *" => "*const __gl_imports::raw::c_void", - "struct wl_resource *" => "*const __gl_imports::raw::c_void", + "const struct AHardwareBuffer *" => "*const __gl_imports::ffi::c_void", // humm + "char *" => "*const __gl_imports::ffi::c_char", + "struct wl_buffer *" => "*const __gl_imports::ffi::c_void", + "struct wl_display *" => "*const __gl_imports::ffi::c_void", + "struct wl_resource *" => "*const __gl_imports::ffi::c_void", "GLeglClientBufferEXT" => "types::GLeglClientBufferEXT", "GLVULKANPROCNV" => "types::GLVULKANPROCNV", From 5a0664fda4471228e8a0d21ac598f4eae59121d8 Mon Sep 17 00:00:00 2001 From: Gabriel Nigro Date: Tue, 4 Mar 2025 15:15:20 -0300 Subject: [PATCH 2/3] Add documentation about no_std and &CStr support --- README.md | 4 ++-- gl/README.md | 27 ++++++++++++++++++++++++++- gl_generator/README.md | 30 +++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 968b7c69..e6770124 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The following crates are contained in this repository: [README](https://github.com/brendanzab/gl-rs/tree/master/gl) -An OpenGL function pointer loader for the Rust Programming Language. +An no_std OpenGL function pointer loader for the Rust Programming Language. ```toml [dependencies] @@ -29,7 +29,7 @@ gl = "0.14.0" [README](https://github.com/brendanzab/gl-rs/tree/master/gl_generator) -Code generators for creating bindings to the Khronos OpenGL APIs. +Code generators for creating no_std bindings to the Khronos OpenGL APIs. ```toml [build-dependencies] diff --git a/gl/README.md b/gl/README.md index 8e72e504..4af4d140 100644 --- a/gl/README.md +++ b/gl/README.md @@ -4,7 +4,7 @@ [![License](https://img.shields.io/crates/l/gl.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/gl.svg)](https://crates.io/crates/gl) -An OpenGL function pointer loader for the Rust Programming Language. +An no_std OpenGL function pointer loader for the Rust Programming Language. ```toml [dependencies] @@ -60,3 +60,28 @@ if gl::Viewport::is_loaded() { // do something... } ``` + +## Symbol string types +In previous versions, if you needed a null-terminated c-string from the `gl::load_with` function, you had to convert the &str to a CString. This limited the use of this library in `no_std` environments. + +In the latest release you can add the `"cstr_symbols"` feature to +your `Cargo.toml` and the symbol name will now be a null-terminated `&CStr`, so you won't have to convert between them anymore. + +```rust +// Quick example with sdl3-sys + +// Without the feature +gl::load_with(| procname: &str | { + match CString::new(procname) { // Allocates and requires std + Ok(procname) => unsafe { + SDL_GL_GetProcAddress(procname.as_ptr()) as *const _ + }, + Err(_) => ptr::null(), + } +}); + +// With the feature +gl::load_with(| procname: &CStr | { + unsafe { SDL_GL_GetProcAddress(procname.as_ptr()) as *const _ } +}); +``` diff --git a/gl_generator/README.md b/gl_generator/README.md index 41146f21..ba849678 100644 --- a/gl_generator/README.md +++ b/gl_generator/README.md @@ -4,7 +4,7 @@ [![License](https://img.shields.io/crates/l/gl_generator.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/gl_generator.svg)](https://crates.io/crates/gl_generator) -Code generators for creating bindings to the Khronos OpenGL APIs. +Code generators for creating no_std bindings to the Khronos OpenGL APIs. ## Usage @@ -64,8 +64,32 @@ fn main() { } ``` -The `build.rs` file will generate all the OpenGL functions in a file named, -`bindings.rs` plus all enumerations, and all types in the `types` submodule. +The `build.rs` file will generate all the OpenGL functions in a file named `bindings.rs` plus all enumerations and all types in the `types` submodule. Note that while the generated bindings are `no_std`, the generator itself is not. + +## Symbol string types +In previous versions, if you needed a null-terminated c-string from the `gl::load_with` function, you had to convert the &str to a CString. This limited the use of this library in `no_std` environments. + +In the latest release you can add the `"cstr_symbols"` feature to +your `Cargo.toml` and the symbol name will now be a null-terminated `&CStr`, so you won't have to convert between them anymore. + +```rust +// Quick example with sdl3-sys + +// Without the feature +gl::load_with(| procname: &str | { + match CString::new(procname) { // Allocates and requires std + Ok(procname) => unsafe { + SDL_GL_GetProcAddress(procname.as_ptr()) as *const _ + }, + Err(_) => ptr::null(), + } +}); + +// With the feature +gl::load_with(| procname: &CStr | { + unsafe { SDL_GL_GetProcAddress(procname.as_ptr()) as *const _ } +}); +``` ## Generator types From 4b93ec65130d5f541b2bbf8f4a2420d12b605eb4 Mon Sep 17 00:00:00 2001 From: Gabriel Nigro Date: Tue, 4 Mar 2025 15:20:51 -0300 Subject: [PATCH 3/3] Replace main readme links with relative ones --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e6770124..811de428 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The following crates are contained in this repository: [![Version](https://img.shields.io/crates/v/gl.svg)](https://crates.io/crates/gl) [![License](https://img.shields.io/crates/l/gl.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/gl.svg)](https://crates.io/crates/gl) -[README](https://github.com/brendanzab/gl-rs/tree/master/gl) +[README](gl) An no_std OpenGL function pointer loader for the Rust Programming Language. @@ -27,7 +27,7 @@ gl = "0.14.0" [![Version](https://img.shields.io/crates/v/gl_generator.svg)](https://crates.io/crates/gl_generator) [![License](https://img.shields.io/crates/l/gl_generator.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/gl_generator.svg)](https://crates.io/crates/gl_generator) -[README](https://github.com/brendanzab/gl-rs/tree/master/gl_generator) +[README](gl_generator) Code generators for creating no_std bindings to the Khronos OpenGL APIs. @@ -40,7 +40,7 @@ gl_generator = "0.14.0" [![Version](https://img.shields.io/crates/v/khronos_api.svg)](https://crates.io/crates/khronos_api) [![License](https://img.shields.io/crates/l/khronos_api.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/khronos_api.svg)](https://crates.io/crates/khronos_api) -[README](https://github.com/brendanzab/gl-rs/tree/master/khronos_api) +[README](khronos_api) The Khronos XML API Registry, exposed as byte string constants. @@ -61,7 +61,7 @@ git submodule update --init [![Version](https://img.shields.io/crates/v/webgl_generator.svg)](https://crates.io/crates/webgl_generator) [![License](https://img.shields.io/crates/l/webgl_generator.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/webgl_generator.svg)](https://crates.io/crates/webgl_generator) -[README](https://github.com/brendanzab/gl-rs/tree/master/webgl_generator) +[README](webgl_generator) Code generators for creating bindings to the WebGL APIs. @@ -74,7 +74,7 @@ webgl_generator = "0.2.0" [![Version](https://img.shields.io/crates/v/webgl_stdweb.svg)](https://crates.io/crates/webgl_stdweb) [![License](https://img.shields.io/crates/l/webgl_stdweb.svg)](https://github.com/brendanzab/gl-rs/blob/master/LICENSE) [![Downloads](https://img.shields.io/crates/d/webgl_stdweb.svg)](https://crates.io/crates/webgl_stdweb) -[README](https://github.com/brendanzab/gl-rs/tree/master/webgl_stdweb) +[README](webgl_stdweb) WebGL bindings using stdweb