Hello,
I have a game loop that updates & renders every ~16 ms. I am running the game on a 144Hz monitor. I am trying different configurations of SDL_GL_SetSwapInterval, event poll placement and SDL_GL_SwapWindow placement within the loop and I am having a hard time figuring out what is optimal. Here are some combinations and the results in Nvidia’s Performance Overlay:
SDL_GL_SetSwapInterval(1);
t1 = get_time();
while (game) {
if (get_time - t1 >= 16.667) {
t1 = get_time();
while (SDL_PollEvent...) {
//blah
}
}
RenderLotsofStuff();
SDL_GL_SwapWindow(gWindow);
}
}
Overlay reports 60fps and Render Latency fluctuates around 17 ms. GPU: ~40%. Setting SDL_GL_SetSwapInterval to zero doesn’t affect those results.
Now I’m moving SDL_GL_SwapWindow so that it’s executed all the time, not every 16ms:
SDL_GL_SetSwapInterval(1);
t1 = get_time();
while (game) {
if (get_time - t1 >= 16.667) {
t1 = get_time();
while (SDL_PollEvent...) {
//blah
}
}
RenderStuff();
}
SDL_GL_SwapWindow(gWindow);
}
Results now are 144 fps, and Render latency fluctuates between 1.5 - 17 ms. GPU: ~40%
Setting SDL_GL_SetSwapInterval to zero: Fps are ~600 and Render Latency around 2 ms. GPU: ~60%
I have 2 main questions:
-
I have trouble understanding what SDL_GL_SwapWindow exactly does (I mean, aside from showing up stuff you drew). Does it enforce some delay? I am not sure what the “right” position for it is inside the code. Are the results I posted “inaccurate/confused” and they fail to measure accurately what happens under the hood?
-
Is it a good practice to poll for events every 1/60th of a second, or is it fine just leaving it run all the time in the while() loop?
Thanks!