Use GLFW swap interval for force vsync to monitor
This commit is contained in:
parent
9861a02ed1
commit
c54e6323a7
@ -92,14 +92,19 @@ int main()
|
|||||||
|
|
||||||
glfwSetWindowUserPointer(window, static_cast<void *>(&game));
|
glfwSetWindowUserPointer(window, static_cast<void *>(&game));
|
||||||
|
|
||||||
|
f32 startTime = static_cast<f32>(glfwGetTime());
|
||||||
f32 secondsElapsed = 0.0f; // Time between current frame and last frame
|
f32 secondsElapsed = 0.0f; // Time between current frame and last frame
|
||||||
|
|
||||||
|
#if 0
|
||||||
// TODO(doyle): Get actual monitor refresh rate
|
// TODO(doyle): Get actual monitor refresh rate
|
||||||
i32 monitorRefreshHz = 60;
|
i32 monitorRefreshHz = 60;
|
||||||
f32 targetSecondsPerFrame = 1.0f / static_cast<f32>(monitorRefreshHz);
|
f32 targetSecondsPerFrame = 1.0f / static_cast<f32>(monitorRefreshHz);
|
||||||
f32 startTime = static_cast<f32>(glfwGetTime());
|
#else
|
||||||
|
// TODO(doyle): http://gafferongames.com/game-physics/fix-your-timestep/
|
||||||
//glfwSwapInterval(1);
|
// NOTE(doyle): Prevent glfwSwapBuffer until a vertical retrace has
|
||||||
|
// occurred, i.e. limit framerate to monitor refresh rate
|
||||||
|
glfwSwapInterval(1);
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Main game loop */
|
/* Main game loop */
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
@ -123,12 +128,14 @@ int main()
|
|||||||
f32 endTime = static_cast<f32>(glfwGetTime());
|
f32 endTime = static_cast<f32>(glfwGetTime());
|
||||||
secondsElapsed = endTime - startTime;
|
secondsElapsed = endTime - startTime;
|
||||||
|
|
||||||
|
#if 0
|
||||||
// TODO(doyle): Busy waiting, should sleep
|
// TODO(doyle): Busy waiting, should sleep
|
||||||
while (secondsElapsed < targetSecondsPerFrame)
|
while (secondsElapsed < targetSecondsPerFrame)
|
||||||
{
|
{
|
||||||
endTime = static_cast<f32>(glfwGetTime());
|
endTime = static_cast<f32>(glfwGetTime());
|
||||||
secondsElapsed = endTime - startTime;
|
secondsElapsed = endTime - startTime;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
LOCAL_PERSIST f32 titleUpdateFrequencyInSeconds = 0.5f;
|
LOCAL_PERSIST f32 titleUpdateFrequencyInSeconds = 0.5f;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user