summaryrefslogtreecommitdiff
path: root/glw/debug.ha
diff options
context:
space:
mode:
authorLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:11:21 +0200
committerLassi Pulkkinen <lassi@pulk.fi>2024-10-31 03:51:35 +0200
commitae44478b30d890fe0fb04022f44d474dcdcc3f9d (patch)
tree5f462459ae4b47d22114eed717d1382d08cf4dfe /glw/debug.ha
Initial commit (import old repo)HEADmain
Diffstat (limited to 'glw/debug.ha')
-rw-r--r--glw/debug.ha34
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);
+ };
+};