summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-12-06 12:54:16 +0100
committerQt by Nokia <qt-info@nokia.com>2011-12-06 20:14:10 +0100
commite68642fe1003467f1483dd8ddb2528cd3136042e (patch)
treedca602bb464398412c853f90aed000eb7ad38dc1 /examples/opengl
parente838cf644fe482d0ff04f2a32f081bc4b6e30297 (diff)
Added multi-screen support to hellowindow example.
Change-Id: I025de342952bffeffa0705eb4cfcf869f32241cc Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/hellowindow/hellowindow.cpp4
-rw-r--r--examples/opengl/hellowindow/hellowindow.h2
-rw-r--r--examples/opengl/hellowindow/main.cpp39
3 files changed, 36 insertions, 9 deletions
diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp
index 2903ddd743..742de251f4 100644
--- a/examples/opengl/hellowindow/hellowindow.cpp
+++ b/examples/opengl/hellowindow/hellowindow.cpp
@@ -46,11 +46,13 @@
#include <qmath.h>
-Renderer::Renderer(const QSurfaceFormat &format, Renderer *share)
+Renderer::Renderer(const QSurfaceFormat &format, Renderer *share, QScreen *screen)
: m_initialized(false)
, m_format(format)
{
m_context = new QOpenGLContext(this);
+ if (screen)
+ m_context->setScreen(screen);
m_context->setFormat(format);
if (share)
m_context->setShareContext(share->m_context);
diff --git a/examples/opengl/hellowindow/hellowindow.h b/examples/opengl/hellowindow/hellowindow.h
index 82d275aa68..b257cef20f 100644
--- a/examples/opengl/hellowindow/hellowindow.h
+++ b/examples/opengl/hellowindow/hellowindow.h
@@ -54,7 +54,7 @@ class Renderer : public QObject
{
Q_OBJECT
public:
- Renderer(const QSurfaceFormat &format, Renderer *share = 0);
+ Renderer(const QSurfaceFormat &format, Renderer *share = 0, QScreen *screen = 0);
QSurfaceFormat format() const { return m_format; }
diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp
index 4a11aa1c7a..36cbc414dd 100644
--- a/examples/opengl/hellowindow/main.cpp
+++ b/examples/opengl/hellowindow/main.cpp
@@ -72,15 +72,13 @@ int main(int argc, char **argv)
windowA->setWindowTitle(QLatin1String("Thread A - Context A"));
windowA->setVisible(true);
- QThread *renderThread = 0;
+ QList<QThread *> renderThreads;
if (multipleWindows) {
Renderer *rendererB = new Renderer(format, rendererA);
- renderThread = new QThread;
+ QThread *renderThread = new QThread;
rendererB->moveToThread(renderThread);
- renderThread->start();
-
- QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), renderThread, SLOT(quit()));
+ renderThreads << renderThread;
HelloWindow *windowB = new HelloWindow(rendererA);
windowB->setGeometry(QRect(center, windowSize).translated(delta / 2, 0));
@@ -91,10 +89,37 @@ int main(int argc, char **argv)
windowC->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, windowSize.height() + delta));
windowC->setWindowTitle(QLatin1String("Thread B - Context B"));
windowC->setVisible(true);
+
+ for (int i = 1; i < QGuiApplication::screens().size(); ++i) {
+ QScreen *screen = QGuiApplication::screens().at(i);
+ Renderer *renderer = new Renderer(format, rendererA, screen);
+
+ renderThread = new QThread;
+ renderer->moveToThread(renderThread);
+ renderThreads << renderThread;
+
+ QRect screenGeometry = screen->availableGeometry();
+ QPoint center = screenGeometry.center();
+
+ QSize windowSize = screenGeometry.size() * 0.8;
+
+ HelloWindow *window = new HelloWindow(renderer);
+ window->setScreen(screen);
+ window->setGeometry(QRect(center, windowSize).translated(-windowSize.width() / 2, -windowSize.height() / 2));
+
+ QChar id = QChar('B' + i);
+ window->setWindowTitle(QLatin1String("Thread ") + id + QLatin1String(" - Context ") + id);
+ window->setVisible(true);
+ }
+ }
+
+ for (int i = 0; i < renderThreads.size(); ++i) {
+ QObject::connect(qGuiApp, SIGNAL(lastWindowClosed()), renderThreads.at(i), SLOT(quit()));
+ renderThreads.at(i)->start();
}
app.exec();
- if (multipleWindows)
- renderThread->wait();
+ for (int i = 0; i < renderThreads.size(); ++i)
+ renderThreads.at(i)->wait();
}