1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Use tracing crate for logging (#1192)

* egui_web: use tracing crate
* egui_glow: use tracing crate
* Log at the debug level
* egui_demo_app: enable tracing to log to stdout
* Use tracing in egui-winit
* Add opt-in tracing support to egui
This commit is contained in:
Emil Ernerfeldt
2022-02-01 12:27:39 +01:00
committed by GitHub
parent 1f03f53dc0
commit c6ac1827f6
28 changed files with 194 additions and 107 deletions

View File

@@ -32,6 +32,7 @@ epi = { version = "0.16.0", path = "../epi", optional = true }
bytemuck = "1.7"
glow = "0.11"
memoffset = "0.6"
tracing = "0.1"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
egui-winit = { version = "0.16.0", path = "../egui-winit", default-features = false, features = ["epi"], optional = true }

View File

@@ -60,8 +60,7 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
)));
let mut painter = crate::Painter::new(&gl, None, "")
.map_err(|error| eprintln!("some OpenGL error occurred {}\n", error))
.unwrap();
.unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error));
let mut integration = egui_winit::epi::EpiIntegration::new(
"egui_glow",
painter.max_texture_side(),

View File

@@ -124,10 +124,7 @@ impl EguiGlow {
pub fn new(window: &winit::window::Window, gl: &glow::Context) -> Self {
let painter = crate::Painter::new(gl, None, "")
.map_err(|error| {
crate::misc_util::glow_print_error(format!(
"error occurred in initializing painter:\n{}",
error
));
tracing::error!("error occurred in initializing painter:\n{}", error);
})
.unwrap();

View File

@@ -5,29 +5,15 @@ use std::option::Option::Some;
pub fn check_for_gl_error(gl: &glow::Context, context: &str) {
let error_code = unsafe { gl.get_error() };
if error_code != glow::NO_ERROR {
glow_print_error(format!(
tracing::error!(
"GL error, at: '{}', code: {} (0x{:X})",
context, error_code, error_code
));
context,
error_code,
error_code
);
}
}
pub(crate) fn glow_print(s: impl std::fmt::Display) {
#[cfg(target_arch = "wasm32")]
web_sys::console::log_1(&format!("egui_glow: {}", s).into());
#[cfg(not(target_arch = "wasm32"))]
eprintln!("egui_glow: {}", s);
}
pub(crate) fn glow_print_error(s: impl std::fmt::Display) {
#[cfg(target_arch = "wasm32")]
web_sys::console::error_1(&format!("egui_glow: {}", s).into());
#[cfg(not(target_arch = "wasm32"))]
eprintln!("egui_glow ERROR: {}", s);
}
pub(crate) unsafe fn compile_shader(
gl: &glow::Context,
shader_type: u32,
@@ -130,7 +116,7 @@ pub(crate) fn supports_vao(gl: &glow::Context) -> bool {
const OPENGL_ES_PREFIX: &str = "OpenGL ES ";
let version_string = unsafe { gl.get_parameter_string(glow::VERSION) };
glow_print(format!("GL version: {:?}.", version_string));
tracing::debug!("GL version: {:?}.", version_string);
// Examples:
// * "WebGL 2.0 (OpenGL ES 3.0 Chromium)"

View File

@@ -9,7 +9,7 @@ use egui::{
use glow::HasContext;
use memoffset::offset_of;
use crate::misc_util::{check_for_gl_error, compile_shader, glow_print, link_program};
use crate::misc_util::{check_for_gl_error, compile_shader, link_program};
use crate::post_process::PostProcess;
use crate::shader_version::ShaderVersion;
use crate::vao_emulate;
@@ -98,7 +98,7 @@ impl Painter {
let shader_version = ShaderVersion::get(gl);
let is_webgl_1 = shader_version == ShaderVersion::Es100;
let header = shader_version.version();
glow_print(format!("Shader header: {:?}.", header));
tracing::debug!("Shader header: {:?}.", header);
let srgb_support = gl.supported_extensions().contains("EXT_sRGB");
let (post_process, srgb_support_define) = match (shader_version, srgb_support) {
@@ -106,7 +106,7 @@ impl Painter {
(ShaderVersion::Es300, _) | (ShaderVersion::Es100, true) => unsafe {
// Add sRGB support marker for fragment shader
if let Some([width, height]) = pp_fb_extent {
glow_print("WebGL with sRGB enabled. Turning on post processing for linear framebuffer blending.");
tracing::debug!("WebGL with sRGB enabled. Turning on post processing for linear framebuffer blending.");
// install post process to correct sRGB color:
(
Some(PostProcess::new(
@@ -120,7 +120,7 @@ impl Painter {
"#define SRGB_SUPPORTED",
)
} else {
glow_print("WebGL or OpenGL ES detected but PostProcess disabled because dimension is None");
tracing::debug!("WebGL or OpenGL ES detected but PostProcess disabled because dimension is None");
(None, "")
}
},
@@ -582,7 +582,7 @@ pub fn clear(gl: &glow::Context, dimension: [u32; 2], clear_color: egui::Rgba) {
impl Drop for Painter {
fn drop(&mut self) {
if !self.destroyed {
eprintln!(
tracing::warn!(
"You forgot to call destroy() on the egui glow painter. Resources will leak!"
);
}

View File

@@ -1,5 +1,5 @@
#![allow(unsafe_code)]
use crate::misc_util::glow_print;
use glow::HasContext;
use std::convert::TryInto;
@@ -17,10 +17,11 @@ impl ShaderVersion {
let shading_lang_string =
unsafe { gl.get_parameter_string(glow::SHADING_LANGUAGE_VERSION) };
let shader_version = Self::parse(&shading_lang_string);
glow_print(format!(
tracing::debug!(
"Shader version: {:?} ({:?}).",
shader_version, shading_lang_string
));
shader_version,
shading_lang_string
);
shader_version
}