diff --git a/core/rend/gui.cpp b/core/rend/gui.cpp index 33b6e7910..e60685719 100644 --- a/core/rend/gui.cpp +++ b/core/rend/gui.cpp @@ -1432,9 +1432,7 @@ static void gui_display_settings() } OptionCheckbox("Widescreen Game Cheats", config::WidescreenGameHacks, "Modify the game so that it displays in 16:9 anamorphic format and use horizontal screen stretching. Only some games are supported."); -#ifndef __APPLE__ OptionCheckbox("VSync", config::VSync, "Synchronizes the frame rate with the screen refresh rate. Recommended"); -#endif OptionCheckbox("Show FPS Counter", config::ShowFPS, "Show on-screen frame/sec counter"); OptionCheckbox("Show VMU In-game", config::FloatVMUs, "Show the VMU LCD screens while in-game"); OptionCheckbox("Rotate Screen 90°", config::Rotate90, "Rotate the screen 90° counterclockwise"); diff --git a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift index 957482c19..fd6e2ff3c 100644 --- a/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift +++ b/shell/apple/emulator-osx/emulator-osx/EmuGLView.swift @@ -10,7 +10,8 @@ import Cocoa class EmuGLView: NSOpenGLView, NSWindowDelegate { - var backingRect:NSRect? + var backingRect: NSRect? + var swapOnVSync = emu_vsync_enabled() override var acceptsFirstResponder: Bool { return true; @@ -20,19 +21,22 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { super.draw(dirtyRect) backingRect = convertToBacking(dirtyRect) - if emu_fast_forward() == false { + if swapOnVSync { draw() } } func draw() { - var sync: GLint = emu_fast_forward() ? 0 : 1 - CGLSetParameter(openGLContext!.cglContextObj!, kCGLCPSwapInterval, &sync) + if swapOnVSync == (emu_fast_forward() || !emu_vsync_enabled()) { + swapOnVSync = (!emu_fast_forward() && emu_vsync_enabled()) + var sync: GLint = swapOnVSync ? 1 : 0 + CGLSetParameter(openGLContext!.cglContextObj!, kCGLCPSwapInterval, &sync) + } if let backingRect = backingRect { openGLContext!.makeCurrentContext() - if (emu_single_frame(Int32(backingRect.width), Int32(backingRect.height)) != 0) { - openGLContext!.flushBuffer() + if emu_single_frame(Int32(backingRect.width), Int32(backingRect.height)) { + openGLContext!.flushBuffer() //Swap for macOS } } } @@ -80,11 +84,11 @@ class EmuGLView: NSOpenGLView, NSWindowDelegate { if (!emu_renderer_enabled()) { NSApplication.shared.terminate(self) } - else if (emu_frame_pending()) { - if emu_fast_forward() { - self.draw() - } else { + else if emu_frame_pending() { + if swapOnVSync { self.needsDisplay = true + } else { + self.draw() } } } diff --git a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h index 980039a65..1e5c98233 100644 --- a/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h +++ b/shell/apple/emulator-osx/emulator-osx/emulator-osx-Bridging-Header.h @@ -19,7 +19,8 @@ void emu_dc_term(); void emu_gui_open_settings(); bool emu_renderer_enabled(); bool emu_fast_forward(); -int emu_single_frame(int w, int h); +bool emu_vsync_enabled(); +bool emu_single_frame(int w, int h); void emu_gles_init(int width, int height); int emu_reicast_init(); void emu_key_input(UInt16 keyCode, bool pressed, UInt32 modifierFlags); diff --git a/shell/apple/emulator-osx/emulator-osx/osx-main.mm b/shell/apple/emulator-osx/emulator-osx/osx-main.mm index eae472ed5..57ada1707 100644 --- a/shell/apple/emulator-osx/emulator-osx/osx-main.mm +++ b/shell/apple/emulator-osx/emulator-osx/osx-main.mm @@ -131,14 +131,27 @@ bool emu_fast_forward() return settings.input.fastForwardMode; } -int emu_single_frame(int w, int h) +bool emu_vsync_enabled() { - if (!emu_frame_pending()) - return 0; + return config::VSync; +} +bool emu_single_frame(int w, int h) +{ screen_width = w; screen_height = h; - return (int)mainui_rend_frame(); + + //For DelayFrameSwapping: use while loop to call multple mainui_rend_frame() until rend_swap_frame(u32 fb_r_sof1) + int counter = 0; + while (mainui_enabled && counter < 5) + { + counter++; + if (mainui_rend_frame()) + { + return true; + } + } + return false; } void emu_gles_init(int width, int height)