|
KGLLib
|
Utility class that measures FPS. More...
#include <fpscounter.h>
Public Member Functions | |
| FPSCounter () | |
| void | nextFrame () |
| void | resetTimeElapsed () |
| float | fps () const |
| QString | fpsString () const |
| float | timeElapsed () |
| float | totalTimeElapsed () |
Protected Attributes | |
| QTime | mTime |
| int | mFrames |
| float | mFPS |
| float | mTimeElapsed |
| float | mTotalTimeElapsed |
| QTime | mLastTime |
Utility class that measures FPS.
FPSCounter is a utility class that keeps track of FPS (frames per second) of your application. It can be a simple performance measurement tool.
Using FPSCounter is simple: if you're using GLWidget then all you have to do is calling fps() or fpsString() method to find out the current FPS. You can also call timeElapsed() to find out how much time has elapsed since last frame was rendered. This could be useful e.g. in animations where an object has a fixed speed and you multiply it by the elapsed time every frame to find out how much the object should be moved.
If you don't use GLWidget then you need to call nextFrame() every time that another frame is rendered.
The fps value is recalculated once a second.
You can also use totalTimeElapsed() to find out how much time has elapsed since nextFrame() was called the very first time.
| KGLLib::FPSCounter::FPSCounter | ( | ) |
Creates new FPS counter. The counter isn't started until nextFrame() is called for the first time.
| float KGLLib::FPSCounter::fps | ( | ) | const [inline] |
Returns the current FPS value.
Note that the value is recalculated by nextFrame() about once a second.
Referenced by fpsString().
| QString KGLLib::FPSCounter::fpsString | ( | ) | const |
| void KGLLib::FPSCounter::nextFrame | ( | ) |
This method should be called whenever a frame is rendered. It increases the internal counters and updates the calculated FPS value once a second.
Referenced by KGLLib::GLWidget::paintGL().
| float KGLLib::FPSCounter::timeElapsed | ( | ) | [inline] |
Returnes time elapsed between last two calls to nextFrame() method. Usually that gives you the time elapsed since last frame and could be used e.g. for animation purposes.
The return value is in seconds, thus a value of 0.075 would indicate that 75 milliseconds have elapsed.
| float KGLLib::FPSCounter::totalTimeElapsed | ( | ) | [inline] |
Returns amount of time that has elapsed since the first call to nextFrame().
1.7.4