From 0228b50dba28b0281a1419988adf26b0beaebb0d Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sun, 31 Jul 2022 13:45:40 -0700 Subject: [PATCH] gpu: make Device.setDeviceLostCallback friendlier Signed-off-by: Stephen Gutekanst --- gpu/src/device.zig | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gpu/src/device.zig b/gpu/src/device.zig index 1565e646..69dfa388 100644 --- a/gpu/src/device.zig +++ b/gpu/src/device.zig @@ -222,10 +222,16 @@ pub const Device = opaque { // TODO: presumably callback should be nullable for unsetting pub inline fn setDeviceLostCallback( device: *Device, - callback: Device.LostCallback, - userdata: ?*anyopaque, + comptime Context: type, + comptime callback: fn (reason: LostReason, message: [*:0]const u8, ctx: Context) callconv(.Inline) void, + context: Context, ) void { - Impl.deviceSetDeviceLostCallback(device, callback, userdata); + const Helper = struct { + pub fn callback(reason: LostReason, message: [*:0]const u8, userdata: ?*anyopaque) callconv(.C) void { + callback(reason, message, if (Context == void) {} else @ptrCast(Context, userdata)); + } + }; + Impl.deviceSetDeviceLostCallback(device, Helper.callback, if (Context == void) null else context); } pub inline fn setLabel(device: *Device, label: [*:0]const u8) void {