Advice to lock frame rate

Started by
10 comments, last by eduardo_costa 10 years, 3 months ago

I think I found the better way, looking at the function SDL_SetVideoMode (which I think doesn't exist in SDL2) I notice a flag that I didn't see before SDL_RENDERER_PRESENTVSYNC , I just add it to my renderer creation function:

renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);

Now the fps is stable 60. (But I wonder if this vsync can be still disable by the user)

This is a bad idea. If your movement rate is based on fps. Enabling vsync will not do what you want. This is because vsync is not quaranteed to be 60hz. It depends on your gpu and display and settings. If you have a 75hz or 120hz display and your gpu supports it and have it enabled then with vsync your game will run at 75fps or 120fps. Or even worse if you are using a 1080i tv as a screen with 30hz progressive setting it will lock the fps to 30. And as you had already guessed users indeed can disable vsync from the driver settings.

You really need to use high preformance timers. Either by forcing updates to 60hz or adjusting movement rate with deltatime.

Advertisement

The purpose of multiple updates before rendering is splitting work in different steps before the render callbacks.

In a more hi-level solution, one could use different time-slices for different tasks and optimize the loop for a given application.

Like:

0ms X ms 16ms

Input Animation Update Physics Rendering Flush

Also, locking the rendering code in 60fps will avoid calling API commands like clear, shaders, swapbuffers, texture binding, ... in a rate greater than it is needed.

I had a great change in perfomance when I reduced the rate of calling of these commands.

In a worst case scenario locking at 40 or 30fps gave me more time to update other non-rendering stuff and the application performed even better!

This topic is closed to new replies.

Advertisement