Skip to content

Instantly share code, notes, and snippets.

@DCubix
Created December 8, 2017 00:12
Show Gist options
  • Save DCubix/e6e1e711ad9a877ff3f668174fd78543 to your computer and use it in GitHub Desktop.
Save DCubix/e6e1e711ad9a877ff3f668174fd78543 to your computer and use it in GitHub Desktop.
Macro to call an OpenGL function, check errors and optionally return a value.
#[macro_export]
macro_rules! GL {
($fun:ident ( $($arg:expr),*)) => {{
unsafe {
let result = ::gl::$fun( $($arg),* );
let err = ::gl::GetError();
if err != ::gl::NO_ERROR {
let err_str = match err {
::gl::INVALID_OPERATION => "Invalid Operation",
::gl::INVALID_ENUM => "Invalid Enum",
::gl::INVALID_VALUE => "Invalid Value",
::gl::OUT_OF_MEMORY => "Out Of Memory",
::gl::INVALID_FRAMEBUFFER_OPERATION => "Invalid Framebuffer Operation",
_ => "Unknown Error"
};
panic!("OpenGL Error ({}): {}\n\tFile:{}",
err, err_str, line!()
);
}
result
}
}};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment