From 8d9ca11b451eb105f54eb20dba1f31864a6a815d Mon Sep 17 00:00:00 2001 From: iddev5 Date: Tue, 24 May 2022 23:41:19 +0530 Subject: [PATCH] mach: wasm: add note about vsync support and move VSyncMode to enums.zig --- src/enums.zig | 22 ++++++++++++++++++++++ src/structs.zig | 20 +------------------- src/wasm.zig | 2 ++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/enums.zig b/src/enums.zig index 8eab93df..29221085 100644 --- a/src/enums.zig +++ b/src/enums.zig @@ -1,3 +1,25 @@ +pub const VSyncMode = enum { + /// Potential screen tearing. + /// No synchronization with monitor, render frames as fast as possible. + /// + /// Not available on WASM, fallback to double + 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. + /// + /// Not available on WASM, fallback to double + triple, +}; + pub const Key = enum { a, b, diff --git a/src/structs.zig b/src/structs.zig index 4fec8d4a..e0e3182a 100644 --- a/src/structs.zig +++ b/src/structs.zig @@ -11,24 +11,6 @@ pub const SizeOptional = struct { height: ?u32, }; -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. @@ -41,7 +23,7 @@ pub const Options = struct { height: u32 = 480, /// Monitor synchronization modes. - vsync: VSyncMode = .double, + vsync: enums.VSyncMode = .double, /// GPU features required by the application. required_features: ?[]gpu.Feature = null, diff --git a/src/wasm.zig b/src/wasm.zig index 2b988100..7816dbe6 100644 --- a/src/wasm.zig +++ b/src/wasm.zig @@ -106,6 +106,8 @@ export fn wasmInit() void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; const allocator = gpa.allocator(); + // NOTE: On wasm, vsync is double by default and cannot be changed. + // Hence options.vsync is not used anywhere. const options = if (@hasDecl(App, "options")) App.options else structs.Options{}; engine = Engine.init(allocator, options) catch unreachable;