egui_glow/
lib.rs

1//! [`egui`] bindings for [`glow`](https://github.com/grovesNL/glow).
2//!
3//! The main type you want to look at is [`Painter`].
4//!
5//! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead.
6//!
7//! ## Feature flags
8#![cfg_attr(feature = "document-features", doc = document_features::document_features!())]
9//!
10
11#![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/// Check for OpenGL error and report it using `log::error`.
30///
31/// Only active in debug builds!
32///
33/// ``` no_run
34/// # let glow_context = todo!();
35/// use egui_glow::check_for_gl_error;
36/// check_for_gl_error!(glow_context);
37/// check_for_gl_error!(glow_context, "during painting");
38/// ```
39#[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/// Check for OpenGL error and report it using `log::error`.
54///
55/// WARNING: slow! Only use during setup!
56///
57/// ``` no_run
58/// # let glow_context = todo!();
59/// use egui_glow::check_for_gl_error_even_in_release;
60/// check_for_gl_error_even_in_release!(glow_context);
61/// check_for_gl_error_even_in_release!(glow_context, "during painting");
62/// ```
63#[macro_export]
64macro_rules! check_for_gl_error_even_in_release {
65    ($gl: expr) => {{
66        $crate::check_for_gl_error_impl($gl, file!(), line!(), "")
67    }};
68    ($gl: expr, $context: literal) => {{
69        $crate::check_for_gl_error_impl($gl, file!(), line!(), $context)
70    }};
71}
72
73#[doc(hidden)]
74pub fn check_for_gl_error_impl(gl: &glow::Context, file: &str, line: u32, context: &str) {
75    use glow::HasContext as _;
76    #[allow(unsafe_code)]
77    let error_code = unsafe { gl.get_error() };
78    if error_code != glow::NO_ERROR {
79        let error_str = match error_code {
80            glow::INVALID_ENUM => "GL_INVALID_ENUM",
81            glow::INVALID_VALUE => "GL_INVALID_VALUE",
82            glow::INVALID_OPERATION => "GL_INVALID_OPERATION",
83            glow::STACK_OVERFLOW => "GL_STACK_OVERFLOW",
84            glow::STACK_UNDERFLOW => "GL_STACK_UNDERFLOW",
85            glow::OUT_OF_MEMORY => "GL_OUT_OF_MEMORY",
86            glow::INVALID_FRAMEBUFFER_OPERATION => "GL_INVALID_FRAMEBUFFER_OPERATION",
87            glow::CONTEXT_LOST => "GL_CONTEXT_LOST",
88            0x8031 => "GL_TABLE_TOO_LARGE1",
89            0x9242 => "CONTEXT_LOST_WEBGL",
90            _ => "<unknown>",
91        };
92
93        if context.is_empty() {
94            log::error!(
95                "GL error, at {}:{}: {} (0x{:X}). Please file a bug at https://github.com/emilk/egui/issues",
96                file,
97                line,
98                error_str,
99                error_code,
100            );
101        } else {
102            log::error!(
103                "GL error, at {}:{} ({}): {} (0x{:X}). Please file a bug at https://github.com/emilk/egui/issues",
104                file,
105                line,
106                context,
107                error_str,
108                error_code,
109            );
110        }
111    }
112}