From fee20d9e466d214e3956782625ccd5effd504613 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Thu, 16 May 2019 11:41:25 -0700 Subject: [PATCH] render scripting interface + renderMethod control --- interface/src/Application.cpp | 9 ++- interface/src/Application.h | 1 - .../scripting/RenderScriptingInterface.cpp | 39 ++++++++++ .../src/scripting/RenderScriptingInterface.h | 71 +++++++++++++++++++ libraries/render-utils/src/RenderViewTask.cpp | 6 +- libraries/task/src/task/Config.h | 3 +- 6 files changed, 117 insertions(+), 12 deletions(-) create mode 100644 interface/src/scripting/RenderScriptingInterface.cpp create mode 100644 interface/src/scripting/RenderScriptingInterface.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3dc49e89d6..7978cd39da 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -193,8 +193,7 @@ #include "scripting/TTSScriptingInterface.h" #include "scripting/KeyboardScriptingInterface.h" #include "scripting/RefreshRateScriptingInterface.h" - - +#include "scripting/RenderScriptingInterface.h" #if defined(Q_OS_MAC) || defined(Q_OS_WIN) #include "SpeechRecognizer.h" @@ -3332,7 +3331,7 @@ void Application::onDesktopRootContextCreated(QQmlContext* surfaceContext) { surfaceContext->setContextProperty("LODManager", DependencyManager::get().data()); surfaceContext->setContextProperty("HMD", DependencyManager::get().data()); surfaceContext->setContextProperty("Scene", DependencyManager::get().data()); - surfaceContext->setContextProperty("Render", _graphicsEngine.getRenderEngine()->getConfiguration().get()); + surfaceContext->setContextProperty("Render", RenderScriptingInterface::getInstance()); surfaceContext->setContextProperty("Workload", _gameWorkload._engine->getConfiguration().get()); surfaceContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface()); surfaceContext->setContextProperty("Snapshot", DependencyManager::get().data()); @@ -3447,7 +3446,7 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get().data()); surfaceContext->setContextProperty("SoundCache", DependencyManager::get().data()); surfaceContext->setContextProperty("AvatarBookmarks", DependencyManager::get().data()); - surfaceContext->setContextProperty("Render", AbstractViewStateInterface::instance()->getRenderEngine()->getConfiguration().get()); + surfaceContext->setContextProperty("Render", RenderScriptingInterface::getInstance()); surfaceContext->setContextProperty("Workload", qApp->getGameWorkload()._engine->getConfiguration().get()); surfaceContext->setContextProperty("Controller", DependencyManager::get().data()); surfaceContext->setContextProperty("Pointers", DependencyManager::get().data()); @@ -7401,7 +7400,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0); scriptEngine->registerGlobalObject("Scene", DependencyManager::get().data()); - scriptEngine->registerGlobalObject("Render", _graphicsEngine.getRenderEngine()->getConfiguration().get()); + scriptEngine->registerGlobalObject("Render", RenderScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Workload", _gameWorkload._engine->getConfiguration().get()); GraphicsScriptingInterface::registerMetaTypes(scriptEngine.data()); diff --git a/interface/src/Application.h b/interface/src/Application.h index 34a5ba1d0c..17f5b24383 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -290,7 +290,6 @@ public: render::EnginePointer getRenderEngine() override { return _graphicsEngine.getRenderEngine(); } gpu::ContextPointer getGPUContext() const { return _graphicsEngine.getGPUContext(); } - const GameWorkload& getGameWorkload() const { return _gameWorkload; } virtual void pushPostUpdateLambda(void* key, const std::function& func) override; diff --git a/interface/src/scripting/RenderScriptingInterface.cpp b/interface/src/scripting/RenderScriptingInterface.cpp new file mode 100644 index 0000000000..0b862eb007 --- /dev/null +++ b/interface/src/scripting/RenderScriptingInterface.cpp @@ -0,0 +1,39 @@ +// +// Created by Sam Gondelman on 5/16/19 +// Copyright 2013-2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "RenderScriptingInterface.h" + +const QString DEFERRED = "deferred"; +const QString FORWARD = "forward"; + +RenderScriptingInterface* RenderScriptingInterface::getInstance() { + static RenderScriptingInterface sharedInstance; + return &sharedInstance; +} + +RenderScriptingInterface::RenderScriptingInterface() { + setRenderMethod((render::Args::RenderMethod)_renderMethodSetting.get() == render::Args::RenderMethod::DEFERRED ? DEFERRED : FORWARD); +} + +QString RenderScriptingInterface::getRenderMethod() { + return (render::Args::RenderMethod)_renderMethodSetting.get() == render::Args::RenderMethod::DEFERRED ? DEFERRED : FORWARD; +} + +void RenderScriptingInterface::setRenderMethod(const QString& renderMethod) { + auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); + if (config) { + if (renderMethod == DEFERRED) { + _renderMethodSetting.set(render::Args::RenderMethod::DEFERRED); + config->setBranch(render::Args::RenderMethod::DEFERRED); + emit config->dirtyEnabled(); + } else if (renderMethod == FORWARD) { + _renderMethodSetting.set(render::Args::RenderMethod::FORWARD); + config->setBranch(render::Args::RenderMethod::FORWARD); + emit config->dirtyEnabled(); + } + } +} \ No newline at end of file diff --git a/interface/src/scripting/RenderScriptingInterface.h b/interface/src/scripting/RenderScriptingInterface.h new file mode 100644 index 0000000000..71a8a64fdb --- /dev/null +++ b/interface/src/scripting/RenderScriptingInterface.h @@ -0,0 +1,71 @@ +// +// Created by Sam Gondelman on 5/16/19 +// Copyright 2013-2019 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RenderScriptingInterface_h +#define hifi_RenderScriptingInterface_h + +#include +#include "Application.h" + +#include "RenderForward.h" + +/**jsdoc + * The Render API allows you to configure the graphics engine + * + * @namespace Render + * + * @hifi-interface + * @hifi-client-entity + * @hifi-avatar + */ +class RenderScriptingInterface : public QObject { + Q_OBJECT + Q_PROPERTY(QString renderMethod READ getRenderMethod WRITE setRenderMethod) + +public: + RenderScriptingInterface(); + + static RenderScriptingInterface* getInstance(); + +public slots: + /**jsdoc + * Get a config for a job by name + * @function Render.getConfig + * @param {string} name - Can be: + * - . Search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) + * - .[.]. Allows you to first look for the parent_name job (from this task as root) and then search from there for the + * optional sub_parent_names and finally from there looking for the job_name (assuming every job in the path is found) + * @returns {object} The sub job config. + */ + QObject* getConfig(const QString& name) { return qApp->getRenderEngine()->getConfiguration()->getConfig(name); } + + /**jsdoc + * Gets the current render method + * @function Render.getRenderMethod + * @returns {string} "deferred" or "forward" + */ + QString getRenderMethod(); + + /**jsdoc + * Sets the current render method + * @function Render.setRenderMethod + * @param {string} renderMethod - "deferred" or "forward" + */ + void setRenderMethod(const QString& renderMethod); + +private: + Setting::Handle _renderMethodSetting { "renderMethod", +#ifdef RENDER_FORWARD + render::Args::RenderMethod::FORWARD +#else + render::Args::RenderMethod::DEFERRED +#endif + }; +}; + +#endif // hifi_RenderScriptingInterface_h diff --git a/libraries/render-utils/src/RenderViewTask.cpp b/libraries/render-utils/src/RenderViewTask.cpp index ffaecedb0b..93a3ff2d67 100644 --- a/libraries/render-utils/src/RenderViewTask.cpp +++ b/libraries/render-utils/src/RenderViewTask.cpp @@ -15,8 +15,6 @@ #include "RenderDeferredTask.h" #include "RenderForwardTask.h" -#include - void RenderShadowsAndDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint8_t tagBits, uint8_t tagMask) { task.addJob("SetRenderMethodTask", render::Args::DEFERRED); @@ -34,9 +32,9 @@ void RenderShadowsAndDeferredTask::build(JobModel& task, const render::Varying& } void DeferredForwardSwitchJob::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint8_t tagBits, uint8_t tagMask) { - task.addBranch("RenderShadowsAndDeferredTask", RENDER_FORWARD ? 1 : 0, input, cullFunctor, tagBits, tagMask); + task.addBranch("RenderShadowsAndDeferredTask", 0, input, cullFunctor, tagBits, tagMask); - task.addBranch("RenderForwardTask", RENDER_FORWARD ? 0 : 1, input); + task.addBranch("RenderForwardTask", 1, input); } void RenderViewTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint8_t tagBits, uint8_t tagMask) { diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index 891970006d..ab76bc5fba 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -220,7 +220,6 @@ public: TaskConfig() = default; TaskConfig(bool enabled) : JobConfig(enabled) {} - /**jsdoc * @function Render.getConfig * @param {string} name @@ -262,7 +261,7 @@ public: class SwitchConfig : public JobConfig { Q_OBJECT - Q_PROPERTY(bool branch READ getBranch WRITE setBranch NOTIFY dirtyEnabled) + Q_PROPERTY(int branch READ getBranch WRITE setBranch NOTIFY dirtyEnabled) public: uint8_t getBranch() const { return _branch; }