diff options
Diffstat (limited to 'pkg/opengl/errors.zig')
| -rw-r--r-- | pkg/opengl/errors.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/pkg/opengl/errors.zig b/pkg/opengl/errors.zig new file mode 100644 index 000000000..86639a53a --- /dev/null +++ b/pkg/opengl/errors.zig @@ -0,0 +1,33 @@ +const std = @import("std"); +const c = @import("c.zig"); +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; +} |
