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