working on vtable
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const std = @import("std");
|
||||
const vk = @import("vulkan");
|
||||
const PhysicalDevice = @import("PhysicalDevice").PhysicalDevice;
|
||||
const Object = @import("object.zig").Object;
|
||||
|
||||
pub const Instance = extern struct {
|
||||
@@ -6,4 +8,6 @@ pub const Instance = extern struct {
|
||||
const ObjectType: vk.ObjectType = .instance;
|
||||
|
||||
object: Object,
|
||||
physical_devices: std.ArrayList(*PhysicalDevice),
|
||||
alloc_callbacks: vk.AllocationCallbacks,
|
||||
};
|
||||
|
||||
@@ -23,15 +23,14 @@ pub const Object = extern struct {
|
||||
};
|
||||
|
||||
pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T {
|
||||
if (handle == .null_handle) {
|
||||
return error.NullHandle;
|
||||
comptime {
|
||||
if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
|
||||
@compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
|
||||
}
|
||||
}
|
||||
|
||||
if (!@hasDecl(T, "object")) {
|
||||
return error.NotAnObject;
|
||||
}
|
||||
if (!@hasDecl(T, "ObjectType") || @TypeOf(T.ObjectType) != vk.ObjectType) {
|
||||
@panic("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
|
||||
if (handle == .null_handle) {
|
||||
return error.NullHandle;
|
||||
}
|
||||
|
||||
const dispatchable: *T = @ptrFromInt(@intFromEnum(handle));
|
||||
@@ -40,3 +39,12 @@ pub inline fn fromHandle(comptime T: type, comptime VkT: type, handle: VkT) !*T
|
||||
}
|
||||
return dispatchable;
|
||||
}
|
||||
|
||||
pub inline fn toHandle(comptime T: type, handle: *T) usize {
|
||||
comptime {
|
||||
if (!@hasDecl(T, "object") or !@hasDecl(T, "ObjectType") or @TypeOf(T.ObjectType) != vk.ObjectType) {
|
||||
@compileError("Object type \"" ++ @typeName(T) ++ "\" is malformed.");
|
||||
}
|
||||
}
|
||||
return @intFromPtr(handle);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user