mirror of
https://github.com/yquake2/yquake2remaster.git
synced 2025-02-16 17:11:03 +00:00
Implement adaptive vsync.
Adaptive vsync is a often requested feauture and easy to implement. Set `r_vsync` to `2` to enable. This is untested because my system doesn't support it.
This commit is contained in:
parent
fc99e5456f
commit
19214d6049
3 changed files with 49 additions and 2 deletions
|
@ -193,6 +193,7 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
|
||||||
|
|
||||||
* **r_vsync**: Enables the vsync: frames are synchronized with
|
* **r_vsync**: Enables the vsync: frames are synchronized with
|
||||||
display refresh rate, should (but doesn't always) prevent tearing.
|
display refresh rate, should (but doesn't always) prevent tearing.
|
||||||
|
Set to `1` for normal vsync and `2` for adaptive vsync.
|
||||||
|
|
||||||
|
|
||||||
## Graphics (GL renderers only)
|
## Graphics (GL renderers only)
|
||||||
|
|
|
@ -130,7 +130,30 @@ int RI_PrepareForWindow(void)
|
||||||
*/
|
*/
|
||||||
void RI_SetVsync(void)
|
void RI_SetVsync(void)
|
||||||
{
|
{
|
||||||
SDL_GL_SetSwapInterval(r_vsync->value ? 1 : 0);
|
// Make sure that the user given
|
||||||
|
// value is SDL compatible...
|
||||||
|
int vsync = 0;
|
||||||
|
|
||||||
|
if (r_vsync->value == 1)
|
||||||
|
{
|
||||||
|
vsync = 1;
|
||||||
|
}
|
||||||
|
else if (r_vsync->value == 2)
|
||||||
|
{
|
||||||
|
vsync = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_GL_SetSwapInterval(vsync) == -1)
|
||||||
|
{
|
||||||
|
if (vsync == -1)
|
||||||
|
{
|
||||||
|
// Not every system supports adaptive
|
||||||
|
// vsync, fallback to normal vsync.
|
||||||
|
R_Printf(PRINT_ALL, "Failed to set adaptive vsync, reverting to normal vsync.\n");
|
||||||
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vsyncActive = SDL_GL_GetSwapInterval() != 0;
|
vsyncActive = SDL_GL_GetSwapInterval() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,30 @@ qboolean GL3_IsVsyncActive(void)
|
||||||
*/
|
*/
|
||||||
void GL3_SetVsync(void)
|
void GL3_SetVsync(void)
|
||||||
{
|
{
|
||||||
SDL_GL_SetSwapInterval(r_vsync->value ? 1 : 0);
|
// Make sure that the user given
|
||||||
|
// value is SDL compatible...
|
||||||
|
int vsync = 0;
|
||||||
|
|
||||||
|
if (r_vsync->value == 1)
|
||||||
|
{
|
||||||
|
vsync = 1;
|
||||||
|
}
|
||||||
|
else if (r_vsync->value == 2)
|
||||||
|
{
|
||||||
|
vsync = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SDL_GL_SetSwapInterval(vsync) == -1)
|
||||||
|
{
|
||||||
|
if (vsync == -1)
|
||||||
|
{
|
||||||
|
// Not every system supports adaptive
|
||||||
|
// vsync, fallback to normal vsync.
|
||||||
|
R_Printf(PRINT_ALL, "Failed to set adaptive vsync, reverting to normal vsync.\n");
|
||||||
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
vsyncActive = SDL_GL_GetSwapInterval() != 0;
|
vsyncActive = SDL_GL_GetSwapInterval() != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue