From e68642fe1003467f1483dd8ddb2528cd3136042e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Tue, 6 Dec 2011 12:54:16 +0100 Subject: Added multi-screen support to hellowindow example. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I025de342952bffeffa0705eb4cfcf869f32241cc Reviewed-by: Jørgen Lind --- examples/opengl/hellowindow/hellowindow.cpp | 4 ++- examples/opengl/hellowindow/hellowindow.h | 2 +- examples/opengl/hellowindow/main.cpp | 39 +++++++++++++++++++++++------ 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 -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 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(); } -- cgit v1.2.3