182 lines
4.3 KiB
Zig
182 lines
4.3 KiB
Zig
const std = @import("std");
|
|
|
|
const Base = @import("Base.zig");
|
|
const Instance = @import("instance.zig").Instance;
|
|
const Display = @import("display.zig").Display;
|
|
const Window = @import("display.zig").Window;
|
|
const Device = @import("device.zig").Device;
|
|
const memory = @import("memory.zig");
|
|
const framebuffer = @import("framebuffer.zig");
|
|
const Swapchain = @import("swapchain.zig").Swapchain;
|
|
const Context = @import("Context.zig");
|
|
//const MainPass = @import("main_pass.zig").MainPass;
|
|
const Command = @import("Command.zig");
|
|
|
|
instance: Instance,
|
|
window: Window,
|
|
device: Device,
|
|
swapchain: Swapchain,
|
|
context: Context,
|
|
// sampler: Sampler, TODO
|
|
// tex_table: TexTable, TODO
|
|
// bindings: Bindings, TODO
|
|
// targets: Targets, TODO
|
|
// mesh_sys: MeshSys, TODO
|
|
// im_sys: ImSys, TODO
|
|
//main_pass: MainPass,
|
|
|
|
const Self = @This();
|
|
|
|
pub fn init() !Self {
|
|
errdefer {
|
|
std.debug.print("failed to init VulkanRenderer", .{});
|
|
}
|
|
|
|
try Base.init();
|
|
|
|
const instance = try Instance.init();
|
|
errdefer instance.deinit();
|
|
|
|
const window = try windowInit(&instance);
|
|
errdefer window.deinit(&instance);
|
|
|
|
const device = try Device.init(&instance, &window);
|
|
errdefer device.deinit();
|
|
|
|
try memory.init(&instance, &device);
|
|
errdefer memory.deinit(&device);
|
|
|
|
try framebuffer.init();
|
|
errdefer framebuffer.deinit(&device);
|
|
|
|
const swapchain = try Swapchain.init(&instance, &window, &device, null);
|
|
errdefer swapchain.deinit();
|
|
|
|
const context = Context.init();
|
|
errdefer context.deinit();
|
|
// try self.sampler.init();
|
|
// try self.texTable.init();
|
|
// try self.bindings.init();
|
|
// try self.targets.init();
|
|
// try self.meshSys.init();
|
|
// try self.imSys.init();
|
|
//try self.main_pass.init();
|
|
|
|
return Self{
|
|
.instance = instance,
|
|
.window = window,
|
|
.device = device,
|
|
.swapchain = swapchain,
|
|
.context = context,
|
|
};
|
|
}
|
|
|
|
pub fn update(self: Self) void {
|
|
// TODO profiling
|
|
|
|
// base system update
|
|
{
|
|
try self.swapchain.acquireSync(&self.device);
|
|
self.swapchain.acquireImage();
|
|
memory.update();
|
|
}
|
|
|
|
// system update
|
|
{
|
|
// TODO: sampler/meshsys/imsys update
|
|
}
|
|
|
|
// setup phase
|
|
{
|
|
//self.main_pass.setup();
|
|
// TODO textable update
|
|
Command.flush();
|
|
// TODO bindings update
|
|
}
|
|
|
|
// execute phase
|
|
//self.main_pass.execute();
|
|
|
|
// present phase
|
|
self.swapchain.submit(Command.get());
|
|
|
|
// background work
|
|
{
|
|
// TODO upload lightmaps, imsys clear
|
|
Command.flush();
|
|
}
|
|
}
|
|
|
|
pub fn deinit(self: Self) void {
|
|
self.device.waitIdle() catch {};
|
|
|
|
// TODO: delete lightmap pack
|
|
|
|
//self.main_pass.deinit();
|
|
|
|
// self.imSys.deinit();
|
|
// self.meshSys.deinit();
|
|
// self.targets.deinit();
|
|
// self.bindings.deinit();
|
|
// self.texTable.deinit();
|
|
// self.sampler.deinit();
|
|
// clear other passes here.
|
|
|
|
memory.finalize(&self.device) catch {};
|
|
|
|
Context.deinit();
|
|
self.swapchain.deinit(&self.device);
|
|
framebuffer.deinit(&self.device);
|
|
self.window.deinit(&self.instance);
|
|
memory.deinit(&self.device);
|
|
self.device.deinit();
|
|
self.instance.deinit();
|
|
}
|
|
|
|
fn windowInit(instance: *const Instance) !Window {
|
|
// TODO: convar cv_fullscreen
|
|
const fullscreen = false;
|
|
|
|
const extents = try Display.getSize(fullscreen);
|
|
const window = try Window.init(instance, "efemra", extents.width, extents.height, fullscreen);
|
|
|
|
// TODO: convar r_width/r_height set
|
|
// TODO: UISys_Init
|
|
return window;
|
|
}
|
|
|
|
fn windowDeinit(window: *Window) void {
|
|
// TODO: uisys_shutdown
|
|
// TODO: convar r_width/r_height unset
|
|
window.deinit();
|
|
}
|
|
|
|
fn windowUpdate(self: Self) !void {
|
|
if (!self.window.isOpen()) {
|
|
return error.WindowNotOpen;
|
|
}
|
|
// TODO: convar fullscreen change check
|
|
if (0) {
|
|
self.device.waitIdle();
|
|
|
|
// TODO: UI pass del
|
|
self.swapchain.deinit();
|
|
self.window.deinit();
|
|
|
|
self.window.init();
|
|
self.swapchain.init(null);
|
|
// TODO: UI pass new
|
|
}
|
|
|
|
if (self.window.updateSize()) {
|
|
try self.swapchain.recreate();
|
|
// TODO set r_width/r_height convar
|
|
}
|
|
|
|
if (!self.swapchain.handle) {
|
|
return error.NoSwapchainHandle;
|
|
}
|
|
|
|
self.targets.maybeRecreate();
|
|
}
|