Created
October 26, 2012 07:35
-
-
Save brendanzab/3957434 to your computer and use it in GitHub Desktop.
check_gl Rust macro
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // example usage: | |
| // | |
| // check_gl!(glVertexAttribPointer(attrib, 4, GL_FLOAT, GL_FALSE as GLboolean, 0, null())); | |
| // | |
| // if there is an error it outputs: `OpenGL <<opengl error code>>: <<function identifier>>(<<function arguments>>)` | |
| // | |
| #[cfg(check_gl)] | |
| macro_rules! check_gl ( | |
| ($fun:ident ($($arg:expr),*)) => ( | |
| util::check_gl_callback( | |
| move $fun ( $($arg),* ), stringify!($fun ( $($arg),* ) ) | |
| ) | |
| ) | |
| ) | |
| // Not currently possible - this is a skeleton macro that when expanded should not impact performance at runtime | |
| // #[cfg(!check_gl)] | |
| // macro_rules! check_gl ( | |
| // ($fun:ident ($($arg:expr),*)) => ( $fun ( $($arg),* ) ) | |
| // ) | |
| fn check_gl_callback<T>(v: T, fn_string: &str) -> T { | |
| let err = glGetError(); | |
| if err != GL_NO_ERROR { | |
| io::println(fmt!("OpenGL %s: %s", gl_error_string(err), connect(words(fn_string), " "))); | |
| } | |
| return move v; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment