forked from mirrors/zig-glsl-view
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.2 KiB
Zig
38 lines
1.2 KiB
Zig
const c = @import("c.zig");
|
|
const std = @import("std");
|
|
const os = std.os;
|
|
const panic = std.debug.panic;
|
|
const builtin = @import("builtin");
|
|
|
|
pub const is_on = if (builtin.mode == std.builtin.Mode.ReleaseFast) c.GL_FALSE else c.GL_TRUE;
|
|
|
|
fn glDebugMessage(source: c.GLenum, typ: c.GLenum, id: c.GLuint, severity: c.GLenum, length: c.GLsizei, _message: [*c]const u8, _: ?*const anyopaque) callconv(.C) void {
|
|
switch (typ) {
|
|
c.GL_DEBUG_TYPE_ERROR, c.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR, c.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR => {},
|
|
else => return,
|
|
}
|
|
|
|
const message = _message[0..@intCast(usize, length)];
|
|
std.debug.print("GL Callback [{}] {} {} / {}: {s}\n", .{ source, typ, id, severity, message });
|
|
}
|
|
|
|
pub fn init() void {
|
|
if (is_on == c.GL_TRUE) {
|
|
c.glEnable(c.GL_DEBUG_OUTPUT);
|
|
c.glDebugMessageCallback(glDebugMessage, null);
|
|
}
|
|
}
|
|
|
|
pub fn assertNoError() void {
|
|
if (is_on == c.GL_TRUE) {
|
|
var err = c.glGetError();
|
|
while (err != c.GL_NO_ERROR) : (err = c.glGetError()) {
|
|
panic("GL error: {}\n", .{err});
|
|
} else {
|
|
return;
|
|
}
|
|
|
|
panic("GL Errors encountered.\n", .{err});
|
|
}
|
|
}
|