opengl: support extension iteration, list in debug mode

This commit is contained in:
Mitchell Hashimoto
2022-08-04 11:13:56 -07:00
parent e163e4962b
commit bb0b95732e
3 changed files with 39 additions and 0 deletions

View File

@ -124,6 +124,7 @@ const Cursor = struct {
); );
} }
/// Stop the timer. This is idempotent.
pub fn stopTimer(self: Cursor) !void { pub fn stopTimer(self: Cursor) !void {
try self.timer.stop(); try self.timer.stop();
} }
@ -166,6 +167,12 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
gl.glad.versionMajor(version), gl.glad.versionMajor(version),
gl.glad.versionMinor(version), gl.glad.versionMinor(version),
}); });
if (builtin.mode == .Debug) {
var ext_iter = try gl.ext.iterator();
while (try ext_iter.next()) |ext| {
log.debug("OpenGL extension available name={s}", .{ext});
}
}
// Culling, probably not necessary. We have to change the winding // Culling, probably not necessary. We have to change the winding
// order since our 0,0 is top-left. // order since our 0,0 is top-left.

View File

@ -15,6 +15,7 @@ pub const c = @import("opengl/c.zig");
pub const glad = @import("opengl/glad.zig"); pub const glad = @import("opengl/glad.zig");
pub usingnamespace @import("opengl/draw.zig"); pub usingnamespace @import("opengl/draw.zig");
pub const ext = @import("opengl/extensions.zig");
pub const Buffer = @import("opengl/Buffer.zig"); pub const Buffer = @import("opengl/Buffer.zig");
pub const Program = @import("opengl/Program.zig"); pub const Program = @import("opengl/Program.zig");
pub const Shader = @import("opengl/Shader.zig"); pub const Shader = @import("opengl/Shader.zig");

31
src/opengl/extensions.zig Normal file
View File

@ -0,0 +1,31 @@
const std = @import("std");
const c = @import("c.zig");
const errors = @import("errors.zig");
/// Returns the number of extensions.
pub fn len() !u32 {
var n: c.GLint = undefined;
c.glGetIntegerv(c.GL_NUM_EXTENSIONS, &n);
try errors.getError();
return @intCast(u32, n);
}
/// Returns an iterator for the extensions.
pub fn iterator() !Iterator {
return Iterator{ .len = try len() };
}
/// Iterator for the available extensions.
pub const Iterator = struct {
/// The total number of extensions.
len: c.GLuint = 0,
i: c.GLuint = 0,
pub fn next(self: *Iterator) !?[]const u8 {
if (self.i >= self.len) return null;
const res = c.glGetStringi(c.GL_EXTENSIONS, self.i);
try errors.getError();
self.i += 1;
return std.mem.sliceTo(res, 0);
}
};