1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use gl;
pub fn gl_get_error() -> Option<gl::types::GLenum> {
let error_code = unsafe { gl::GetError() };
match error_code {
gl::NO_ERROR => None,
_ => Some(error_code),
}
}
pub fn gl_get_error_name(error_code: &gl::types::GLenum) -> String {
match *error_code {
gl::INVALID_ENUM => "INVALID_ENUM",
gl::INVALID_VALUE => "INVALID_VALUE",
gl::INVALID_OPERATION => "INVALID_OPERATION",
gl::INVALID_FRAMEBUFFER_OPERATION => "INVALID_FRAMEBUFFER_OPERATION",
gl::OUT_OF_MEMORY => "OUT_OF_MEMORY",
gl::STACK_UNDERFLOW => "STACK_UNDERFLOW",
gl::STACK_OVERFLOW => "STACK_OVERFLOW",
_ => "Unknown Error",
}
.to_string()
}
pub fn gl_get_errors() -> Vec<u32> {
let mut errors = Vec::<u32>::new();
while let Some(error) = gl_get_error() {
errors.push(error);
}
errors
}
pub fn gl_clear_errors() {
while let Some(_error) = gl_get_error() {}
}
#[macro_export]
macro_rules! gl_call {
($gl_fn:expr) => {{
let result = unsafe { $gl_fn };
if cfg!(debug_assertions) {
let errors = $crate::gl_call::gl_get_errors();
if !errors.is_empty() {
panic!(
"OpenGL Errors: {}",
errors
.iter()
.map($crate::gl_call::gl_get_error_name)
.collect::<Vec<_>>()
.join(", ")
);
}
}
result
}};
}