mach: Reorganised native backend files, moved structs and fixed circular

dependency
This commit is contained in:
iddev5 2022-05-15 12:33:50 +05:30 committed by Stephen Gutekanst
parent 2df0bc2786
commit 657091ed65
6 changed files with 106 additions and 117 deletions

View file

@ -6,48 +6,6 @@ const App = @import("app");
const structs = @import("structs.zig");
const enums = @import("enums.zig");
pub const VSyncMode = enum {
/// Potential screen tearing.
/// No synchronization with monitor, render frames as fast as possible.
none,
/// No tearing, synchronizes rendering with monitor refresh rate, rendering frames when ready.
///
/// Tries to stay one frame ahead of the monitor, so when it's ready for the next frame it is
/// already prepared.
double,
/// No tearing, synchronizes rendering with monitor refresh rate, rendering frames when ready.
///
/// Tries to stay two frames ahead of the monitor, so when it's ready for the next frame it is
/// already prepared.
triple,
};
/// Application options that can be configured at init time.
pub const Options = struct {
/// The title of the window.
title: [*:0]const u8 = "Mach engine",
/// The width of the window.
width: u32 = 640,
/// The height of the window.
height: u32 = 480,
/// Monitor synchronization modes.
vsync: VSyncMode = .double,
/// GPU features required by the application.
required_features: ?[]gpu.Feature = null,
/// GPU limits required by the application.
required_limits: ?gpu.Limits = null,
/// Whether the application has a preference for low power or high performance GPU.
power_preference: gpu.PowerPreference = .none,
};
const Engine = @This();
/// Window, events, inputs etc.
@ -58,7 +16,7 @@ gpu_driver: GpuDriver,
allocator: Allocator,
options: Options,
options: structs.Options,
/// The amount of time (in seconds) that has passed since the last frame was rendered.
///
@ -102,7 +60,7 @@ pub const GpuDriver = struct {
target_desc: gpu.SwapChain.Descriptor,
};
pub fn init(allocator: std.mem.Allocator, options: Options) !Engine {
pub fn init(allocator: std.mem.Allocator, options: structs.Options) !Engine {
var engine = Engine{
.allocator = allocator,
.options = options,
@ -111,6 +69,8 @@ pub fn init(allocator: std.mem.Allocator, options: Options) !Engine {
.gpu_driver = undefined,
};
// Note: if in future, there is a conflict in init() signature of different backends,
// move these calls to the entry point file, which is native.zig for Glfw, for example
engine.core.internal = try GetCoreInternalType().init(allocator, &engine);
engine.gpu_driver.internal = try GetGpuDriverInternalType().init(allocator, &engine);