From 34135fa83e2c9a4b1cbad33c55d3b5aea4134563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Gasi=C5=84ski?= Date: Sun, 6 Oct 2024 22:28:34 +0200 Subject: [PATCH] WIP: Resource manager --- src/Material.zig | 12 +++++++++ src/ResourceManager.zig | 54 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/Material.zig create mode 100644 src/ResourceManager.zig diff --git a/src/Material.zig b/src/Material.zig new file mode 100644 index 0000000..f65275f --- /dev/null +++ b/src/Material.zig @@ -0,0 +1,12 @@ +const std = @import("std"); +const vk = @import("vulkan"); + +const Context = @import("Context.zig"); + +const Self = @This(); + +allocator: std.mem.Allocator, + +ctx: Context, + +pub fn new(allocator: std.mem.Allocator, ctx: Context) Self {} diff --git a/src/ResourceManager.zig b/src/ResourceManager.zig new file mode 100644 index 0000000..4aff513 --- /dev/null +++ b/src/ResourceManager.zig @@ -0,0 +1,54 @@ +const std = @import("std"); +const vk = @import("vulkan"); + +const Context = @import("Context.zig"); +const Mesh = @import("Mesh.zig"); +const Material = @import("Material.zig"); + +const Self = @This(); + +allocator: std.mem.Allocator, + +ctx: Context, + +sampler_descriptor_pool: vk.DescriptorPool, +sampler_descriptor_set_layout: vk.DescriptorSetLayout, + +mesh_cache: std.AutoArrayHashMap([]const u8, Mesh), +material_cache: std.AutoArrayHashMap([]const u8, Material), + +pub fn new(allocator: std.mem.Allocator, ctx: Context) Self { + var self: Self = undefined; + + self.allocator = allocator; + self.ctx = ctx; + + self.mesh_cache = std.AutoArrayHashMap([]const u8, Mesh).init(allocator); + self.material_cache = std.AutoArrayHashMap([]const u8, Material).init(allocator); + + return self; +} + +pub fn deinit(self: *Self) void { + // TODO Release resources properly + self.mesh_cache.deinit(); + self.material_cache.deinit(); +} + +pub fn getMesh(self: *Self, file_name: []const u8) !Mesh { + if (self.mesh_cache.get(file_name)) |mesh| { + return mesh; + } + + // TODO Create mesh + + return undefined; +} + +fn allocateDescriptorSet(self: *Self) !void { + // TODO +} + +fn createDescriptorSetLayout(self: *Self) !void { + // TODO +}