Created
December 8, 2017 00:12
-
-
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.
This file contains 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
#[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