diff --git a/build.zig.zon b/build.zig.zon index a37eee2..6a47079 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -17,8 +17,8 @@ .hash = "app-0.0.0-AOV9_YDvAAAjjuCldX-9p7mt3Oswbv8bTB2rvcZ67Fn1", }, .gtl = .{ - .url = "git+http://2.120.146.66:25569/abux/gtl.git#3c7fcfcb1276b76ec4695ce5ce9dba4d8255a176", - .hash = "gtl-0.0.0-e3QoJMRYAADChgXn2sogTxsbUpEBSHjOGZeoEx4ccMMD", + .url = "git+http://192.168.0.11:25569/abux/GTL.git#f9772950b5097bbbda39cd68d86f6b6062c41fec", + .hash = "gtl-0.0.0-e3QoJPNxAABpkY1nvYNN7r02CI4z2aki1_FHDPzdWi9P", }, .NYXMath = .{ .url = "git+http://192.168.0.11:25569/abux/NYXMath.git#cb7b54995bdb46321f112bba2a704d58cf53aeb1", diff --git a/src/main.zig b/src/main.zig index f28d327..3ff10db 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,6 +6,7 @@ // const std = @import("std"); +const gtl = @import("gtl"); const math = @import("math"); const App = @import("app"); @@ -44,18 +45,25 @@ pub fn main(init: std.process.Init) !void { }); try app.plugins.build(&app); - { // DEBUG - std.debug.print("\x1b[33m┏━\x1b[0m PLUGINS\n", .{}); + // DEBUG + if (gtl.log.print(.debug, "PLUGINS", gtl.ansi.yellow)) |v| { + defer v.end(); + for (app.plugins.data.items) |plugin| { - std.debug.print("\x1b[33m┃\x1b[0m {s:<12} {s}\n", .{ plugin.name, plugin.description }); + v.write("{s}", .{plugin.name}); } - std.debug.print("\x1b[33m┗━\x1b[0m\n", .{}); } // --- LIFETIME --- try app.schedules.run(App.stage.init, &app); defer app.schedules.runReversed(App.stage.deinit, &app) catch unreachable; + // --- # --- + errdefer { + app.schedules.runReversed(App.stage.deinit, &app) catch unreachable; + app.deinit(); + } + // --- MAIN LOOP --- while (true) { // --- # --- diff --git a/src/plugins/device/resource/adapter_info.zig b/src/plugins/device/resource/adapter_info.zig new file mode 100644 index 0000000..739e446 --- /dev/null +++ b/src/plugins/device/resource/adapter_info.zig @@ -0,0 +1,26 @@ +//! ---------------------------------------------------- +//! ---------------------------------------------------- + +const wgpu = @import("wgpu"); + +/// ---------------------------------------------------- +/// ---------------------------------------------------- +pub const Backend = enum { + vulkan, + webgpu, + opengl, + + d3d11, + d3d12, + metal, +}; + +// +// FIELDS +// + +device: []const u8, +vendor: []const u8, + +backend: Backend, +surface_format: wgpu.WGPUTextureFormat, diff --git a/src/plugins/device/root.zig b/src/plugins/device/root.zig index 1f00102..434a575 100644 --- a/src/plugins/device/root.zig +++ b/src/plugins/device/root.zig @@ -12,6 +12,7 @@ const lifetime = @import("system/lifetime.zig"); // PUBLIC // +pub const AdapterInfo = @import("resource/adapter_info.zig"); pub const WGPUDevice = @import("resource/wgpu_device.zig"); /// ---------------------------------------------------- diff --git a/src/plugins/device/system/lifetime.zig b/src/plugins/device/system/lifetime.zig index bb2e011..bb22d77 100644 --- a/src/plugins/device/system/lifetime.zig +++ b/src/plugins/device/system/lifetime.zig @@ -6,6 +6,7 @@ const wgpu = @import("wgpu"); const App = @import("app"); const WGPUInstance = @import("../../platform/resource/wgpu_instance.zig"); +const AdapterInfo = @import("../resource/adapter_info.zig"); const WGPUDevice = @import("../resource/wgpu_device.zig"); /// ---------------------------------------------------- @@ -51,6 +52,42 @@ pub fn init(app: *App) !void { const adapter = if (adapter_userdata.adapter) |v| v else return error.NoAdapter; defer wgpu.wgpuAdapterRelease(adapter); + // --- GET ADAPTER INFO --- + var adapter_info: wgpu.WGPUAdapterInfo = .{}; + switch (wgpu.wgpuAdapterGetInfo(adapter, &adapter_info)) { + wgpu.WGPUStatus_Success => {}, + else => return error.AdapterInfoFailed, + } + + // --- GET SURFACE CAPABILITIES --- + // var surface_caps: wgpu.WGPUSurfaceCapabilities = .{}; + // defer wgpu.wgpuSurfaceCapabilitiesFreeMembers(surface_caps); + + // switch (wgpu.wgpuSurfaceGetCapabilities( + // surface, + // adapter, + // &surface_caps, + // )) { + // wgpu.WGPUStatus_Success => {}, + // else => return error.SurfaceCapabilitiesFailed, + // } + + // --- SET ADAPTER INFO --- + try app.resources.set(AdapterInfo{ + .device = std.mem.span(adapter_info.device.data), + .vendor = std.mem.span(adapter_info.vendor.data), + .backend = switch (adapter_info.backendType) { + wgpu.WGPUBackendType_Vulkan => .vulkan, + wgpu.WGPUBackendType_WebGPU => .webgpu, + wgpu.WGPUBackendType_OpenGL => .opengl, + wgpu.WGPUBackendType_D3D11 => .d3d11, + wgpu.WGPUBackendType_D3D12 => .d3d12, + wgpu.WGPUBackendType_Metal => .metal, + else => return error.InvalidBackendType, + }, + .surface_format = 28, + }); + // // DEVICE // diff --git a/src/plugins/playground/root.zig b/src/plugins/playground/root.zig index a928845..58aadda 100644 --- a/src/plugins/playground/root.zig +++ b/src/plugins/playground/root.zig @@ -79,7 +79,7 @@ fn start(app: *App) !void { Transform3D{}, }); - const count: usize = 100; + const count: usize = 200; const radius: f32 = 5.0; for (0..count) |i| { @@ -90,7 +90,12 @@ fn start(app: *App) !void { Material{ .value = try render_world.materials.put(.{ .style = .{ - .albedo = .{ 0.2, 0.2, 0.8, 1 }, + .albedo = .{ + 0.2, + 0.0 + (angle * std.math.pi) * 0.01, + 0.0 + (angle * std.math.pi) * 0.02, + 1, + }, }, .unique = .{ .cull_mode = .none, diff --git a/src/plugins/renderer/resource/renderer.zig b/src/plugins/renderer/resource/renderer.zig index 8d45051..0d53a9d 100644 --- a/src/plugins/renderer/resource/renderer.zig +++ b/src/plugins/renderer/resource/renderer.zig @@ -8,9 +8,6 @@ const Mesh = @import("../../cache/resource/mesh_cache.zig").MeshID; const Handle = gtl.Handle; const Self = @This(); -// TODO: -const Camera = struct {}; - /// ---------------------------------------------------- /// ---------------------------------------------------- pub const DrawCMD = union(enum) { @@ -22,6 +19,7 @@ pub const DrawCMD = union(enum) { draw_indexed: struct { mesh: Mesh, + entity: u64, material: Handle(Material), }, diff --git a/src/plugins/renderer/system/prepare.zig b/src/plugins/renderer/system/prepare.zig index cbc1c37..24747a8 100644 --- a/src/plugins/renderer/system/prepare.zig +++ b/src/plugins/renderer/system/prepare.zig @@ -476,7 +476,14 @@ fn createPipeline( .mask = ~@as(u32, 0), .alphaToCoverageEnabled = 0, }, - .depthStencil = null, + // .depthStencil = &wgpu.WGPUDepthStencilState{ + // .format = wgpu.WGPUTextureFormat_Depth24Plus, + // .depthCompare = wgpu.WGPUCompareFunction_Less, + // .depthWriteEnabled = 1, + // + // .stencilReadMask = 0, + // .stencilWriteMask = 0, + // }, }) orelse { return error.PipelineCreationFailed; };