summaryrefslogtreecommitdiffstats
path: root/examples/opengl/hellowindow/main.cpp
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-08-18 10:50:18 +0200
committerPaul Olav Tvete <paul.tvete@nokia.com>2011-08-19 13:57:30 +0200
commit66d9b4d2f843205e56550e631d82184d20f7038e (patch)
tree9a22bfb729bfc3d9e4f4d09cc6ff0bd80d493468 /examples/opengl/hellowindow/main.cpp
parent9db6c348df79729ebba5069ccd5e5cb960da4000 (diff)
Make the hellowindow example multi-threaded to stress the GL backend.
Change-Id: I9e158c0889b050f9ed76ea21176102fc792eef83 Reviewed-on: http://codereview.qt.nokia.com/3150 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
Diffstat (limited to 'examples/opengl/hellowindow/main.cpp')
-rw-r--r--examples/opengl/hellowindow/main.cpp40
1 files changed, 36 insertions, 4 deletions
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
index af5943adf46..b247807019c 100644
--- a/examples/opengl/hellowindow/main.cpp
+++ b/examples/opengl/hellowindow/main.cpp
@@ -1,4 +1,6 @@
#include <QGuiApplication>
+#include <QScreen>
+#include <QThread>
#include "hellowindow.h"
@@ -6,13 +8,43 @@ int main(int argc, char **argv)
{
QGuiApplication app(argc, argv);
- Renderer renderer;
+ QScreen *screen = QGuiApplication::primaryScreen();
- HelloWindow windowA(&renderer);
+ QRect screenGeometry = screen->availableGeometry();
+
+ QSurfaceFormat format;
+ format.setDepthBufferSize(16);
+ format.setSamples(4);
+
+ QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80);
+ QSize windowSize(400, 320);
+ int delta = 40;
+
+ Renderer rendererA(format);
+ Renderer rendererB(format, &rendererA);
+
+ QThread renderThread;
+ rendererB.moveToThread(&renderThread);
+ renderThread.start();
+
+ QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), &renderThread, SLOT(quit()));
+
+ HelloWindow windowA(&rendererA);
+ windowA.setGeometry(QRect(center, windowSize).translated(-windowSize.width() - delta / 2, 0));
+ windowA.setWindowTitle(QLatin1String("Thread A - Context A"));
windowA.setVisible(true);
- HelloWindow windowB(&renderer);
+ HelloWindow windowB(&rendererA);
+ windowB.setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
+ windowB.setWindowTitle(QLatin1String("Thread A - Context A"));
windowB.setVisible(true);
- return app.exec();
+ HelloWindow windowC(&rendererB);
+ windowC.setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
+ windowC.setWindowTitle(QLatin1String("Thread B - Context B"));
+ windowC.setVisible(true);
+
+ app.exec();
+
+ renderThread.wait();
}