macro_rules! checkerr {
($gl:expr) => {
$crate::error::check_err_impl($gl, file!(), line!());
};
}
pub(crate) use checkerr;
use crate::opengl::Gl;
#[cfg(debug_assertions)]
#[inline]
pub(crate) fn check_err_impl(gl: &Gl, file: &str, line: u32) {
let mut err_count: usize = 0;
loop {
let err = unsafe { gl.GetError() };
if err == crate::opengl::NO_ERROR {
break;
}
if err_count > 1000 {
panic!("More than 1000 OpenGL error read, quitting");
}
log::error!(
"OpenGL error @ {}:{}: {:#X} {}",
file,
line,
err,
gl_err_to_str(err)
);
err_count += 1;
}
}
#[cfg(not(debug_assertions))]
#[inline(always)]
pub(crate) fn check_err_impl(_gl: &Gl, _file: &str, _line: u32) {}
pub(crate) const fn gl_err_to_str(err: crate::opengl::types::GLenum) -> &'static str {
match err {
crate::opengl::INVALID_ENUM => "Invalid Enum",
crate::opengl::INVALID_VALUE => "Invalid Value",
crate::opengl::INVALID_OPERATION => "Invalid Operation",
crate::opengl::OUT_OF_MEMORY => "Out Of Memory",
crate::opengl::INVALID_FRAMEBUFFER_OPERATION => "Invalid Framebuffer Operation",
_ => "(unknown)",
}
}