[macOS] Fix DelayFrameSwapping and optimise Vsync logic (#307)

* Support macOS 10.15 and 11
* Enable VSync option on macOS. Use "swapOnVSync" logic from other wsi
* Limit `mainui_rend_frame()` to 5 iterations max: 4 renders and the final swap
This commit is contained in:
vkedwardli 2021-08-24 17:43:19 +08:00 committed by GitHub
parent ce58ba3472
commit 7a33ae35e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 17 deletions

View File

@ -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");

View File

@ -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()
}
}
}

View File

@ -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);

View File

@ -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)