add VSync toggle

This commit is contained in:
Arisotura 2019-09-01 20:20:22 +02:00
parent 5b51034436
commit abb06269a1
4 changed files with 44 additions and 3 deletions

View File

@ -39,12 +39,14 @@ uiWindow* win;
uiRadioButtons* rbRenderer;
uiCheckbox* cbGLDisplay;
uiCheckbox* cbVSync;
uiCheckbox* cbThreaded3D;
uiCombobox* cbResolution;
uiCheckbox* cbAntialias;
int old_renderer;
int old_gldisplay;
int old_vsync;
int old_threaded3D;
int old_resolution;
int old_antialias;
@ -89,6 +91,11 @@ void RevertSettings()
{
Config::ScreenUseGL = old_gldisplay;
}
if (old_vsync != Config::ScreenVSync)
{
Config::ScreenVSync = old_vsync;
ApplyNewSettings(4);
}
if (old_usegl != new_usegl)
{
apply2 = true;
@ -134,17 +141,25 @@ void OnRendererChanged(uiRadioButtons* rb, void* blarg)
ApplyNewSettings(2);
else
ApplyNewSettings(3);
uiControlSetFocus(uiControl(win));
}
void OnGLDisplayChanged(uiCheckbox* cb, void* blarg)
{
Config::ScreenUseGL = uiCheckboxChecked(cb);
if (Config::ScreenUseGL) uiControlEnable(uiControl(cbVSync));
else uiControlDisable(uiControl(cbVSync));
ApplyNewSettings(2);
uiControlSetFocus(uiControl(win));
}
void OnVSyncChanged(uiCheckbox* cb, void* blarg)
{
Config::ScreenVSync = uiCheckboxChecked(cb);
ApplyNewSettings(4);
}
void OnThreaded3DChanged(uiCheckbox* cb, void* blarg)
{
Config::Threaded3D = uiCheckboxChecked(cb);
@ -232,6 +247,10 @@ void Open()
cbGLDisplay = uiNewCheckbox("OpenGL display");
uiCheckboxOnToggled(cbGLDisplay, OnGLDisplayChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(cbGLDisplay), 0);
cbVSync = uiNewCheckbox("VSync");
uiCheckboxOnToggled(cbVSync, OnVSyncChanged, NULL);
uiBoxAppend(in_ctrl, uiControl(cbVSync), 0);
}
{
@ -300,17 +319,22 @@ void Open()
old_renderer = Config::_3DRenderer;
old_gldisplay = Config::ScreenUseGL;
old_vsync = Config::ScreenVSync;
old_threaded3D = Config::Threaded3D;
old_resolution = Config::GL_ScaleFactor;
old_antialias = Config::GL_Antialias;
uiCheckboxSetChecked(cbGLDisplay, Config::ScreenUseGL);
uiCheckboxSetChecked(cbVSync, Config::ScreenVSync);
uiCheckboxSetChecked(cbThreaded3D, Config::Threaded3D);
uiComboboxSetSelected(cbResolution, Config::GL_ScaleFactor-1);
//uiCheckboxSetChecked(cbAntialias, Config::GL_Antialias);
uiRadioButtonsSetSelected(rbRenderer, Config::_3DRenderer);
UpdateControls();
if (Config::ScreenUseGL) uiControlEnable(uiControl(cbVSync));
else uiControlDisable(uiControl(cbVSync));
uiControlShow(uiControl(win));
}

View File

@ -43,6 +43,7 @@ int ScreenSizing;
int ScreenFilter;
int ScreenUseGL;
int ScreenVSync;
int ScreenRatio;
int LimitFPS;
@ -118,6 +119,7 @@ ConfigEntry PlatformConfigFile[] =
{"ScreenFilter", 0, &ScreenFilter, 1, NULL, 0},
{"ScreenUseGL", 0, &ScreenUseGL, 1, NULL, 0},
{"ScreenVSync", 0, &ScreenVSync, 0, NULL, 0},
{"ScreenRatio", 0, &ScreenRatio, 0, NULL, 0},
{"LimitFPS", 0, &LimitFPS, 1, NULL, 0},

View File

@ -54,6 +54,7 @@ extern int ScreenSizing;
extern int ScreenFilter;
extern int ScreenUseGL;
extern int ScreenVSync;
extern int ScreenRatio;
extern int LimitFPS;

View File

@ -988,7 +988,8 @@ int EmuThreadFunc(void* burp)
uiAreaQueueRedrawAll(MainDrawArea);
bool limitfps = Config::LimitFPS && !HotkeyDown(HK_FastForward);
SPU::Sync(limitfps);
bool vsync = Config::ScreenVSync && Screen_UseGL;
SPU::Sync(limitfps || vsync);
float framerate = (1000.0f * nlines) / (60.0f * 263.0f);
@ -2260,6 +2261,19 @@ void ApplyNewSettings(int type)
GPU3D::InitRenderer(Screen_UseGL);
if (Screen_UseGL) uiGLMakeContextCurrent(NULL);
}
else if (type == 4) // vsync
{
if (Screen_UseGL)
{
uiGLMakeContextCurrent(GLContext);
uiGLSetVSync(Config::ScreenVSync);
uiGLMakeContextCurrent(NULL);
}
else
{
// TODO eventually: VSync for non-GL screen?
}
}
EmuRunning = prevstatus;
}
@ -2469,7 +2483,7 @@ void CreateMainWindow(bool opengl)
if (opengl_good)
{
uiGLMakeContextCurrent(GLContext);
uiGLSetVSync(0); // TODO: make configurable?
uiGLSetVSync(Config::ScreenVSync);
if (!GLScreen_Init()) opengl_good = false;
if (opengl_good)
{