From ed28a05e24d2af7fc768ada09a9c2d5e0af94fdb Mon Sep 17 00:00:00 2001 From: Martin Reboredo Date: Sat, 18 Jun 2022 13:35:24 -0300 Subject: [PATCH] OpenGL rendering cli flag --- Engine/CLArgs.cpp | 33 ++++++++++++++++++++++++++++++ Engine/EffectInstanceRenderRoI.cpp | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/Engine/CLArgs.cpp b/Engine/CLArgs.cpp index d73522e06b..e52fb375f7 100644 --- a/Engine/CLArgs.cpp +++ b/Engine/CLArgs.cpp @@ -324,6 +324,12 @@ CLArgs::printUsage(const std::string& programName) " the settings and prior to executing Python commands or loading the project.\n" " For choice settings, the value may be an integer index for the option, or\n" " a quoted string, as in: --setting enableOpenGLRendering=\\\"enabled\\\"\n" + " --opengl choice\n" + " Select whether to activate OpenGL rendering or not. If disabled, even\n" + " though a Project enable GPU rendering, it will not be activated.\n" + " choice can be one of enabled (enables OpenGL rendering if available)\n" + " disabled (disables it otherwise) and foreground (uses OpenGL only\n" + " if it's not running at background)\"\n" " -c [ --cmd ] \"PythonCommand\"\n" " Execute custom Python code passed as a script prior to executing the Python\n" " script or loading the project passed as parameter. This option may be used\n" @@ -1004,6 +1010,33 @@ CLArgsPrivate::parse() } } } + + { + QStringList::iterator it = hasToken( QString::fromUtf8("opengl"), QString() ); + if ( it != args.end() ) { + it = args.erase(it); + + if ( it == args.end() || it->startsWith( QChar::fromLatin1('-') ) ) { + std::cout << tr("You must specify a choice when using the --opengl option").toStdString() << std::endl; + error = 1; + + return; + } + + QString choice = *it; + it = args.erase(it); + + if (choice != QString::fromUtf8("enabled") && choice != QString::fromUtf8("disabled") && choice != QString::fromUtf8("foreground")) { + std::cout << tr("Valid options for --opengl are enabled, disabled and foreground").toStdString() << std::endl; + error = 1; + + return; + } + + settingCommands.push_back( "NatronEngine.natron.getSettings().getParam(\"enableOpenGLRendering\").setValue(\"" + choice.toStdString() + "\")"); + } + } + //Parse settings for (;;) { QStringList::iterator it = hasToken( QString::fromUtf8("setting"), QString() ); diff --git a/Engine/EffectInstanceRenderRoI.cpp b/Engine/EffectInstanceRenderRoI.cpp index ca63a93169..fd29405bb9 100644 --- a/Engine/EffectInstanceRenderRoI.cpp +++ b/Engine/EffectInstanceRenderRoI.cpp @@ -882,6 +882,10 @@ EffectInstance::renderRoI(const RenderRoIArgs & args, } } } + } else if ( appPTR->isOpenGLLoaded() && !appPTR->getCurrentSettings()->isOpenGLRenderingEnabled() && openGLSupport == ePluginOpenGLRenderSupportNeeded ) { + QString message = tr("OpenGL render is required for a plugin but it's currently disabled, please consider passing `--opengl enabled` to %1").arg(QString::fromUtf8(NATRON_APPLICATION_NAME)); + setPersistentMessage(eMessageTypeError, message.toStdString()); + return eRenderRoIRetCodeFailed; }