Implement vid_displayrefreshrate to override the displays refresh rate.

Modern LCD displays often haven't itegral refresh rates like 60hz but
fractional ones  like 59.95hz. SDL communicates the refresh rate as
integer. On X11 the rate is rounded up or down with round(), but on
Windows it's (at least on my system with an AMD Radeon) truncated...
So on an 59.95hz display it's just 59hz, Quake II renders 0.95 frames
too few and the user sees microstutters.

And return the actual / requested display frame rate increased by one
to work around inaccuracies in Quake IIs internal timing. It should be
a problem if we're running a little bit too fast.

This is belived to fix at least a part of issue #277.

Refreshrate 2
This commit is contained in:
Yamagi Burmeister 2018-02-12 17:54:02 +01:00
parent f0240af308
commit 832f3f6497

View file

@ -56,15 +56,18 @@ static SDL_Surface* window = NULL;
// some compatibility defines
#define SDL_SRCCOLORKEY SDL_TRUE
#define SDL_OPENGL SDL_WINDOW_OPENGL
#endif
cvar_t *vid_displayrefreshrate;
/*
* Initializes the SDL video subsystem
*/
int
GLimp_Init(void)
{
vid_displayrefreshrate = Cvar_Get("vid_displayrefreshrate", "-1", CVAR_ARCHIVE);
if (!SDL_WasInit(SDL_INIT_VIDEO))
{
@ -406,6 +409,11 @@ int glimp_refreshRate = -1;
*/
int GLimp_GetRefreshRate(void)
{
if (vid_displayrefreshrate->value > -1)
{
glimp_refreshRate = ceil(vid_displayrefreshrate->value);
}
#if SDL_VERSION_ATLEAST(2, 0, 0)
// do this only once, assuming people don't change their display settings
@ -426,6 +434,13 @@ int GLimp_GetRefreshRate(void)
}
}
/* The value reported by SDL may be one frame too low, for example
on my old Radeon R7 360 the driver returns 59hz for my 59.95hz
display. And Quake II isn't that accurate, we loose a little bit
here and there. Since it doesn't really hurt if we're running a
litte bit too fast just return one frame more than we really have. */
glimp_refreshRate++;
return glimp_refreshRate;
#else
// Asume 60hz.