History

Testing a different approach

Sam Gateau committed 7 years ago

Commit 54d17051 parent 4e2480d5 files · +65 −45Browse files

Showing the changes to interface/src/scripting/RenderScriptingInterface.cpp (1 of 5 files). Show all

Unified · Split

interface/src/scripting/RenderScriptingInterface.cpp+21−18
@@ -10,6 +10,7 @@ · 9 unmodified lines
10#include "LightingModel.h"10#include "LightingModel.h"
11#include "AntialiasingEffect.h"11#include "AntialiasingEffect.h"
12 12
13std::once_flag RenderScriptingInterface::registry_flag;
13 14
14RenderScriptingInterface* RenderScriptingInterface::getInstance() {15RenderScriptingInterface* RenderScriptingInterface::getInstance() {
15 static RenderScriptingInterface sharedInstance;16 static RenderScriptingInterface sharedInstance;
@@ -17,32 +18,34 @@ RenderScriptingInterface* RenderScriptingInterface::getInstance() { · 1 unmodified line
17}18}
18 19
19RenderScriptingInterface::RenderScriptingInterface() {20RenderScriptingInterface::RenderScriptingInterface() {
20 setRenderMethod((RenderMethod)_renderMethodSetting.get() == RenderMethod::DEFERRED ? RenderMethod::DEFERRED : RenderMethod::FORWARD);21 std::call_once(registry_flag, [] {
22 qmlRegisterType<RenderScriptingInterface>("RenderEnums", 1, 0, "RenderEnums");
23 });
24
25 setRenderMethod((RenderMethod)_renderMethodSettingLock.resultWithReadLock<int>([&] {
26 return _renderMethodSetting.get();
27 }));
21 setShadowsEnabled(_shadowsEnabledSetting.get());28 setShadowsEnabled(_shadowsEnabledSetting.get());
22 setAmbientOcclusionEnabled(_ambientOcclusionEnabledSetting.get());29 setAmbientOcclusionEnabled(_ambientOcclusionEnabledSetting.get());
23 setAntialiasingEnabled(_antialiasingEnabledSetting.get());30 setAntialiasingEnabled(_antialiasingEnabledSetting.get());
24}31}
25 32
26RenderScriptingInterface::RenderMethod RenderScriptingInterface::getRenderMethod() {33RenderScriptingInterface::RenderMethod RenderScriptingInterface::getRenderMethod() {
27 return (RenderMethod)_renderMethodSetting.get() == RenderMethod::DEFERRED ? RenderMethod::DEFERRED : RenderMethod::FORWARD;34 return (RenderMethod) _renderMethod;
28}35}
29 36
30void RenderScriptingInterface::setRenderMethod(RenderScriptingInterface::RenderMethod renderMethod) {37void RenderScriptingInterface::setRenderMethod(RenderMethod renderMethod) {
31 RenderMethod newMethod = renderMethod == RenderMethod::FORWARD ? RenderMethod::FORWARD : RenderMethod::DEFERRED;38 if (_renderMethod != (int) renderMethod) {
32 if (_renderMethodSetting.get() == newMethod) {39 _renderMethodSettingLock.withWriteLock([&] {
33 return;40 _renderMethod = (int)renderMethod;
34 }41 _renderMethodSetting.set((int)renderMethod);
35 42
36 if (QThread::currentThread() != thread()) {43 auto config = dynamic_cast<task::SwitchConfig*>(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch"));
37 QMetaObject::invokeMethod(this, "setRenderMethod", Q_ARG(RenderScriptingInterface::RenderMethod, renderMethod));44 if (config) {
38 return;45 _renderMethodSetting.set((int)renderMethod);
39 }46 config->setBranch((int)renderMethod);
40 47 }
41 auto config = dynamic_cast<task::SwitchConfig*>(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch"));48 });
42 if (config) {
43 _renderMethodSetting.set(newMethod);
44 config->setBranch(newMethod);
45 emit config->dirtyEnabled();
46 emit settingsChanged();49 emit settingsChanged();
47 }50 }
48}51}