Skip to content

Commit

Permalink
Remove calls to gl.getError in release builds (#1583)
Browse files Browse the repository at this point in the history
This slows down the web version a lot, especially on some browsers

Publish new web demo
  • Loading branch information
emilk committed May 5, 2022
1 parent cb2298e commit e82b87c
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
Binary file modified docs/egui_demo_app_bg.wasm
Binary file not shown.
1 change: 1 addition & 0 deletions eframe/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C


## Unreleased
* `egui_glow`: remove calls to `gl.get_error` in release builds to speed up rendering ([#1583](https://github.com/emilk/egui/pull/1583)).


## 0.18.0 - 2022-04-30
Expand Down
1 change: 1 addition & 0 deletions egui_glow/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to the `egui_glow` integration will be noted in this file.


## Unreleased
* Remove calls to `gl.get_error` in release builds to speed up rendering ([#1583](https://github.com/emilk/egui/pull/1583)).


## 0.18.0 - 2022-04-30
Expand Down
26 changes: 26 additions & 0 deletions egui_glow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub use winit::*;

/// Check for OpenGL error and report it using `tracing::error`.
///
/// Only active in debug builds!
///
/// ``` no_run
/// # let glow_context = todo!();
/// use egui_glow::check_for_gl_error;
Expand All @@ -30,6 +32,30 @@ pub use winit::*;
/// ```
#[macro_export]
macro_rules! check_for_gl_error {
($gl: expr) => {{
if cfg!(debug_assertions) {
$crate::check_for_gl_error_impl($gl, file!(), line!(), "")
}
}};
($gl: expr, $context: literal) => {{
if cfg!(debug_assertions) {
$crate::check_for_gl_error_impl($gl, file!(), line!(), $context)
}
}};
}

/// Check for OpenGL error and report it using `tracing::error`.
///
/// WARNING: slow! Only use during setup!
///
/// ``` no_run
/// # let glow_context = todo!();
/// use egui_glow::check_for_gl_error_even_in_release;
/// check_for_gl_error_even_in_release!(glow_context);
/// check_for_gl_error_even_in_release!(glow_context, "during painting");
/// ```
#[macro_export]
macro_rules! check_for_gl_error_even_in_release {
($gl: expr) => {{
$crate::check_for_gl_error_impl($gl, file!(), line!(), "")
}};
Expand Down
4 changes: 2 additions & 2 deletions egui_glow/src/painter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Painter {
shader_prefix: &str,
) -> Result<Painter, String> {
crate::profile_function!();
check_for_gl_error!(&gl, "before Painter::new");
crate::check_for_gl_error_even_in_release!(&gl, "before Painter::new");

let max_texture_side = unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) } as usize;

Expand Down Expand Up @@ -204,7 +204,7 @@ impl Painter {

let element_array_buffer = gl.create_buffer()?;

check_for_gl_error!(&gl, "after Painter::new");
crate::check_for_gl_error_even_in_release!(&gl, "after Painter::new");

Ok(Painter {
gl,
Expand Down
4 changes: 2 additions & 2 deletions egui_glow/src/post_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl PostProcess {
glow::UNSIGNED_BYTE,
None,
);
check_for_gl_error!(&gl, "post process texture initialization");
crate::check_for_gl_error_even_in_release!(&gl, "post process texture initialization");

gl.framebuffer_texture_2d(
glow::FRAMEBUFFER,
Expand Down Expand Up @@ -160,7 +160,7 @@ impl PostProcess {
gl.buffer_data_u8_slice(glow::ELEMENT_ARRAY_BUFFER, &indices, glow::STATIC_DRAW);

gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, None);
check_for_gl_error!(&gl, "post process initialization");
crate::check_for_gl_error_even_in_release!(&gl, "post process initialization");

Ok(PostProcess {
gl,
Expand Down
5 changes: 5 additions & 0 deletions sh/build_demo_web.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@ while test $# -gt 0; do
echo " --open: open the result in a browser"
exit 0
;;

# Skip running `wasm-opt`.
# --fast also preserves debug symbols, which is great for profiling.
--fast)
shift
FAST=true
;;

--open)
shift
OPEN=true
;;

*)
break
;;
Expand Down

0 comments on commit e82b87c

Please sign in to comment.