Jump to content
  • Advertisement
Sign in to follow this  

FPS calculation

This topic is 4753 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a couple of questions related to the seemingly trivial task of calculating FPS for my application. I'm running the following code to calculate my frame rate: This is called once every frame. //update number of frames gs_FPScounter++; //no. seconds passed gs_nextSecond = timeGetTime() * 0.001f; if ( gs_nextSecond - gs_prevSecond > 1.0f ) { gs_prevSecond = gs_nextSecond; gs_FPS = gs_FPScounter; gs_FPScounter = 0; } I get, for my relatively simple app ( rotating cubes ), a frame rate of of around 67fps. two points 1. this is incredibly low given the hardware configuration I'm running it on ( P4m GF Go 5200 ).It should be higher. I've run D3D apps that give higher frame rates ( over 100 ) on my machine. 2. It could be that my refresh rate is bound to 60Hz(lap top screen won't go any higher), and I'm rendering using a double buffer and VSync. This still makes no sense as my FPS should be capped at 60fps.So why 67fps. Mark

Share this post


Link to post
Share on other sites
Advertisement
You might want to change this..
gs_prevSecond = gs_nextSecond;
to this..
gs_prevSecond += 1.0f;

Should be slightly more accurate. Other than that, everything looks fine. Have you tried disabling the refresh rate with..
Present.FullScreen_RefreshRateInHz = D3DPRESENT_INTERVAL_IMMEDIATE ?

I'm not sure what else (unless your rendering loop?) could cause problems.

Share this post


Link to post
Share on other sites
Quote:
Original post by MarkyMark
2. It could be that my refresh rate is bound to 60Hz(lap top screen won't go any higher), and I'm rendering using a double buffer and VSync. This still makes no sense as my FPS should be capped at 60fps.So why 67fps.


Could be because (gs_nextSecond - gs_prevSecond) won't be exactly 1.0, as you assume. It will more likely be a little bigger than that. So it should be:

gs_FPS = gs_FPScounter/(gl_NextSecond-gs_prevSecond);

Anyway, measuring your FPS with VSync on is not a good idea. Turn it off.

Share this post


Link to post
Share on other sites

I have'nt worked out why yet, but for some reason
changing gs_prevSecond = gs_nextSecond to gs_prevSecond += 1.0f
resulting in my FPS showing up as 1

Share this post


Link to post
Share on other sites
Make sure gs_prevSecond is initialized to timeGetTime() * 0.001f on startup.

edit:

It would have eventually caught up after a while. Possibly hours [smile]

Share this post


Link to post
Share on other sites
Thanks that did the job.

Its now capped at 60Hz which is what I would have expected from
my hardware configuration.

Now to try and measure the frame rate without VSync.


Mark

Share this post


Link to post
Share on other sites

some things still bother me.

I ran the demo by turning DOUBLE BUFFERING off in the pixel format
descriptor ( this is OpenGL ) and removing the SwapBuffer call
at the end of the game loop.

The frame goes up ( max 180fps at 800x400 ) but the display is
very jittery. I'm assuming this is to be expected. Am I right?

now for my point of confusion...

As I see it the situation is either
1) max frame rate of 60fps with double buffering turned on
2) max frame rate of 180fps with double buffering turned off, but jittery

but..

I'm running some of the D3D samples, and I'm getting very high
frame rates on some of them e.g 640fps on Text3D (w/o jitter ) and I don't understand how.




Share this post


Link to post
Share on other sites
fps = 1000 / Avg;
// Avg is the average time per frame. (in ms)
//To calculate avg...

//Nice-Code

tmr += timeneeded
cnt++;
if (cnt = 32) {avg = tmr & 31; tmr = 0; cnt = 0;}
fps = 1000 / avg;

//Just be sure to init avg to 1.

From,
Nice coder

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!