1#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
9#![allow(clippy::float_cmp)]
12#![allow(clippy::manual_range_contains)]
13#![allow(clippy::undocumented_unsafe_blocks)]
14
15pub mod painter;
16pub use glow;
17pub use painter::{CallbackFn, Painter, PainterError};
18mod misc_util;
19mod shader_version;
20mod vao;
21
22pub use shader_version::ShaderVersion;
23
24#[cfg(feature = "winit")]
25pub mod winit;
26#[cfg(feature = "winit")]
27pub use winit::*;
28
29#[macro_export]
40macro_rules! check_for_gl_error {
41 ($gl: expr) => {{
42 if cfg!(debug_assertions) {
43 $crate::check_for_gl_error_impl($gl, file!(), line!(), "")
44 }
45 }};
46 ($gl: expr, $context: literal) => {{
47 if cfg!(debug_assertions) {
48 $crate::check_for_gl_error_impl($gl, file!(), line!(), $context)
49 }
50 }};
51}
52
53#[macro_export]
64macro_rules! check_for_gl_error_even_in_release {
65 ($gl: expr) => {{ $crate::check_for_gl_error_impl($gl, file!(), line!(), "") }};
66 ($gl: expr, $context: literal) => {{ $crate::check_for_gl_error_impl($gl, file!(), line!(), $context) }};
67}
68
69#[doc(hidden)]
70pub fn check_for_gl_error_impl(gl: &glow::Context, file: &str, line: u32, context: &str) {
71 use glow::HasContext as _;
72 #[expect(unsafe_code)]
73 let error_code = unsafe { gl.get_error() };
74 if error_code != glow::NO_ERROR {
75 let error_str = match error_code {
76 glow::INVALID_ENUM => "GL_INVALID_ENUM",
77 glow::INVALID_VALUE => "GL_INVALID_VALUE",
78 glow::INVALID_OPERATION => "GL_INVALID_OPERATION",
79 glow::STACK_OVERFLOW => "GL_STACK_OVERFLOW",
80 glow::STACK_UNDERFLOW => "GL_STACK_UNDERFLOW",
81 glow::OUT_OF_MEMORY => "GL_OUT_OF_MEMORY",
82 glow::INVALID_FRAMEBUFFER_OPERATION => "GL_INVALID_FRAMEBUFFER_OPERATION",
83 glow::CONTEXT_LOST => "GL_CONTEXT_LOST",
84 0x8031 => "GL_TABLE_TOO_LARGE1",
85 0x9242 => "CONTEXT_LOST_WEBGL",
86 _ => "<unknown>",
87 };
88
89 if context.is_empty() {
90 log::error!(
91 "GL error, at {file}:{line}: {error_str} (0x{error_code:X}). Please file a bug at https://github.com/emilk/egui/issues"
92 );
93 } else {
94 log::error!(
95 "GL error, at {file}:{line} ({context}): {error_str} (0x{error_code:X}). Please file a bug at https://github.com/emilk/egui/issues"
96 );
97 }
98 }
99}