Renderer/src/plugin.zig

71 lines
2 KiB
Zig

//! ----------------------------------------------------
//! ----------------------------------------------------
const App = @import("app");
const system = @import("system/root.zig");
const resource = @import("resource/root.zig");
const component = @import("component/root.zig");
/// ----------------------------------------------------
/// ----------------------------------------------------
pub const plugin: App.plugin.Plugin = .{
.name = "Renderer",
.description = "WebGPU Renderer",
.build = build,
};
/// ----------------------------------------------------
/// ----------------------------------------------------
fn build(
_: *App.plugin.Plugin,
ctx: App.plugin.Context,
) !void {
// --- CORE ---
try ctx.app.resources.set(resource.Instance{});
try ctx.app.resources.set(resource.Device{});
try ctx.app.resources.set(resource.window{});
try ctx.app.resources.set(resource.Cache.init(ctx.app.alloc));
// --- RENDER ---
try ctx.app.resources.set(resource.RenderFrame{});
try ctx.app.resources.set(resource.RenderQueue.init(ctx.app.alloc));
{ // TEST
try ctx.app.world.spawn(.{
component.PBRMaterial{},
});
try ctx.app.world.spawn(.{
component.UnlitMaterial{},
});
}
// --- INIT ---
try ctx.app.schedules.addMany(App.stage.Init, &.{
system.instance.init,
system.window.init,
system.device.init,
system.frame.begin,
system.frame.prepare,
});
// --- DEINIT ---
try ctx.app.schedules.addMany(App.stage.Deinit, &.{
system.frame.end,
struct { // TODO: Clean this shit up 🥀
pub fn sys(_ctx: App.scheduler.Context) !void {
if (_ctx.app.resources.getPtr(resource.Cache)) |cache| {
cache.deinit();
}
}
}.sys,
system.device.deinit,
system.window.deinit,
system.instance.deinit,
});
// --- INPUT ---
try ctx.app.schedules.addMany(App.stage.Inputs, &.{});
}