-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathframeratecounter.cpp
More file actions
36 lines (31 loc) · 899 Bytes
/
frameratecounter.cpp
File metadata and controls
36 lines (31 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "frameratecounter.h"
FrameRateCounter::FrameRateCounter(QQuickItem *parent) :
QQuickItem3D(parent),
m_fps(0.0),
m_usedSurface(0)
{
m_fpsTimer.restart();
}
double FrameRateCounter::fps() const
{
return m_fps;
}
void FrameRateCounter::drawItem(QGLPainter *painter)
{
Q_UNUSED(painter)
if(!m_usedSurface) {
m_usedSurface = painter->currentSurface();
}
if(m_usedSurface != painter->currentSurface()) {
return; // If we are not painting to the original surface, we might be in the other 3D frame, so return
}
int sinceLastTime = m_fpsTimer.elapsed();
if(sinceLastTime < 10) { // We are capped at 60 FPS, so anything lower is ignored
return;
}
m_fpsTimer.restart();
double currentFps = 1000.0 / sinceLastTime;
m_fps = 0.8*m_fps + 0.2 * currentFps;
emit fpsChanged(m_fps);
sinceLastTime = 0.0;
}