Skip to content

Commit 5c2d67e

Browse files
committed
working on vtable
1 parent 335dec1 commit 5c2d67e

2 files changed

Lines changed: 19 additions & 7 deletions

File tree

src/vulkan/Instance.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
const std = @import("std");
12
const vk = @import("vulkan");
3+
const PhysicalDevice = @import("PhysicalDevice").PhysicalDevice;
24
const Object = @import("object.zig").Object;
35

46
pub const Instance = extern struct {
57
const Self = @This();
68
const ObjectType: vk.ObjectType = .instance;
79

810
object: Object,
11+
physical_devices: std.ArrayList(*PhysicalDevice),
12+
alloc_callbacks: vk.AllocationCallbacks,
913
};

src/vulkan/object.zig

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ pub const Object = extern struct {
2323
};
2424

2525
pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T {
26-
if (handle == .null_handle) {
27-
return error.NullHandle;
26+
comptime {
27+
if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
28+
@compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
29+
}
2830
}
2931

30-
if (!@hasDecl(T, "object")) {
31-
return error.NotAnObject;
32-
}
33-
if (!@hasDecl(T, "ObjectType") || @TypeOf(T.ObjectType) != vk.ObjectType) {
34-
@panic("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
32+
if (handle == .null_handle) {
33+
return error.NullHandle;
3534
}
3635

3736
const dispatchable: *T = @ptrFromInt(@intFromEnum(handle));
@@ -40,3 +39,12 @@ pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T
4039
}
4140
return dispatchable;
4241
}
42+
43+
pub inline fn toHandle(comptime T: type, handle: *T) usize {
44+
comptime {
45+
if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
46+
@compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
47+
}
48+
}
49+
return @intFromPtr(handle);
50+
}

0 commit comments

Comments
 (0)