multiwindow: Base fps on number of frames swapped, not timing of last frame
Change-Id: I582e4f35b2702ac3792c5641fa10f74a79351bed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
16a421aa83
commit
0f8c2ab3d8
@ -69,12 +69,15 @@
|
|||||||
|
|
||||||
class Window : public QOpenGLWindow
|
class Window : public QOpenGLWindow
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
Window(int n) : idx(n) {
|
Window(int n) : idx(n) {
|
||||||
r = g = b = fps = 0;
|
r = g = b = fps = 0;
|
||||||
y = 0;
|
y = 0;
|
||||||
resize(200, 200);
|
resize(200, 200);
|
||||||
t2.start();
|
|
||||||
|
connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped()));
|
||||||
|
fpsTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void paintGL() {
|
void paintGL() {
|
||||||
@ -106,20 +109,27 @@ public:
|
|||||||
if (y > height() - 20)
|
if (y > height() - 20)
|
||||||
y = 20;
|
y = 20;
|
||||||
|
|
||||||
if (t2.elapsed() > 1000) {
|
|
||||||
fps = 1000.0 / t.elapsed();
|
|
||||||
t2.restart();
|
|
||||||
}
|
|
||||||
t.restart();
|
|
||||||
|
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void frameSwapped() {
|
||||||
|
++framesSwapped;
|
||||||
|
if (fpsTimer.elapsed() > 1000) {
|
||||||
|
fps = qRound(framesSwapped * (1000.0 / fpsTimer.elapsed()));
|
||||||
|
framesSwapped = 0;
|
||||||
|
fpsTimer.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int idx;
|
int idx;
|
||||||
GLfloat r, g, b, fps;
|
GLfloat r, g, b;
|
||||||
int y;
|
int y;
|
||||||
QElapsedTimer t, t2;
|
|
||||||
|
int framesSwapped;
|
||||||
|
QElapsedTimer fpsTimer;
|
||||||
|
int fps;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -167,3 +177,5 @@ int main(int argc, char **argv)
|
|||||||
qDeleteAll(extraWindows);
|
qDeleteAll(extraWindows);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "main.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user