mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-09-20 12:38:08 +00:00
This migrates all remaining uses of cImport (and addTranslateC for good measure) to using translate-c for C translation, ensuring that we are ready for when cImport is removed from the language, and also that all sources of C translation are using the same snapshot of the external package (when can then be updated when we need to fix something). A couple of notes: * A few options have been added to support the new translations, namely the ability to link libraries (passed through to linkLibrary on the Translator side) and whether or not to initialize default values (looks like cImport did this without a way to control it, but translate-c does not do it by default). * Using the new library linking option actually simplifies the process of translating a number of the C packages as we have been shipping the necessary headers for these packages already with the applicable libraries. For some of the more complex translation processes though, we still include the appropriate directories directly.
46 lines
1.5 KiB
Zig
46 lines
1.5 KiB
Zig
const std = @import("std");
|
|
const c = @import("opengl_c");
|
|
|
|
pub const Context = c.GladGLContext;
|
|
|
|
/// This is the current context. Set this var manually prior to calling
|
|
/// any of this package's functions. I know its nasty to have a global but
|
|
/// this makes it match OpenGL API styles where it also operates on a
|
|
/// threadlocal global.
|
|
pub threadlocal var context: Context = undefined;
|
|
|
|
/// 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 GlProc = *const fn () callconv(.c) void;
|
|
const GlfwFn = *const fn ([*:0]const u8) callconv(.c) ?GlProc;
|
|
|
|
const res = switch (@TypeOf(getProcAddress)) {
|
|
// glfw
|
|
GlfwFn => c.gladLoadGLContext(&context, @ptrCast(getProcAddress)),
|
|
|
|
// null proc address means that we are just loading the globally
|
|
// pointed gl functions
|
|
@TypeOf(null) => c.gladLoaderLoadGLContext(&context),
|
|
|
|
// try as-is. If this introduces a compiler error, then add a new case.
|
|
else => c.gladLoadGLContext(&context, @ptrCast(getProcAddress)),
|
|
};
|
|
if (res == 0) return error.GLInitFailed;
|
|
return res;
|
|
}
|
|
|
|
pub fn unload() void {
|
|
c.gladLoaderUnloadGLContext(&context);
|
|
context = undefined;
|
|
}
|
|
|
|
pub fn versionMajor(res: c_uint) c_uint {
|
|
return c.GLAD_VERSION_MAJOR(res);
|
|
}
|
|
|
|
pub fn versionMinor(res: c_uint) c_uint {
|
|
return c.GLAD_VERSION_MINOR(res);
|
|
}
|