summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-08-24 12:14:59 +0200
committerTor Arne Vestbø <tor.arne.vestbo@theqtcompany.com>2016-08-24 12:39:12 +0000
commit0f8c2ab3d89dd49d89ae53cfefa83e38ea3c3c17 (patch)
tree4665eb48311b2878bf6ac47e40ec029ab42ec0bb /tests
parent16a421aa834dde5b8dd276444718053b8842f894 (diff)
multiwindow: Base fps on number of frames swapped, not timing of last frame
Change-Id: I582e4f35b2702ac3792c5641fa10f74a79351bed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/manual/qopenglwindow/multiwindow/main.cpp30
1 files changed, 21 insertions, 9 deletions
diff --git a/tests/manual/qopenglwindow/multiwindow/main.cpp b/tests/manual/qopenglwindow/multiwindow/main.cpp
index 47616ded0f..7c4b143cf9 100644
--- a/tests/manual/qopenglwindow/multiwindow/main.cpp
+++ b/tests/manual/qopenglwindow/multiwindow/main.cpp
@@ -69,12 +69,15 @@
class Window : public QOpenGLWindow
{
+ Q_OBJECT
public:
Window(int n) : idx(n) {
r = g = b = fps = 0;
y = 0;
resize(200, 200);
- t2.start();
+
+ connect(this, SIGNAL(frameSwapped()), SLOT(frameSwapped()));
+ fpsTimer.start();
}
void paintGL() {
@@ -106,20 +109,27 @@ public:
if (y > height() - 20)
y = 20;
- if (t2.elapsed() > 1000) {
- fps = 1000.0 / t.elapsed();
- t2.restart();
- }
- t.restart();
-
update();
}
+public slots:
+ void frameSwapped() {
+ ++framesSwapped;
+ if (fpsTimer.elapsed() > 1000) {
+ fps = qRound(framesSwapped * (1000.0 / fpsTimer.elapsed()));
+ framesSwapped = 0;
+ fpsTimer.restart();
+ }
+ }
+
private:
int idx;
- GLfloat r, g, b, fps;
+ GLfloat r, g, b;
int y;
- QElapsedTimer t, t2;
+
+ int framesSwapped;
+ QElapsedTimer fpsTimer;
+ int fps;
};
int main(int argc, char **argv)
@@ -167,3 +177,5 @@ int main(int argc, char **argv)
qDeleteAll(extraWindows);
return r;
}
+
+#include "main.moc"