aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qml/main.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2023-02-02 13:50:19 +0100
committerLaszlo Agocs <laszlo.agocs@qt.io>2023-02-07 19:23:13 +0100
commit36f0cb435ecc7af326c745f793d104a3d5c65304 (patch)
tree2792c4e728faf9d0507146426f15822b1f1f7353 /tools/qml/main.cpp
parent37f2c169a5ea2a16432651c261e16aaa8b07b7cc (diff)
Bring QSurfaceFormat configurability to qmlscene's level in the qml tool
Restore the --transparent and --multisample options. Also make the default QSurfaceFormat setting universal (no need to tie it to the option of forcing a core profile context), and prevent the warning that is printed when the default surfaceformat is changed after the application is already created with AA_ShareOpenGLContexts set. This involves having to handle the relevant arguments manually early on, not through QCommandLineParser. All this matches the qmlscene behavior. NB qmlscene requests 16 samples with --multisample which is completely pointless in practice. Use the common 4 now. Change-Id: I671e5f22846a715675ea936bb7cf2a31a849dc28 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'tools/qml/main.cpp')
-rw-r--r--tools/qml/main.cpp51
1 files changed, 39 insertions, 12 deletions
diff --git a/tools/qml/main.cpp b/tools/qml/main.cpp
index f09f3a5ff8..e9a084a059 100644
--- a/tools/qml/main.cpp
+++ b/tools/qml/main.cpp
@@ -80,6 +80,9 @@ static bool verboseMode = false;
static bool quietMode = false;
static bool glShareContexts = true;
static bool disableShaderCache = true;
+static bool requestAlphaChannel = false;
+static bool requestMSAA = false;
+static bool requestCoreProfile = false;
static void loadConf(const QString &override, bool quiet) // Terminates app on failure
{
@@ -327,6 +330,12 @@ static void getAppFlags(int argc, char **argv)
glShareContexts = false;
} else if (!strcmp(argv[i], "-enable-shader-cache") || !strcmp(argv[i], "--enable-shader-cache")) {
disableShaderCache = false;
+ } else if (!strcmp(argv[i], "-transparent") || !strcmp(argv[i], "--transparent")) {
+ requestAlphaChannel = true;
+ } else if (!strcmp(argv[i], "-multisample") || !strcmp(argv[i], "--multisample")) {
+ requestMSAA = true;
+ } else if (!strcmp(argv[i], "-core-profile") || !strcmp(argv[i], "--core-profile")) {
+ requestCoreProfile = true;
}
}
#else
@@ -365,6 +374,27 @@ int main(int argc, char *argv[])
{
getAppFlags(argc, argv);
+ // Must set the default QSurfaceFormat before creating the app object if
+ // AA_ShareOpenGLContexts is going to be set.
+#if defined(QT_GUI_LIB)
+ QSurfaceFormat surfaceFormat;
+ surfaceFormat.setDepthBufferSize(24);
+ surfaceFormat.setStencilBufferSize(8);
+ if (requestMSAA)
+ surfaceFormat.setSamples(4);
+ if (requestMSAA)
+ surfaceFormat.setAlphaBufferSize(8);
+ if (qEnvironmentVariableIsSet("QSG_CORE_PROFILE")
+ || qEnvironmentVariableIsSet("QML_CORE_PROFILE")
+ || requestCoreProfile)
+ {
+ // intentionally requesting 4.1 core to play nice with macOS
+ surfaceFormat.setVersion(4, 1);
+ surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
+ }
+ QSurfaceFormat::setDefaultFormat(surfaceFormat);
+#endif
+
if (glShareContexts)
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
if (disableShaderCache)
@@ -449,14 +479,22 @@ int main(int argc, char *argv[])
parser.addOption(glSoftwareOption); // Just for the help text... we've already handled this argument above
QCommandLineOption glCoreProfile(QStringLiteral("core-profile"),
QCoreApplication::translate("main", "Force use of OpenGL Core Profile."));
- parser.addOption(glCoreProfile);
+ parser.addOption(glCoreProfile); // Just for the help text... we've already handled this argument above
QCommandLineOption glContextSharing(QStringLiteral("disable-context-sharing"),
QCoreApplication::translate("main", "Disable the use of a shared GL context for QtQuick Windows"));
parser.addOption(glContextSharing); // Just for the help text... we've already handled this argument above
+ // Options relevant for other 3D APIs as well
QCommandLineOption shaderCaching(QStringLiteral("enable-shader-cache"),
QCoreApplication::translate("main", "Enable persistent caching of generated shaders"));
parser.addOption(shaderCaching); // Just for the help text... we've already handled this argument above
+ QCommandLineOption transparentOption(QStringLiteral("transparent"),
+ QCoreApplication::translate("main", "Requests an alpha channel in order to enable semi-transparent windows."));
+ parser.addOption(transparentOption); // Just for the help text... we've already handled this argument above
+ QCommandLineOption multisampleOption(QStringLiteral("multisample"),
+ QCoreApplication::translate("main", "Requests 4x multisample antialiasing."));
+ parser.addOption(multisampleOption); // Just for the help text... we've already handled this argument above
#endif // QT_GUI_LIB
+
// Debugging and verbosity options
QCommandLineOption quietOption(QStringLiteral("quiet"),
QCoreApplication::translate("main", "Suppress all output."));
@@ -525,17 +563,6 @@ int main(int argc, char *argv[])
if (!customSelectors.isEmpty())
e.setExtraFileSelectors(customSelectors);
-#if defined(QT_GUI_LIB)
- if (qEnvironmentVariableIsSet("QSG_CORE_PROFILE") || qEnvironmentVariableIsSet("QML_CORE_PROFILE") || parser.isSet(glCoreProfile)) {
- QSurfaceFormat surfaceFormat;
- surfaceFormat.setStencilBufferSize(8);
- surfaceFormat.setDepthBufferSize(24);
- surfaceFormat.setVersion(4, 1);
- surfaceFormat.setProfile(QSurfaceFormat::CoreProfile);
- QSurfaceFormat::setDefaultFormat(surfaceFormat);
- }
-#endif
-
files << parser.values(qmlFileOption);
if (parser.isSet(configOption))
confFile = parser.value(configOption);