mirror of https://github.com/encounter/SDL.git
Calculate simulated vsync interval based on display refresh rate
This commit is contained in:
parent
208964f038
commit
e2753e19e8
|
@ -933,6 +933,26 @@ static SDL_RenderLineMethod SDL_GetRenderLineMethod()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SDL_CalculateSimulatedVSyncInterval(SDL_Renderer *renderer, SDL_Window *window)
|
||||||
|
{
|
||||||
|
/* FIXME: SDL refresh rate API should return numerator/denominator */
|
||||||
|
int refresh_rate = 0;
|
||||||
|
int display_index = SDL_GetWindowDisplayIndex(window);
|
||||||
|
SDL_DisplayMode mode;
|
||||||
|
|
||||||
|
if (display_index < 0) {
|
||||||
|
display_index = 0;
|
||||||
|
}
|
||||||
|
if (SDL_GetDesktopDisplayMode(display_index, &mode) == 0) {
|
||||||
|
refresh_rate = mode.refresh_rate;
|
||||||
|
}
|
||||||
|
if (!refresh_rate) {
|
||||||
|
/* Pick a good default refresh rate */
|
||||||
|
refresh_rate = 60;
|
||||||
|
}
|
||||||
|
renderer->simulate_vsync_interval = (1000 / refresh_rate);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_Renderer *
|
SDL_Renderer *
|
||||||
SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
|
SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
|
||||||
{
|
{
|
||||||
|
@ -1022,6 +1042,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
|
||||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SDL_CalculateSimulatedVSyncInterval(renderer, window);
|
||||||
|
|
||||||
VerifyDrawQueueFunctions(renderer);
|
VerifyDrawQueueFunctions(renderer);
|
||||||
|
|
||||||
|
@ -4273,7 +4294,7 @@ static void
|
||||||
SDL_RenderSimulateVSync(SDL_Renderer * renderer)
|
SDL_RenderSimulateVSync(SDL_Renderer * renderer)
|
||||||
{
|
{
|
||||||
Uint32 now, elapsed;
|
Uint32 now, elapsed;
|
||||||
const Uint32 interval = (1000 / 60); /* FIXME: What FPS? */
|
const Uint32 interval = renderer->simulate_vsync_interval;
|
||||||
|
|
||||||
if (!interval) {
|
if (!interval) {
|
||||||
/* We can't do sub-ms delay, so just return here */
|
/* We can't do sub-ms delay, so just return here */
|
||||||
|
|
|
@ -211,6 +211,7 @@ struct SDL_Renderer
|
||||||
/* Whether we should simulate vsync */
|
/* Whether we should simulate vsync */
|
||||||
SDL_bool wanted_vsync;
|
SDL_bool wanted_vsync;
|
||||||
SDL_bool simulate_vsync;
|
SDL_bool simulate_vsync;
|
||||||
|
Uint32 simulate_vsync_interval;
|
||||||
Uint32 last_present;
|
Uint32 last_present;
|
||||||
|
|
||||||
/* The logical resolution for rendering */
|
/* The logical resolution for rendering */
|
||||||
|
|
Loading…
Reference in New Issue