/ egui_glow / src / lib.rs
lib.rs
 1  //! [`egui`] bindings for [`glow`](https://github.com/grovesNL/glow).
 2  //!
 3  //! The main type you want to use is [`EguiGlow`].
 4  //!
 5  //! This library is an [`epi`] backend.
 6  //! If you are writing an app, you may want to look at [`eframe`](https://docs.rs/eframe) instead.
 7  
 8  #![allow(clippy::float_cmp)]
 9  #![allow(clippy::manual_range_contains)]
10  
11  pub mod painter;
12  pub use glow;
13  pub use painter::Painter;
14  mod misc_util;
15  mod post_process;
16  mod shader_version;
17  mod vao;
18  
19  #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
20  pub mod winit;
21  #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
22  pub use winit::*;
23  
24  #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
25  mod epi_backend;
26  
27  #[cfg(all(not(target_arch = "wasm32"), feature = "winit"))]
28  pub use epi_backend::{run, NativeOptions};
29  
30  /// Check for OpenGL error and report it using `tracing::error`.
31  ///
32  /// ``` no_run
33  /// # let glow_context = todo!();
34  /// use egui_glow::check_for_gl_error;
35  /// check_for_gl_error!(glow_context);
36  /// check_for_gl_error!(glow_context, "during painting");
37  /// ```
38  #[macro_export]
39  macro_rules! check_for_gl_error {
40      ($gl: expr) => {{
41          $crate::check_for_gl_error_impl($gl, file!(), line!(), "")
42      }};
43      ($gl: expr, $context: literal) => {{
44          $crate::check_for_gl_error_impl($gl, file!(), line!(), $context)
45      }};
46  }
47  
48  #[doc(hidden)]
49  pub fn check_for_gl_error_impl(gl: &glow::Context, file: &str, line: u32, context: &str) {
50      use glow::HasContext as _;
51      #[allow(unsafe_code)]
52      let error_code = unsafe { gl.get_error() };
53      if error_code != glow::NO_ERROR {
54          let error_str = match error_code {
55              glow::INVALID_ENUM => "GL_INVALID_ENUM",
56              glow::INVALID_VALUE => "GL_INVALID_VALUE",
57              glow::INVALID_OPERATION => "GL_INVALID_OPERATION",
58              glow::STACK_OVERFLOW => "GL_STACK_OVERFLOW",
59              glow::STACK_UNDERFLOW => "GL_STACK_UNDERFLOW",
60              glow::OUT_OF_MEMORY => "GL_OUT_OF_MEMORY",
61              glow::INVALID_FRAMEBUFFER_OPERATION => "GL_INVALID_FRAMEBUFFER_OPERATION",
62              glow::CONTEXT_LOST => "GL_CONTEXT_LOST",
63              0x8031 => "GL_TABLE_TOO_LARGE1",
64              0x9242 => "CONTEXT_LOST_WEBGL",
65              _ => "<unknown>",
66          };
67  
68          if context.is_empty() {
69              tracing::error!(
70                  "GL error, at {}:{}: {} (0x{:X}). Please file a bug at https://github.com/emilk/egui/issues",
71                  file,
72                  line,
73                  error_str,
74                  error_code,
75              );
76          } else {
77              tracing::error!(
78                  "GL error, at {}:{} ({}): {} (0x{:X}). Please file a bug at https://github.com/emilk/egui/issues",
79                  file,
80                  line,
81                  context,
82                  error_str,
83                  error_code,
84              );
85          }
86      }
87  }