PDA

View Full Version : why there is an upper limite 60 fps for the frame rate?



shapeare
07-24-2012, 09:33 AM
I tried calculating the framerate of my program by placing the following code in the Idle function, but never can it exceed 60 fps. And I am sure that the draw call in the rendering loop takes less than 0.01s, so theoretical the framerate should be bigger than 100fps.



void CalculateFrameRate()
{
static float framesPerSecond = 0.0f; // This will store our fps
static float lastTimeFPS = 0.0f; // This will hold the time from the last frame
float currentTimeFPS = GetTickCount() * 0.001f;
++framesPerSecond;
if( currentTimeFPS - lastTimeFPS > 1.0f )
{
lastTimeFPS = currentTimeFPS;
framesPerSecond = 0;
}
}


static void Idle(void)
{
glutPostRedisplay();
CalculateFrameRate();
}

How to correctly measure the frame rate?

Dark Photon
07-24-2012, 10:06 AM
Except for testing perf, typically little reason to render faster than your monitor can display. To exceed that, turn off sync-to-vblank.

mhagain
07-24-2012, 11:51 AM
I'd just add that GetTickCount isn't a reliable measure of time, particularly where something like an FPS counter is concerned (particularly everywhere, in fact!) You typically get a resolution of 10ms to 16ms, but at 60fps each frame is going to be 16.6666... ms long, so that's a huge potential margin of error. If you want a reliable timer under Windows better off using QueryPerformanceCounter or timeGetTime (with timeBeginPeriod) instead.

arekkusu
07-24-2012, 12:36 PM
Except for testing perf, typically little reason to render faster than your monitor can display. To exceed that, turn off sync-to-vblank.

To expand on that: the operative word in "fps" is frame. If you turn off vsync, you are no longer presenting frames, you are presenting parts of frames. Really, zero fps.

Instead of benchmarking "how many times can I swap buffers per second", perhaps consider "how many milliseconds does my rendering take"? Which you can measure with good old glFinish, or EXT_timer_query.