render scripting interface + renderMethod control

This commit is contained in:
SamGondelman 2019-05-16 11:41:25 -07:00
parent cf5869f199
commit fee20d9e46
6 changed files with 117 additions and 12 deletions

View file

@ -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<LODManager>().data());
surfaceContext->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
surfaceContext->setContextProperty("Scene", DependencyManager::get<SceneScriptingInterface>().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<Snapshot>().data());
@ -3447,7 +3446,7 @@ void Application::setupQmlSurface(QQmlContext* surfaceContext, bool setAdditiona
surfaceContext->setContextProperty("InputConfiguration", DependencyManager::get<InputConfiguration>().data());
surfaceContext->setContextProperty("SoundCache", DependencyManager::get<SoundCacheScriptingInterface>().data());
surfaceContext->setContextProperty("AvatarBookmarks", DependencyManager::get<AvatarBookmarks>().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<controller::ScriptingInterface>().data());
surfaceContext->setContextProperty("Pointers", DependencyManager::get<PointerScriptingInterface>().data());
@ -7401,7 +7400,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEnginePointe
scriptEngine->registerFunction("HMD", "getHUDLookAtPosition3D", HMDScriptingInterface::getHUDLookAtPosition3D, 0);
scriptEngine->registerGlobalObject("Scene", DependencyManager::get<SceneScriptingInterface>().data());
scriptEngine->registerGlobalObject("Render", _graphicsEngine.getRenderEngine()->getConfiguration().get());
scriptEngine->registerGlobalObject("Render", RenderScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("Workload", _gameWorkload._engine->getConfiguration().get());
GraphicsScriptingInterface::registerMetaTypes(scriptEngine.data());

View file

@ -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<void()>& func) override;

View file

@ -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<task::SwitchConfig*>(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();
}
}
}

View file

@ -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 <QtCore/QObject>
#include "Application.h"
#include "RenderForward.h"
/**jsdoc
* The <code>Render</code> 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:
* - <job_name>. Search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root)
* - <parent_name>.[<sub_parent_names>.]<job_name>. 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} <code>"deferred"</code> or <code>"forward"</code>
*/
QString getRenderMethod();
/**jsdoc
* Sets the current render method
* @function Render.setRenderMethod
* @param {string} renderMethod - <code>"deferred"</code> or <code>"forward"</code>
*/
void setRenderMethod(const QString& renderMethod);
private:
Setting::Handle<int> _renderMethodSetting { "renderMethod",
#ifdef RENDER_FORWARD
render::Args::RenderMethod::FORWARD
#else
render::Args::RenderMethod::DEFERRED
#endif
};
};
#endif // hifi_RenderScriptingInterface_h

View file

@ -15,8 +15,6 @@
#include "RenderDeferredTask.h"
#include "RenderForwardTask.h"
#include <RenderForward.h>
void RenderShadowsAndDeferredTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint8_t tagBits, uint8_t tagMask) {
task.addJob<SetRenderMethod>("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>("RenderShadowsAndDeferredTask", RENDER_FORWARD ? 1 : 0, input, cullFunctor, tagBits, tagMask);
task.addBranch<RenderShadowsAndDeferredTask>("RenderShadowsAndDeferredTask", 0, input, cullFunctor, tagBits, tagMask);
task.addBranch<RenderForwardTask>("RenderForwardTask", RENDER_FORWARD ? 0 : 1, input);
task.addBranch<RenderForwardTask>("RenderForwardTask", 1, input);
}
void RenderViewTask::build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint8_t tagBits, uint8_t tagMask) {

View file

@ -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; }