Skip to content

Instantly share code, notes, and snippets.

@brendanzab
Created October 26, 2012 07:35
Show Gist options
  • Select an option

  • Save brendanzab/3957434 to your computer and use it in GitHub Desktop.

Select an option

Save brendanzab/3957434 to your computer and use it in GitHub Desktop.
check_gl Rust macro
// 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