Files
ghostty/pkg/opengl/errors.zig
Chris Marchesi fe9cf6a266 build: fully transition away from cImport/addTranslateC
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.
2026-09-15 11:01:24 -07:00

34 lines
968 B
Zig

const std = @import("std");
const c = @import("opengl_c");
const glad = @import("glad.zig");
pub const Error = error{
InvalidEnum,
InvalidValue,
InvalidOperation,
InvalidFramebufferOperation,
OutOfMemory,
Unknown,
};
/// getError returns the error (if any) from the last OpenGL operation.
pub fn getError() Error!void {
return switch (glad.context.GetError.?()) {
c.GL_NO_ERROR => {},
c.GL_INVALID_ENUM => Error.InvalidEnum,
c.GL_INVALID_VALUE => Error.InvalidValue,
c.GL_INVALID_OPERATION => Error.InvalidOperation,
c.GL_INVALID_FRAMEBUFFER_OPERATION => Error.InvalidFramebufferOperation,
c.GL_OUT_OF_MEMORY => Error.OutOfMemory,
else => Error.Unknown,
};
}
/// mustError just calls getError but always results in an error being returned.
/// If getError has no error, then Unknown is returned.
pub fn mustError() Error!void {
try getError();
return Error.Unknown;
}