gpu: make Device.setDeviceLostCallback friendlier

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
This commit is contained in:
Stephen Gutekanst 2022-07-31 13:45:40 -07:00 committed by Stephen Gutekanst
parent dec1f08dd1
commit 0228b50dba

View file

@ -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 {