new opengl function calls for stage2

This commit is contained in:
Mitchell Hashimoto
2022-10-14 09:18:33 -07:00
parent e73db24f0e
commit c99fb89738
2 changed files with 10 additions and 3 deletions

View File

@ -191,7 +191,10 @@ pub fn create(alloc: Allocator, loop: libuv.Loop, config: *const Config) !*Windo
try glfw.swapInterval(1);
// Load OpenGL bindings
const version = try gl.glad.load(glfw.getProcAddress);
const version = try gl.glad.load(switch (builtin.zig_backend) {
.stage1 => glfw.getProcAddress,
else => &glfw.getProcAddress,
});
log.info("loaded OpenGL {}.{}", .{
gl.glad.versionMajor(version),
gl.glad.versionMinor(version),

View File

@ -1,13 +1,17 @@
const std = @import("std");
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 GlProc = std.meta.FnPtr(fn () callconv(.C) void);
const GlfwFn = std.meta.FnPtr(fn ([*:0]const u8) callconv(.C) ?GlProc);
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,
GlfwFn => c.gladLoadGL(@ptrCast(
std.meta.FnPtr(fn ([*c]const u8) callconv(.C) ?GlProc),
getProcAddress,
)),