mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 07:46:12 +03:00
opengl: glad helpers
This commit is contained in:
12
src/App.zig
12
src/App.zig
@ -34,16 +34,10 @@ pub fn init(alloc: std.mem.Allocator) !App {
|
||||
try glfw.swapInterval(1);
|
||||
|
||||
// Load OpenGL bindings
|
||||
const version = gl.c.gladLoadGL(@ptrCast(
|
||||
fn ([*c]const u8) callconv(.C) ?fn () callconv(.C) void,
|
||||
glfw.getProcAddress,
|
||||
));
|
||||
if (version == 0) {
|
||||
return error.OpenGLInitFailed;
|
||||
}
|
||||
const version = try gl.glad.load(glfw.getProcAddress);
|
||||
log.info("loaded OpenGL {}.{}", .{
|
||||
gl.c.GLAD_VERSION_MAJOR(@intCast(c_uint, version)),
|
||||
gl.c.GLAD_VERSION_MINOR(@intCast(c_uint, version)),
|
||||
gl.glad.versionMajor(version),
|
||||
gl.glad.versionMinor(version),
|
||||
});
|
||||
|
||||
// Blending for text
|
||||
|
@ -12,9 +12,11 @@
|
||||
//! comptime help. I'm deferring this until later but have some fun ideas.
|
||||
|
||||
pub const c = @import("opengl/c.zig");
|
||||
pub const glad = @import("opengl/glad.zig");
|
||||
pub usingnamespace @import("opengl/draw.zig");
|
||||
|
||||
pub const Buffer = @import("opengl/Buffer.zig");
|
||||
pub const Program = @import("opengl/Program.zig");
|
||||
pub const Shader = @import("opengl/Shader.zig");
|
||||
pub const Texture = @import("opengl/Texture.zig");
|
||||
pub const VertexArray = @import("opengl/VertexArray.zig");
|
||||
pub usingnamespace @import("opengl/draw.zig");
|
||||
|
29
src/opengl/glad.zig
Normal file
29
src/opengl/glad.zig
Normal file
@ -0,0 +1,29 @@
|
||||
const c = @import("c.zig");
|
||||
|
||||
/// Initialize Glad. This is guaranteed to succeed if no errors are returned.
|
||||
/// The getProcAddress param is an anytype so that we can accept multiple
|
||||
/// forms of the function depending on what we're interfacing with.
|
||||
pub fn load(getProcAddress: anytype) !c_int {
|
||||
const res = switch (@TypeOf(getProcAddress)) {
|
||||
// glfw
|
||||
fn ([*:0]const u8) callconv(.C) ?fn () callconv(.C) void => c.gladLoadGL(@ptrCast(
|
||||
fn ([*c]const u8) callconv(.C) ?fn () callconv(.C) void,
|
||||
getProcAddress,
|
||||
)),
|
||||
|
||||
// try as-is. If this introduces a compiler error, then add a new case.
|
||||
else => c.gladLoadGL(getProcAddress),
|
||||
};
|
||||
if (res == 0) return error.GLInitFailed;
|
||||
return res;
|
||||
}
|
||||
|
||||
pub fn versionMajor(res: c_int) c_uint {
|
||||
// The intcast here is due to translate-c weirdness
|
||||
return c.GLAD_VERSION_MAJOR(@intCast(c_uint, res));
|
||||
}
|
||||
|
||||
pub fn versionMinor(res: c_int) c_uint {
|
||||
// The intcast here is due to translate-c weirdness
|
||||
return c.GLAD_VERSION_MINOR(@intCast(c_uint, res));
|
||||
}
|
Reference in New Issue
Block a user