Add persistent render engine configuration file

This commit is contained in:
Zach Pomerantz 2016-02-09 11:07:10 -08:00
parent 66e1d9668c
commit 84197e5eb2
4 changed files with 102 additions and 2 deletions

View file

@ -1156,6 +1156,7 @@ void Application::initializeGL() {
render::CullFunctor cullFunctor = LODManager::shouldRender;
_renderEngine->addJob<RenderShadowTask>("RenderShadowTask", cullFunctor);
_renderEngine->addJob<RenderDeferredTask>("RenderDeferredTask", cullFunctor);
_renderEngine->loadConfig();
_renderEngine->registerScene(_main3DScene);
// TODO: Load a cached config file

View file

@ -335,7 +335,19 @@ void setupPreferences() {
{
static const QString RENDER("Graphics");
auto renderConfig = qApp->getRenderEngine()->getConfiguration();
auto renderEngine = qApp->getRenderEngine();
auto renderConfig = renderEngine->getConfiguration();
{
auto getter = [renderEngine]()->QString { return renderEngine->getNamedConfig(); };
auto setter = [renderEngine](QString config) { renderEngine->setNamedConfig(config); };
auto preference = new ComboBoxBrowsePreference(RENDER, "Engine Profile", getter, setter);
preference->setItems(renderEngine->getNamedConfigList());
preference->setBrowseLabel("Custom...");
preference->setBrowseFilter("Engine Profiles (*.json)");
preferences->addPreference(preference);
}
// Theses will override the engine profile because they are defined afterwards
{
auto getter = [renderConfig]()->bool { return renderConfig->isJobEnabled<AmbientOcclusionEffect>(); };
auto setter = [renderConfig](bool enable) { renderConfig->setJobEnabled<AmbientOcclusionEffect>(enable); };

View file

@ -9,17 +9,83 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Engine.h"
#include <QtCore/QFile>
#include <gpu/Context.h>
#include "Engine.h"
using namespace render;
const QString ENGINE_CONFIG_DEFAULT = "Default";
// TODO: Presets (e.g., "Highest Performance", "Highest Quality") will go here
const QMap<QString, QString> Engine::PRESETS = {};
Engine::Engine() :
_namedConfig(QStringList() << "Render" << "Engine"),
_sceneContext(std::make_shared<SceneContext>()),
_renderContext(std::make_shared<RenderContext>()) {
}
QStringList Engine::getNamedConfigList() {
QStringList list;
list << ENGINE_CONFIG_DEFAULT << PRESETS.keys();
auto current = _namedConfig.get();
if (!list.contains(current)) {
list << current;
}
return list;
}
QString Engine::getNamedConfig() {
return _namedConfig.get();
}
void Engine::setNamedConfig(const QString& config) {
_namedConfig.set(config);
loadConfig();
}
void Engine::loadConfig() {
auto config = getConfiguration();
QString current = _namedConfig.get();
if (_defaultConfig.isNull()) {
// Set the default
_defaultConfig =
QJsonDocument::fromJson(config->toJSON().toUtf8()).object();
}
if (current == ENGINE_CONFIG_DEFAULT) {
// Load the default
config->load(_defaultConfig.toObject());
} else if (PRESETS.contains(current)) {
// Load a preset
config->load(QJsonDocument::fromJson(PRESETS[current].toUtf8()).object());
} else {
QFile file(current);
if (!file.exists()) {
qWarning() << "Engine configuration file" << current << "does not exist";
} else if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qWarning() << "Engine configuration file" << current << "cannot be opened";
} else {
QString data = file.readAll();
file.close();
QJsonParseError error;
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8(), &error);
if (error.error == error.NoError) {
config->load(doc.object());
qDebug() << "Engine configuration file" << current << "loaded";
} else {
qWarning() << "Engine configuration file" << current << "failed to load:" <<
error.errorString() << "at offset" << error.offset;
}
}
}
}
void Engine::run() {
// Sync GPU state before beginning to render
_renderContext->args->_context->syncCache();

View file

@ -12,6 +12,8 @@
#ifndef hifi_render_Engine_h
#define hifi_render_Engine_h
#include <SettingHandle.h>
#include "Context.h"
#include "Task.h"
@ -25,6 +27,19 @@ public:
Engine();
~Engine() = default;
// Get the configurations
QStringList getNamedConfigList();
// Get the current named configuration
QString getNamedConfig();
// Set a named configuration
void setNamedConfig(const QString& config);
// Load the current named config
// The first time this is run, it will also set the current configuration as Default
void loadConfig();
// Register the scene
void registerScene(const ScenePointer& scene) { _sceneContext->_scene = scene; }
@ -37,8 +52,14 @@ public:
void run();
protected:
Setting::Handle<QString> _namedConfig;
QJsonValue _defaultConfig;
SceneContextPointer _sceneContext;
RenderContextPointer _renderContext;
private:
static const QMap<QString, QString> PRESETS;
};
using EnginePointer = std::shared_ptr<Engine>;