OpenGL examples: Introduce QCommandLineParser
Task-number: QTBUG-60626 Change-Id: I6d102327c89206fcdce10f3ac04e112270b11ad2 Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
parent
d64940891d
commit
b3717fc7f0
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -51,6 +51,8 @@
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QSurfaceFormat>
|
||||
#include <QCommandLineParser>
|
||||
#include <QCommandLineOption>
|
||||
#include "mainwindow.h"
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
@ -58,10 +60,21 @@ 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);
|
||||
parser.process(a);
|
||||
|
||||
QSurfaceFormat format;
|
||||
format.setDepthBufferSize(24);
|
||||
format.setStencilBufferSize(8);
|
||||
if (QCoreApplication::arguments().contains(QStringLiteral("--multisample")))
|
||||
if (parser.isSet(multipleSampleOption))
|
||||
format.setSamples(4);
|
||||
QSurfaceFormat::setDefaultFormat(format);
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user