Skip to content

Commit

Permalink
add VSync toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisotura committed Sep 1, 2019
1 parent 5b51034 commit abb0626
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 3 deletions.
26 changes: 25 additions & 1 deletion src/libui_sdl/DlgVideoSettings.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

{
Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 2 additions & 0 deletions src/libui_sdl/PlatformConfig.cpp
Expand Up @@ -43,6 +43,7 @@ int ScreenSizing;
int ScreenFilter;

int ScreenUseGL;
int ScreenVSync;
int ScreenRatio;

int LimitFPS;
Expand Down Expand Up @@ -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},
Expand Down
1 change: 1 addition & 0 deletions src/libui_sdl/PlatformConfig.h
Expand Up @@ -54,6 +54,7 @@ extern int ScreenSizing;
extern int ScreenFilter;

extern int ScreenUseGL;
extern int ScreenVSync;
extern int ScreenRatio;

extern int LimitFPS;
Expand Down
18 changes: 16 additions & 2 deletions src/libui_sdl/main.cpp
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit abb0626

Please sign in to comment.