mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 20:06:02 +02:00
Add persistent render engine configuration file
This commit is contained in:
parent
66e1d9668c
commit
84197e5eb2
4 changed files with 102 additions and 2 deletions
|
@ -1156,6 +1156,7 @@ void Application::initializeGL() {
|
||||||
render::CullFunctor cullFunctor = LODManager::shouldRender;
|
render::CullFunctor cullFunctor = LODManager::shouldRender;
|
||||||
_renderEngine->addJob<RenderShadowTask>("RenderShadowTask", cullFunctor);
|
_renderEngine->addJob<RenderShadowTask>("RenderShadowTask", cullFunctor);
|
||||||
_renderEngine->addJob<RenderDeferredTask>("RenderDeferredTask", cullFunctor);
|
_renderEngine->addJob<RenderDeferredTask>("RenderDeferredTask", cullFunctor);
|
||||||
|
_renderEngine->loadConfig();
|
||||||
_renderEngine->registerScene(_main3DScene);
|
_renderEngine->registerScene(_main3DScene);
|
||||||
// TODO: Load a cached config file
|
// TODO: Load a cached config file
|
||||||
|
|
||||||
|
|
|
@ -335,7 +335,19 @@ void setupPreferences() {
|
||||||
|
|
||||||
{
|
{
|
||||||
static const QString RENDER("Graphics");
|
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 getter = [renderConfig]()->bool { return renderConfig->isJobEnabled<AmbientOcclusionEffect>(); };
|
||||||
auto setter = [renderConfig](bool enable) { renderConfig->setJobEnabled<AmbientOcclusionEffect>(enable); };
|
auto setter = [renderConfig](bool enable) { renderConfig->setJobEnabled<AmbientOcclusionEffect>(enable); };
|
||||||
|
|
|
@ -9,17 +9,83 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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 <gpu/Context.h>
|
||||||
|
|
||||||
#include "Engine.h"
|
|
||||||
|
|
||||||
using namespace render;
|
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() :
|
Engine::Engine() :
|
||||||
|
_namedConfig(QStringList() << "Render" << "Engine"),
|
||||||
_sceneContext(std::make_shared<SceneContext>()),
|
_sceneContext(std::make_shared<SceneContext>()),
|
||||||
_renderContext(std::make_shared<RenderContext>()) {
|
_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() {
|
void Engine::run() {
|
||||||
// Sync GPU state before beginning to render
|
// Sync GPU state before beginning to render
|
||||||
_renderContext->args->_context->syncCache();
|
_renderContext->args->_context->syncCache();
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
#ifndef hifi_render_Engine_h
|
#ifndef hifi_render_Engine_h
|
||||||
#define hifi_render_Engine_h
|
#define hifi_render_Engine_h
|
||||||
|
|
||||||
|
#include <SettingHandle.h>
|
||||||
|
|
||||||
#include "Context.h"
|
#include "Context.h"
|
||||||
#include "Task.h"
|
#include "Task.h"
|
||||||
|
|
||||||
|
@ -25,6 +27,19 @@ public:
|
||||||
Engine();
|
Engine();
|
||||||
~Engine() = default;
|
~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
|
// Register the scene
|
||||||
void registerScene(const ScenePointer& scene) { _sceneContext->_scene = scene; }
|
void registerScene(const ScenePointer& scene) { _sceneContext->_scene = scene; }
|
||||||
|
|
||||||
|
@ -37,8 +52,14 @@ public:
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
Setting::Handle<QString> _namedConfig;
|
||||||
|
QJsonValue _defaultConfig;
|
||||||
|
|
||||||
SceneContextPointer _sceneContext;
|
SceneContextPointer _sceneContext;
|
||||||
RenderContextPointer _renderContext;
|
RenderContextPointer _renderContext;
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const QMap<QString, QString> PRESETS;
|
||||||
};
|
};
|
||||||
using EnginePointer = std::shared_ptr<Engine>;
|
using EnginePointer = std::shared_ptr<Engine>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue