aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib.rs5
-rw-r--r--src/repeat.rs30
2 files changed, 35 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 653935a..1003c7a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -15,6 +15,7 @@ mod str;
mod token_stream;
const OPENGL_CMD_NAME_REPLACE: &str = "gl_command_name";
+const OPENGL_CMD_NAME_NOPREFIX_REPLACE: &str = "gl_command_name_noprefix";
const OPENGL_CMD_RET_TYPE_REPLACE: &str = "gl_command_ret_type";
const OPENGL_CMD_ARGS_REPLACE: &str = "gl_command_args";
const OPENGL_CMD_ARG_NAMES_REPLACE: &str = "gl_command_arg_names";
@@ -32,6 +33,10 @@ static OPENGL_REGISTRY: Lazy<Registry> = Lazy::new(|| Registry::retrieve().unwra
/// **`gl_command_name`**<br>
/// Will be replaced by the full command name. For example, `glViewport`.
///
+/// **`gl_command_name_noprefix`**<br>
+/// Will be replaced by the command name without the "gl" prefix. For example,
+/// `Viewport`.
+///
/// **`gl_command_ret_type`**<br>
/// Will be replaced by the command return type. For example, `GLuint`.
///
diff --git a/src/repeat.rs b/src/repeat.rs
index 668fefb..594d23e 100644
--- a/src/repeat.rs
+++ b/src/repeat.rs
@@ -10,6 +10,7 @@ use crate::{
OPENGL_CMD_ARGS_REPLACE,
OPENGL_CMD_ARG_NAMES_REPLACE,
OPENGL_CMD_ARG_TYPES_REPLACE,
+ OPENGL_CMD_NAME_NOPREFIX_REPLACE,
OPENGL_CMD_NAME_REPLACE,
OPENGL_CMD_RET_TYPE_REPLACE,
};
@@ -31,6 +32,19 @@ pub fn for_each_opengl_command_impl(
)),
);
+ let cmd_prototype = gl_command.prototype();
+
+ let stream = stream.replace_ident(
+ &Ident::new(OPENGL_CMD_NAME_NOPREFIX_REPLACE, Span::call_site()),
+ &TokenTree::Ident(Ident::new(
+ cmd_prototype
+ .name()
+ .strip_prefix("gl")
+ .unwrap_or_else(|| cmd_prototype.name()),
+ Span::call_site(),
+ )),
+ );
+
let return_type = gl_command.prototype().return_type();
let stream = stream.replace_ident(
@@ -197,5 +211,21 @@ mod tests
}
.to_string(),
);
+
+ assert_eq!(
+ for_each_opengl_command_impl(
+ &quote! {
+ fn #ht gl_command_name_noprefix(#ht gl_command_args) -> #ht gl_command_ret_type {}
+ },
+ &registry,
+ )
+ .to_string(),
+ quote! {
+ fn BindBuffer() -> std::ffi::c_void {}
+ fn ActiveTexture(abc: GLuint, xyz: GLshort) -> std::ffi::c_void {}
+ fn DrawArrays(foo: GLubyte) -> GLint {}
+ }
+ .to_string(),
+ );
}
}