diff options
author | HampusM <hampus@hampusmat.com> | 2023-10-15 00:06:07 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-10-15 00:06:07 +0200 |
commit | da329909f93597970afd169cee28ece3bee7127b (patch) | |
tree | b8ce428d458ab5e3e699334877253b10a62c8fe2 /engine/src/renderer | |
parent | 46f27f31e425f5eba494f499bd7a6ac8f8713c2a (diff) |
feat(engine): add logging OpenGL debug messages
Diffstat (limited to 'engine/src/renderer')
-rw-r--r-- | engine/src/renderer/mod.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/engine/src/renderer/mod.rs b/engine/src/renderer/mod.rs index 4ed3c0a..cc1631f 100644 --- a/engine/src/renderer/mod.rs +++ b/engine/src/renderer/mod.rs @@ -3,6 +3,8 @@ use std::process::abort; use glfw::WindowSize; +#[cfg(feature = "debug")] +use crate::opengl::debug::{MessageSeverity, MessageSource, MessageType}; use crate::opengl::shader::Program as ShaderProgram; use crate::opengl::vertex_array::{PrimitiveKind, VertexArray}; use crate::opengl::vertex_buffer::{BufferUsage, VertexBuffer}; @@ -28,6 +30,22 @@ pub fn initialize(window: &glfw::Window) -> Result<(), Error> } }); + #[cfg(feature = "debug")] + { + use crate::opengl::debug::{ + enable_debug_output, + set_debug_message_callback, + set_debug_message_control, + MessageIdsAction, + }; + + enable_debug_output(); + + set_debug_message_callback(opengl_debug_message_cb); + + set_debug_message_control(None, None, None, &[], MessageIdsAction::Disable); + } + let window_size = window.size().map_err(Error::GetWindowSizeFailed)?; set_viewport(&Vec2 { x: 0, y: 0 }, &window_size); @@ -35,6 +53,37 @@ pub fn initialize(window: &glfw::Window) -> Result<(), Error> Ok(()) } +#[cfg(feature = "debug")] +#[tracing::instrument(skip_all)] +fn opengl_debug_message_cb( + source: MessageSource, + ty: MessageType, + id: u32, + severity: MessageSeverity, + message: &str, +) +{ + use tracing::{event, Level}; + + macro_rules! create_event { + ($level: expr) => { + event!($level, ?source, ?ty, id, ?severity, message); + }; + } + + match ty { + MessageType::Error => { + create_event!(Level::ERROR); + } + MessageType::Other => { + create_event!(Level::INFO); + } + _ => { + create_event!(Level::WARN); + } + }; +} + pub fn render<'renderable>(renderables: impl IntoIterator<Item = &'renderable Renderable>) { clear_buffers(BufferClearMask::COLOR); |