//! ---------------------------------------------------- //! ---------------------------------------------------- const std = @import("std"); const gtl = @import("gtl"); const Material = @import("../../common/component/material.zig"); 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) { draw: struct { mesh: Mesh, material: Material, }, draw_indexed: struct { mesh: Mesh, material: Material, }, begin_pass: struct { camera: Handle(Camera), color: [4]f32 = .{ 0, 0, 0, 255 }, load_op: enum { load, clear, } = .clear, store_op: enum { store, discard, } = .store, }, end_pass, }; // // FIELDS // commands: std.ArrayList(DrawCMD), alloc: std.mem.Allocator, /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn init(alloc: std.mem.Allocator) Self { return .{ .commands = .empty, .alloc = alloc, }; } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn deinit(self: *Self) void { self.commands.deinit(self.alloc); } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn clear(self: *Self) void { self.commands.clearRetainingCapacity(); } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn draw( self: *Self, cmd: DrawCMD, ) !void { try self.commands.append( self.alloc, cmd, ); } // // TESTING // /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn beginPass(self: *Self) void { self.draw(.{ .begin_pass = .{ .camera = undefined, } }) catch unreachable; } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn endPass(self: *Self) void { self.draw(.end_pass) catch unreachable; } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn drawTriangle(self: *Self) void { self.draw(.{ .draw = .{ .material = .{}, .mesh = .triangle } }) catch unreachable; } /// ---------------------------------------------------- /// ---------------------------------------------------- pub fn drawSquare(self: *Self) void { self.draw(.{ .draw = .{ .material = .{}, .mesh = .square } }) catch unreachable; }