diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:08:55 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-09-26 16:14:54 +0200 |
commit | aadfe7d634de04519102c5827ca885dc2e2199c9 (patch) | |
tree | d92db346ca95332b177036a53f1f6beb2e24fb74 /examples/opengl | |
parent | 4b6c1448047362b8c38d265e6414f0e3e59b8d37 (diff) | |
parent | a732e16d5fd9dbf8a0289fec9f948b12e9ba2c19 (diff) |
Merge remote-tracking branch 'origin/5.10' into dev
Conflicts:
src/gui/kernel/qguiapplication.cpp
src/platformsupport/input/libinput/qlibinputpointer.cpp
src/plugins/platforminputcontexts/ibus/qibusplatforminputcontext.h
src/plugins/platforms/cocoa/qcocoawindow.h
src/testlib/qtestsystem.h
Change-Id: I5975ffb3261c2dd82fe02ec4e57df7c0950226c5
Diffstat (limited to 'examples/opengl')
-rw-r--r-- | examples/opengl/hellogl2/glwidget.cpp | 7 | ||||
-rw-r--r-- | examples/opengl/hellogl2/glwidget.h | 5 | ||||
-rw-r--r-- | examples/opengl/hellogl2/main.cpp | 27 | ||||
-rw-r--r-- | examples/opengl/hellowindow/main.cpp | 27 | ||||
-rw-r--r-- | examples/opengl/qopenglwidget/main.cpp | 19 | ||||
-rw-r--r-- | examples/opengl/threadedqopenglwidget/main.cpp | 15 |
6 files changed, 87 insertions, 13 deletions
diff --git a/examples/opengl/hellogl2/glwidget.cpp b/examples/opengl/hellogl2/glwidget.cpp index fc961da4c4..318adb5043 100644 --- a/examples/opengl/hellogl2/glwidget.cpp +++ b/examples/opengl/hellogl2/glwidget.cpp @@ -54,6 +54,8 @@ #include <QCoreApplication> #include <math.h> +bool GLWidget::m_transparent = false; + GLWidget::GLWidget(QWidget *parent) : QOpenGLWidget(parent), m_xRot(0), @@ -61,10 +63,9 @@ GLWidget::GLWidget(QWidget *parent) m_zRot(0), m_program(0) { - m_core = QCoreApplication::arguments().contains(QStringLiteral("--coreprofile")); + m_core = QSurfaceFormat::defaultFormat().profile() == QSurfaceFormat::CoreProfile; // --transparent causes the clear color to be transparent. Therefore, on systems that // support it, the widget will become transparent apart from the logo. - m_transparent = QCoreApplication::arguments().contains(QStringLiteral("--transparent")); if (m_transparent) { QSurfaceFormat fmt = format(); fmt.setAlphaBufferSize(8); @@ -127,6 +128,8 @@ void GLWidget::setZRotation(int angle) void GLWidget::cleanup() { + if (m_program == nullptr) + return; makeCurrent(); m_logoVbo.destroy(); delete m_program; diff --git a/examples/opengl/hellogl2/glwidget.h b/examples/opengl/hellogl2/glwidget.h index cff5633893..21dd200dc7 100644 --- a/examples/opengl/hellogl2/glwidget.h +++ b/examples/opengl/hellogl2/glwidget.h @@ -68,6 +68,9 @@ public: GLWidget(QWidget *parent = 0); ~GLWidget(); + static bool isTransparent() { return m_transparent; } + static void setTransparent(bool t) { m_transparent = t; } + QSize minimumSizeHint() const override; QSize sizeHint() const override; @@ -108,7 +111,7 @@ private: QMatrix4x4 m_proj; QMatrix4x4 m_camera; QMatrix4x4 m_world; - bool m_transparent; + static bool m_transparent; }; #endif diff --git a/examples/opengl/hellogl2/main.cpp b/examples/opengl/hellogl2/main.cpp index 143f659eb6..b52a5a37d3 100644 --- a/examples/opengl/hellogl2/main.cpp +++ b/examples/opengl/hellogl2/main.cpp @@ -51,25 +51,46 @@ #include <QApplication> #include <QDesktopWidget> #include <QSurfaceFormat> +#include <QCommandLineParser> +#include <QCommandLineOption> +#include "glwidget.h" #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); + QCoreApplication::setApplicationName("Qt Hello GL 2 Example"); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription(QCoreApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption multipleSampleOption("multisample", "Multisampling"); + parser.addOption(multipleSampleOption); + QCommandLineOption coreProfileOption("coreprofile", "Use core profile"); + parser.addOption(coreProfileOption); + QCommandLineOption transparentOption("transparent", "Transparent window"); + parser.addOption(transparentOption); + + parser.process(app); + QSurfaceFormat fmt; fmt.setDepthBufferSize(24); - if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) + if (parser.isSet(multipleSampleOption)) fmt.setSamples(4); - if (QCoreApplication::arguments().contains(QStringLiteral("--coreprofile"))) { + if (parser.isSet(coreProfileOption)) { fmt.setVersion(3, 2); fmt.setProfile(QSurfaceFormat::CoreProfile); } QSurfaceFormat::setDefaultFormat(fmt); MainWindow mainWindow; - if (QCoreApplication::arguments().contains(QStringLiteral("--transparent"))) { + + GLWidget::setTransparent(parser.isSet(transparentOption)); + if (GLWidget::isTransparent()) { mainWindow.setAttribute(Qt::WA_TranslucentBackground); mainWindow.setAttribute(Qt::WA_NoSystemBackground, false); } diff --git a/examples/opengl/hellowindow/main.cpp b/examples/opengl/hellowindow/main.cpp index a20e7002a1..7f0be39f5d 100644 --- a/examples/opengl/hellowindow/main.cpp +++ b/examples/opengl/hellowindow/main.cpp @@ -52,6 +52,8 @@ #include <qpa/qplatformintegration.h> +#include <QCommandLineParser> +#include <QCommandLineOption> #include <QGuiApplication> #include <QScreen> #include <QThread> @@ -60,9 +62,26 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); + QCoreApplication::setApplicationName("Qt HelloWindow GL Example"); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription(QCoreApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption multipleOption("multiple", "Create multiple windows"); + parser.addOption(multipleOption); + QCommandLineOption multipleSampleOption("multisample", "Multisampling"); + parser.addOption(multipleSampleOption); + QCommandLineOption multipleScreenOption("multiscreen", "Run on multiple screens"); + parser.addOption(multipleScreenOption); + QCommandLineOption timeoutOption("timeout", "Close after 10s"); + parser.addOption(timeoutOption); + parser.process(app); + // Some platforms can only have one window per screen. Therefore we need to differentiate. - const bool multipleWindows = QGuiApplication::arguments().contains(QStringLiteral("--multiple")); - const bool multipleScreens = QGuiApplication::arguments().contains(QStringLiteral("--multiscreen")); + const bool multipleWindows = parser.isSet(multipleOption); + const bool multipleScreens = parser.isSet(multipleScreenOption); QScreen *screen = QGuiApplication::primaryScreen(); @@ -70,7 +89,7 @@ int main(int argc, char *argv[]) QSurfaceFormat format; format.setDepthBufferSize(16); - if (QGuiApplication::arguments().contains(QStringLiteral("--multisample"))) + if (parser.isSet(multipleSampleOption)) format.setSamples(4); QPoint center = QPoint(screenGeometry.center().x(), screenGeometry.top() + 80); @@ -136,7 +155,7 @@ int main(int argc, char *argv[]) } // Quit after 10 seconds. For platforms that do not have windows that are closeable. - if (QCoreApplication::arguments().contains(QStringLiteral("--timeout"))) + if (parser.isSet(timeoutOption)) QTimer::singleShot(10000, qGuiApp, &QCoreApplication::quit); const int exitValue = app.exec(); diff --git a/examples/opengl/qopenglwidget/main.cpp b/examples/opengl/qopenglwidget/main.cpp index f9b5731b8f..42fc772445 100644 --- a/examples/opengl/qopenglwidget/main.cpp +++ b/examples/opengl/qopenglwidget/main.cpp @@ -51,6 +51,8 @@ #include <QApplication> #include <QMainWindow> #include <QSurfaceFormat> +#include <QCommandLineParser> +#include <QCommandLineOption> #include "mainwindow.h" int main( int argc, char ** argv ) @@ -58,12 +60,25 @@ int main( int argc, char ** argv ) Q_INIT_RESOURCE(texture); QApplication a( argc, argv ); + QCoreApplication::setApplicationName("Qt QOpenGLWidget Example"); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription(QCoreApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption multipleSampleOption("multisample", "Multisampling"); + parser.addOption(multipleSampleOption); + QCommandLineOption srgbOption("srgb", "Use sRGB Color Space"); + parser.addOption(srgbOption); + parser.process(a); + QSurfaceFormat format; format.setDepthBufferSize(24); format.setStencilBufferSize(8); - if (QCoreApplication::arguments().contains(QStringLiteral("--srgb"))) + if (parser.isSet(srgbOption)) format.setColorSpace(QSurfaceFormat::sRGBColorSpace); - if (QCoreApplication::arguments().contains(QStringLiteral("--multisample"))) + if (parser.isSet(multipleSampleOption)) format.setSamples(4); QSurfaceFormat::setDefaultFormat(format); diff --git a/examples/opengl/threadedqopenglwidget/main.cpp b/examples/opengl/threadedqopenglwidget/main.cpp index c22cee9228..b9e491040f 100644 --- a/examples/opengl/threadedqopenglwidget/main.cpp +++ b/examples/opengl/threadedqopenglwidget/main.cpp @@ -53,6 +53,8 @@ #include <QDesktopWidget> #include <QSurfaceFormat> #include <QOpenGLContext> +#include <QCommandLineParser> +#include <QCommandLineOption> #include "mainwindow.h" #include "glwidget.h" @@ -67,6 +69,17 @@ int main( int argc, char ** argv ) { QApplication a( argc, argv ); + QCoreApplication::setApplicationName("Qt Threaded QOpenGLWidget Example"); + QCoreApplication::setOrganizationName("QtProject"); + QCoreApplication::setApplicationVersion(QT_VERSION_STR); + QCommandLineParser parser; + parser.setApplicationDescription(QCoreApplication::applicationName()); + parser.addHelpOption(); + parser.addVersionOption(); + QCommandLineOption singleOption("single", "Single thread"); + parser.addOption(singleOption); + parser.process(a); + QSurfaceFormat format; format.setDepthBufferSize(16); QSurfaceFormat::setDefaultFormat(format); @@ -93,7 +106,7 @@ int main( int argc, char ** argv ) QScopedPointer<MainWindow> mw1; QScopedPointer<MainWindow> mw2; - if (!QApplication::arguments().contains(QStringLiteral("--single"))) { + if (!parser.isSet(singleOption)) { if (supportsThreading) { pos += QPoint(100, 100); mw1.reset(new MainWindow); |