const options = @import("build_options"); const std = @import("std"); usingnamespace if (options.renderdoc) struct { const c = @cImport({ @cInclude("renderdoc_app.h"); @cInclude("dlfcn.h"); }); fn fix_fields(comptime T: type) type { const TypeId = std.builtin.TypeId; var ti = @typeInfo(T); const num_fields = ti.Struct.fields.len; var fields = [_]TypeId.StructField{undefined} ** num_fields; for (ti.Struct.fields) |field, i| { var field_ti = @typeInfo(field.field_type); switch (field_ti) { .Optional => |opt| { fields[i] = TypeId.StructField{ .name = field.name, .field_type = opt.child, .default_value = @as(opt.child, fields[i].default_value), .is_comptime = field.is_comptime, .alignment = field.alignment, }; }, else => { fields[i] = field; }, } } ti.Struct.fields = fields[0..]; return @Type(.{ .Struct = .{ .layout = .Extern, .fields = fields, .decls = [_]TypeId.Declaration{}, .is_tuple = false, }, }); } const API = struct { StartFrameCapture: fn (c.RENDERDOC_DevicePointer, c.RENDERDOC_WindowHandle) callconv(.C) void, EndFrameCapture: fn (c.RENDERDOC_DevicePointer, c.RENDERDOC_WindowHandle) callconv(.C) u32, }; extern fn RENDERDOC_GetAPI(c.RENDERDOC_Version, [*c]?*c_void) callconv(.C) c_int; pub var api: ?API = null; pub fn load_api() !void { var tmp_api: ?*c.RENDERDOC_API_1_1_2 = null; if (RENDERDOC_GetAPI(.eRENDERDOC_API_Version_1_1_2, @ptrCast([*c]?*c_void, &tmp_api)) != 1) { return error.Unknown; } if (tmp_api) |_api| { var local_api: API = undefined; var have_all: bool = true; if (_api.StartFrameCapture) |fp| { local_api.StartFrameCapture = fp; } else { return error.NoStart; } if (_api.EndFrameCapture) |fp| { local_api.EndFrameCapture = fp; } else { return error.NoEnd; } api = local_api; } else { return error.ApiEmpty; } } } else struct { pub const api: ?u32 = null; pub fn load_api() !void { if (false) return error.NonError; } };