glfw: support compiling with stage2 (-fno-stage1) (#365)
This commit is contained in:
parent
786e0d6263
commit
7bb877bd55
7 changed files with 35 additions and 32 deletions
|
|
@ -255,7 +255,7 @@ pub inline fn getName(self: Joystick) error{PlatformError}!?[:0]const u8 {
|
|||
else => unreachable,
|
||||
};
|
||||
return if (name_opt) |name|
|
||||
std.mem.span(name)
|
||||
std.mem.span(@ptrCast([*:0]const u8, name))
|
||||
else
|
||||
null;
|
||||
}
|
||||
|
|
@ -297,7 +297,7 @@ pub inline fn getGUID(self: Joystick) error{PlatformError}!?[:0]const u8 {
|
|||
else => unreachable,
|
||||
};
|
||||
return if (guid_opt) |guid|
|
||||
std.mem.span(guid)
|
||||
std.mem.span(@ptrCast([*:0]const u8, guid))
|
||||
else
|
||||
null;
|
||||
}
|
||||
|
|
@ -490,7 +490,7 @@ pub inline fn getGamepadName(self: Joystick) ?[:0]const u8 {
|
|||
else => unreachable,
|
||||
};
|
||||
return if (name_opt) |name|
|
||||
std.mem.span(name)
|
||||
std.mem.span(@ptrCast([*:0]const u8, name))
|
||||
else
|
||||
null;
|
||||
}
|
||||
|
|
@ -603,7 +603,8 @@ test "setUserPointer_syntax" {
|
|||
const joystick = glfw.Joystick{ .jid = .one };
|
||||
|
||||
// Must be called from joystick callback, we cannot test it.
|
||||
_ = joystick.setUserPointer;
|
||||
_ = joystick;
|
||||
_ = setUserPointer;
|
||||
}
|
||||
|
||||
test "getUserPointer_syntax" {
|
||||
|
|
@ -614,7 +615,8 @@ test "getUserPointer_syntax" {
|
|||
const joystick = glfw.Joystick{ .jid = .one };
|
||||
|
||||
// Must be called from joystick callback, we cannot test it.
|
||||
_ = joystick.getUserPointer;
|
||||
_ = joystick;
|
||||
_ = getUserPointer;
|
||||
}
|
||||
|
||||
test "setCallback" {
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ pub inline fn getContentScale(self: Monitor) error{PlatformError}!ContentScale {
|
|||
/// see also: monitor_properties
|
||||
pub inline fn getName(self: Monitor) [*:0]const u8 {
|
||||
internal_debug.assertInitialized();
|
||||
if (c.glfwGetMonitorName(self.handle)) |name| return name;
|
||||
if (c.glfwGetMonitorName(self.handle)) |name| return @ptrCast([*:0]const u8, name);
|
||||
getError() catch |err| return switch (err) {
|
||||
Error.NotInitialized => unreachable,
|
||||
else => unreachable,
|
||||
|
|
@ -239,7 +239,7 @@ pub inline fn getVideoModes(self: Monitor, allocator: mem.Allocator) (mem.Alloca
|
|||
const slice = try allocator.alloc(VideoMode, @intCast(u32, count));
|
||||
var i: u32 = 0;
|
||||
while (i < count) : (i += 1) {
|
||||
slice[i] = VideoMode{ .handle = modes[i] };
|
||||
slice[i] = VideoMode{ .handle = @ptrCast([*c]const c.GLFWvidmode, modes)[i] };
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ pub inline fn getAll(allocator: mem.Allocator) mem.Allocator.Error![]Monitor {
|
|||
const slice = try allocator.alloc(Monitor, @intCast(u32, count));
|
||||
var i: u32 = 0;
|
||||
while (i < count) : (i += 1) {
|
||||
slice[i] = Monitor{ .handle = monitors[i].? };
|
||||
slice[i] = Monitor{ .handle = @ptrCast([*c]const ?*c.GLFWmonitor, monitors)[i].? };
|
||||
}
|
||||
return slice;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ pub inline fn setClipboardString(value: [*:0]const u8) error{PlatformError}!void
|
|||
/// see also: clipboard, glfwSetClipboardString
|
||||
pub inline fn getClipboardString() error{ FormatUnavailable, PlatformError }![:0]const u8 {
|
||||
internal_debug.assertInitialized();
|
||||
if (c.glfwGetClipboardString(null)) |c_str| return std.mem.span(c_str);
|
||||
if (c.glfwGetClipboardString(null)) |c_str| return std.mem.span(@ptrCast([*:0]const u8, c_str));
|
||||
getError() catch |err| return switch (err) {
|
||||
Error.NotInitialized => unreachable,
|
||||
Error.FormatUnavailable, Error.PlatformError => |e| e,
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ pub const Key = enum(c_int) {
|
|||
else => unreachable,
|
||||
};
|
||||
return if (name_opt) |name|
|
||||
std.mem.span(name)
|
||||
std.mem.span(@ptrCast([*:0]const u8, name))
|
||||
else
|
||||
null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -288,7 +288,7 @@ fn initHint(hint: InitHint, value: anytype) void {
|
|||
///
|
||||
/// thread_safety: This function may be called from any thread.
|
||||
pub inline fn getVersionString() [:0]const u8 {
|
||||
return std.mem.span(c.glfwGetVersionString());
|
||||
return std.mem.span(@ptrCast([*:0]const u8, c.glfwGetVersionString()));
|
||||
}
|
||||
|
||||
/// Returns the currently selected platform.
|
||||
|
|
|
|||
|
|
@ -137,7 +137,7 @@ pub inline fn extensionSupported(extension: [:0]const u8) error{ NoCurrentContex
|
|||
std.debug.assert(extension.len != 0);
|
||||
std.debug.assert(extension[0] != 0);
|
||||
|
||||
const supported = c.glfwExtensionSupported(extension);
|
||||
const supported = c.glfwExtensionSupported(extension.ptr);
|
||||
getError() catch |err| return switch (err) {
|
||||
Error.NoCurrentContext, Error.PlatformError => |e| e,
|
||||
Error.NotInitialized => unreachable,
|
||||
|
|
@ -147,12 +147,13 @@ pub inline fn extensionSupported(extension: [:0]const u8) error{ NoCurrentContex
|
|||
return supported == c.GLFW_TRUE;
|
||||
}
|
||||
|
||||
const builtin = @import("builtin");
|
||||
/// Client API function pointer type.
|
||||
///
|
||||
/// Generic function pointer used for returning client API function pointers.
|
||||
///
|
||||
/// see also: context_glext, glfwGetProcAddress
|
||||
pub const GLProc = fn () callconv(.C) void;
|
||||
pub const GLProc = if (builtin.zig_backend == .stage1 or builtin.zig_backend == .other) fn () callconv(.C) void else *const fn () callconv(.C) void;
|
||||
|
||||
/// Returns the address of the specified function for the current context.
|
||||
///
|
||||
|
|
@ -197,7 +198,7 @@ test "makeContextCurrent" {
|
|||
try glfw.init(.{});
|
||||
defer glfw.terminate();
|
||||
|
||||
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
const window = Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
// return without fail, because most of our CI environments are headless / we cannot open
|
||||
// windows on them.
|
||||
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||
|
|
@ -222,7 +223,7 @@ test "swapInterval" {
|
|||
try glfw.init(.{});
|
||||
defer glfw.terminate();
|
||||
|
||||
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
const window = Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
// return without fail, because most of our CI environments are headless / we cannot open
|
||||
// windows on them.
|
||||
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||
|
|
@ -239,7 +240,7 @@ test "getProcAddress" {
|
|||
try glfw.init(.{});
|
||||
defer glfw.terminate();
|
||||
|
||||
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
const window = Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
// return without fail, because most of our CI environments are headless / we cannot open
|
||||
// windows on them.
|
||||
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||
|
|
@ -256,7 +257,7 @@ test "extensionSupported" {
|
|||
try glfw.init(.{});
|
||||
defer glfw.terminate();
|
||||
|
||||
const window = glfw.Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
const window = Window.create(640, 480, "Hello, Zig!", null, null, .{}) catch |err| {
|
||||
// return without fail, because most of our CI environments are headless / we cannot open
|
||||
// windows on them.
|
||||
std.debug.print("note: failed to create window: {}\n", .{err});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue