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); }; };