diff options
author | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-10-08 16:57:07 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@digia.com> | 2014-10-10 13:17:13 +0200 |
commit | eaf04207bddd778380cae178db1bf3cce7d6b9df (patch) | |
tree | 0f1f9ab9a8a2ed402ba03a28e6318ed2f8962c0b /examples/opengl/threadedqopenglwidget/main.cpp | |
parent | bf73ab490de127d1a22cb31acb2e251b1daef328 (diff) | |
download | qtbase-eaf04207bddd778380cae178db1bf3cce7d6b9df.tar.gz |
Improve threadedqopenglwidget example.
Retrieve vendor/renderer name similar to context info
and exclude renderers that do not support threaded
Open GL (ANGLE/noveau).
Change-Id: I690c2fc277538bf28bf1f6032c2e017ede15e434
Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
Diffstat (limited to 'examples/opengl/threadedqopenglwidget/main.cpp')
-rw-r--r-- | examples/opengl/threadedqopenglwidget/main.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp index 75b7f5e46f..2c94469b7c 100644 --- a/examples/opengl/threadedqopenglwidget/main.cpp +++ b/examples/opengl/threadedqopenglwidget/main.cpp @@ -40,10 +40,19 @@ #include <QApplication> #include <QMainWindow> +#include <QDesktopWidget> #include <QSurfaceFormat> +#include <QOpenGLContext> #include "mainwindow.h" #include "glwidget.h" +static QString getGlString(QOpenGLFunctions *functions, GLenum name) +{ + if (const GLubyte *p = functions->glGetString(name)) + return QString::fromLatin1(reinterpret_cast<const char *>(p)); + return QString(); +} + int main( int argc, char ** argv ) { QApplication a( argc, argv ); @@ -54,20 +63,38 @@ int main( int argc, char ** argv ) // Two top-level windows with two QOpenGLWidget children in each. // The rendering for the four QOpenGLWidgets happens on four separate threads. - MainWindow mw1; - mw1.setMinimumSize(800, 400); - mw1.show(); + GLWidget topLevelGlWidget; + QPoint pos = QApplication::desktop()->availableGeometry(&topLevelGlWidget).topLeft() + QPoint(200, 200); + topLevelGlWidget.setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example top level")); + topLevelGlWidget.resize(200, 200); + topLevelGlWidget.move(pos); + topLevelGlWidget.show(); + + const QString glInfo = getGlString(topLevelGlWidget.context()->functions(), GL_VENDOR) + + QLatin1Char('/') + getGlString(topLevelGlWidget.context()->functions(), GL_RENDERER); + + const bool supportsThreading = !glInfo.contains(QLatin1String("nouveau"), Qt::CaseInsensitive) + && !glInfo.contains(QLatin1String("ANGLE"), Qt::CaseInsensitive); + + const QString toolTip = supportsThreading ? glInfo : glInfo + QStringLiteral("\ndoes not support threaded OpenGL."); + topLevelGlWidget.setToolTip(toolTip); + + QScopedPointer<MainWindow> mw1; QScopedPointer<MainWindow> mw2; - if (!QApplication::arguments().contains(QStringLiteral("--single"))) { + if (supportsThreading && !QApplication::arguments().contains(QStringLiteral("--single"))) { + pos += QPoint(100, 100); + mw1.reset(new MainWindow); + mw1->setToolTip(toolTip); + mw1->move(pos); + mw1->setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example #1")); + mw1->show(); + pos += QPoint(100, 100); mw2.reset(new MainWindow); - mw2->setMinimumSize(800, 400); + mw2->setToolTip(toolTip); + mw2->move(pos); + mw2->setWindowTitle(QStringLiteral("Threaded QOpenGLWidget example #2")); mw2->show(); - - // And a top-level. - GLWidget *bonus = new GLWidget(0); - bonus->resize(200, 200); - bonus->show(); } return a.exec(); |