summaryrefslogtreecommitdiffstats
path: root/examples/opengl
diff options
context:
space:
mode:
authorFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-10-20 19:12:23 +0200
committerFrederik Gladhorn <frederik.gladhorn@theqtcompany.com>2014-10-20 19:12:25 +0200
commit3361fcbc28be96262d22fd2b024c85fbcbc61462 (patch)
tree48976f337b3885971dc1976b9a27cec5e7dfa2ec /examples/opengl
parentdc612acdc6577594c8f61345cea2de549d7aae34 (diff)
parent5e342f6f041208d142d97202f61179d7163eb773 (diff)
Merge remote-tracking branch 'origin/5.4' into dev
Diffstat (limited to 'examples/opengl')
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.cpp2
-rw-r--r--examples/opengl/threadedqopenglwidget/glwidget.h2
-rw-r--r--examples/opengl/threadedqopenglwidget/main.cpp47
-rw-r--r--examples/opengl/threadedqopenglwidget/mainwindow.cpp1
4 files changed, 39 insertions, 13 deletions
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.cpp b/examples/opengl/threadedqopenglwidget/glwidget.cpp
index d447f0c716..ecf1287045 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.cpp
+++ b/examples/opengl/threadedqopenglwidget/glwidget.cpp
@@ -42,8 +42,6 @@
#include <math.h>
#include <QGuiApplication>
-const int bubbleNum = 8;
-
GLWidget::GLWidget(QWidget *parent)
: QOpenGLWidget(parent)
{
diff --git a/examples/opengl/threadedqopenglwidget/glwidget.h b/examples/opengl/threadedqopenglwidget/glwidget.h
index 8319faf322..c063e846dc 100644
--- a/examples/opengl/threadedqopenglwidget/glwidget.h
+++ b/examples/opengl/threadedqopenglwidget/glwidget.h
@@ -100,7 +100,7 @@ class GLWidget : public QOpenGLWidget
{
Q_OBJECT
public:
- GLWidget(QWidget *parent);
+ explicit GLWidget(QWidget *parent = 0);
~GLWidget();
protected:
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();
diff --git a/examples/opengl/threadedqopenglwidget/mainwindow.cpp b/examples/opengl/threadedqopenglwidget/mainwindow.cpp
index 29c59573cf..de866f5615 100644
--- a/examples/opengl/threadedqopenglwidget/mainwindow.cpp
+++ b/examples/opengl/threadedqopenglwidget/mainwindow.cpp
@@ -43,6 +43,7 @@
MainWindow::MainWindow()
{
+ setMinimumSize(800, 400);
GLWidget *glwidget1 = new GLWidget(this);
glwidget1->resize(400, 400);