diff options
Diffstat (limited to 'glw/debug.ha')
-rw-r--r-- | glw/debug.ha | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/glw/debug.ha b/glw/debug.ha new file mode 100644 index 0000000..2ffe3c4 --- /dev/null +++ b/glw/debug.ha @@ -0,0 +1,34 @@ +use strings; +use types::c; +use trace; + +use gl::*; + +fn debug_callback( + source: gl_enum, + type_: gl_enum, + id: uint, + severity: gl_enum, + length: i32, + message: nullable *const c::char, + user_data: nullable *opaque, +) void = { + // (2024 note): I'm painfully aware of the data race present here: + // The GL driver can call this from another thread, and the stdlib has + // some non-thread-safe stuff in it that we use, in particular strconv. + // I've seen it happen at times, but it's pretty rare. + const message = (message: *const [*]u8)[..length]; + const message = strings::fromutf8(message)!; + const message = strings::trimsuffix(message, "\n"); + trace::debug(&trace::root, "gl: {}", message); +}; + +export fn init_debug_logging() void = { + let ctxflags = 0i32; + glGetIntegerv(GL_CONTEXT_FLAGS, &ctxflags); + + if (ctxflags & GL_CONTEXT_FLAG_DEBUG_BIT: i32 != 0) { + trace::info(&trace::root, "opengl debugging is enabled"); + glDebugMessageCallback(&debug_callback, null); + }; +}; |