From aa38f7ad83e809bbf3b1aa7a014fa65692f66275 Mon Sep 17 00:00:00 2001 From: David Herberth Date: Sun, 22 Aug 2021 16:51:55 +0200 Subject: [PATCH] rust: strips spec prefix from enumerations gh: #336 --- example/rust/gl-glfw-mx/src/main.rs | 2 +- example/rust/gl-glfw/src/main.rs | 2 +- glad/generator/rust/templates/impl.rs | 2 +- glad/generator/rust/templates/types/glx.rs | 8 ++++---- test/rust/compile/gl/default/003/Cargo.toml | 10 ++++++++++ test/rust/compile/gl/default/003/test.rs | 16 ++++++++++++++++ test/rust/run/gl/default/001/test.rs | 2 +- 7 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 test/rust/compile/gl/default/003/Cargo.toml create mode 100644 test/rust/compile/gl/default/003/test.rs diff --git a/example/rust/gl-glfw-mx/src/main.rs b/example/rust/gl-glfw-mx/src/main.rs index 3f4341e2..53294fd9 100644 --- a/example/rust/gl-glfw-mx/src/main.rs +++ b/example/rust/gl-glfw-mx/src/main.rs @@ -48,7 +48,7 @@ fn draw(window: &mut Window) { window.source.make_current(); unsafe { window.gl.ClearColor(0.7, 0.9, 0.1, 1.0); - window.gl.Clear(gl::GL_COLOR_BUFFER_BIT); + window.gl.Clear(gl::COLOR_BUFFER_BIT); } window.source.swap_buffers(); } diff --git a/example/rust/gl-glfw/src/main.rs b/example/rust/gl-glfw/src/main.rs index e3edcfdf..c37a279a 100644 --- a/example/rust/gl-glfw/src/main.rs +++ b/example/rust/gl-glfw/src/main.rs @@ -23,7 +23,7 @@ fn main() { unsafe { gl::ClearColor(0.7, 0.9, 0.1, 1.0); - gl::Clear(gl::GL_COLOR_BUFFER_BIT); + gl::Clear(gl::COLOR_BUFFER_BIT); } window.swap_buffers(); diff --git a/glad/generator/rust/templates/impl.rs b/glad/generator/rust/templates/impl.rs index 82ecf523..771eaab4 100644 --- a/glad/generator/rust/templates/impl.rs +++ b/glad/generator/rust/templates/impl.rs @@ -59,7 +59,7 @@ pub mod enumerations { use super::types::*; {% for enum in feature_set.enums %} - pub const {{ enum.name }}: {{ enum|enum_type }} = {{ enum|enum_value }}; + pub const {{ enum.name|no_prefix }}: {{ enum|enum_type }} = {{ enum|enum_value }}; {% endfor %} } diff --git a/glad/generator/rust/templates/types/glx.rs b/glad/generator/rust/templates/types/glx.rs index af5b300b..f2d08e7e 100644 --- a/glad/generator/rust/templates/types/glx.rs +++ b/glad/generator/rust/templates/types/glx.rs @@ -99,14 +99,14 @@ pub struct GLXBufferClobberEventSGIX { #[repr(C)] #[derive(Copy, Clone)] pub struct GLXHyperpipeNetworkSGIX { - pub pipeName: [std::os::raw::c_char; super::enumerations::GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], + pub pipeName: [std::os::raw::c_char; super::enumerations::HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], pub networkId: std::os::raw::c_int, } #[repr(C)] #[derive(Copy, Clone)] pub struct GLXHyperpipeConfigSGIX { - pub pipeName: [std::os::raw::c_char; super::enumerations::GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], + pub pipeName: [std::os::raw::c_char; super::enumerations::HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], pub channel: std::os::raw::c_int, pub participationType: std::os::raw::c_uint, pub timeSlice: std::os::raw::c_int, @@ -115,7 +115,7 @@ pub struct GLXHyperpipeConfigSGIX { #[repr(C)] #[derive(Copy, Clone)] pub struct GLXPipeRect { - pub pipeName: [std::os::raw::c_char; super::enumerations::GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], + pub pipeName: [std::os::raw::c_char; super::enumerations::HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], pub srcXOrigin: std::os::raw::c_int, pub srcYOrigin: std::os::raw::c_int, pub srcWidth: std::os::raw::c_int, @@ -129,7 +129,7 @@ pub struct GLXPipeRect { #[repr(C)] #[derive(Copy, Clone)] pub struct GLXPipeRectLimits { - pub pipeName: [std::os::raw::c_char; super::enumerations::GLX_HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], + pub pipeName: [std::os::raw::c_char; super::enumerations::HYPERPIPE_PIPE_NAME_LENGTH_SGIX as usize], pub XOrigin: std::os::raw::c_int, pub YOrigin: std::os::raw::c_int, pub maxHeight: std::os::raw::c_int, diff --git a/test/rust/compile/gl/default/003/Cargo.toml b/test/rust/compile/gl/default/003/Cargo.toml new file mode 100644 index 00000000..a2d023e0 --- /dev/null +++ b/test/rust/compile/gl/default/003/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "compile-gl-default-003" +version = "0.1.0" + +[[bin]] +path = "test.rs" +name = "test" + +[dependencies] +glad-gl = { path = "./glad-gl/" } diff --git a/test/rust/compile/gl/default/003/test.rs b/test/rust/compile/gl/default/003/test.rs new file mode 100644 index 00000000..b1701ca1 --- /dev/null +++ b/test/rust/compile/gl/default/003/test.rs @@ -0,0 +1,16 @@ +#![deny(warnings)] +/** + * Enums / Constants should not be prefixed. + * + * GLAD: $GLAD --out-path=$tmp --api="gl:core=" rust + * COMPILE: cp -r $test_dir/. $tmp && cd $tmp && cargo build + * RUN: cargo run + */ +extern crate glad_gl; +use glad_gl::gl; + +#[allow(path_statements)] +fn main() { + gl::_1PASS_EXT; + gl::ALPHA; +} diff --git a/test/rust/run/gl/default/001/test.rs b/test/rust/run/gl/default/001/test.rs index 6bb0f5b8..f8f2f1be 100644 --- a/test/rust/run/gl/default/001/test.rs +++ b/test/rust/run/gl/default/001/test.rs @@ -29,7 +29,7 @@ fn main() { unsafe { gl::Viewport(0, 0, 300, 300); gl::ClearColor(0.7, 0.9, 0.1, 1.0); - gl::Clear(gl::GL_COLOR_BUFFER_BIT); + gl::Clear(gl::COLOR_BUFFER_BIT); } window.swap_buffers();