//! ---------------------------------------------------- //! ---------------------------------------------------- const vk = @import("vulkan"); const gtl = @import("gtl"); const Gfx = @import("../gfx.zig"); const Handle = gtl.Handle; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const Window = union(enum) { win32: struct { hwnd: *anyopaque, hinstance: *anyopaque, }, xcb: struct { connection: *anyopaque, window: u32, }, xlib: struct { display: *anyopaque, window: c_ulong, }, wayland: struct { display: *anyopaque, surface: *anyopaque, }, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const AdapterConfig = struct {}; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const DeviceConfig = struct { adapter: Handle(Adapter), surface: Handle(Surface), }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const Format = enum { int, float, vec2, vec3, vec4, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const VertexBinding = struct { binding: u32 = 0, stride: u32, input_rate: enum { vertex, instance, } = .vertex, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const VertexAttribute = struct { location: u32, binding: u32 = 0, offset: u32, format: Format, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const PipelineConfig = struct { shader: Handle(Shader), swapchain: Handle(Swapchain), device: Handle(Device), vertex_binding: ?VertexBinding = null, vertex_attributes: []const VertexAttribute = &.{}, topology: enum { triangle_list, line_list, } = .triangle_list, cull_mode: enum { front_and_back, front, back, none, } = .back, front_face: enum { ccw, cw, } = .cw, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const BufferUsage = enum { vertex, index, }; /// ---------------------------------------------------- /// ---------------------------------------------------- pub const BufferSharingMode = enum { exclusive, }; // // HANDLE TYPES // pub const Adapter = struct {}; pub const Device = struct {}; pub const Surface = struct {}; pub const Swapchain = struct {}; pub const Buffer = struct { handle: Handle(Buffer), device: Handle(Device), gfx: *Gfx, pub fn set(self: *const Buffer, value: anytype) !void { switch (self.gfx.ctx) { .vulkan => |*v| { const raw = v.resource.buffers.get(self.handle) orelse return error.BufferNotFound; try raw.set(value, @sizeOf(@TypeOf(value))); }, } } pub fn bind(self: *const Buffer) !void { switch (self.gfx.ctx) { .vulkan => |*v| { const raw = v.resource.buffers.get(self.handle) orelse return error.BufferNotFound; const frame = v.currentFrame(); if (frame.cmd_buf) |cmd| { const buffers = [_]vk.VkBuffer{raw.raw}; const offsets = [_]vk.VkDeviceSize{0}; switch (raw.usage) { .vertex => vk.vkCmdBindVertexBuffers(cmd, 0, 1, &buffers, &offsets), .index => vk.vkCmdBindIndexBuffer(cmd, raw.raw, 0, vk.VK_INDEX_TYPE_UINT32), } } }, } } }; pub const Image = struct {}; pub const ImageView = struct {}; pub const Sampler = struct {}; pub const Shader = struct {}; pub const PipelineLayout = struct {}; pub const Pipeline = struct { handle: Handle(Pipeline), device: Handle(Device), gfx: *Gfx, pub fn bind(self: *const Pipeline) !void { try switch (self.gfx.ctx) { .vulkan => |*v| v.bindPipeline(self.handle), }; } pub fn setUniform(self: *const Pipeline, name: []const u8, value: anytype) !void { _ = self; _ = name; _ = value; } };