From 767f413a2c1c16ccf02bf411900227154d256703 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 29 Jul 2019 00:07:16 -0700 Subject: [PATCH 01/21] merging the various job/task/switch congif into one --- .../scripting/RenderScriptingInterface.cpp | 2 +- libraries/render/src/render/Engine.h | 2 +- libraries/task/src/task/Config.cpp | 12 ++-- libraries/task/src/task/Config.h | 71 ++++++++++++++++--- libraries/task/src/task/Task.h | 56 +++++++++------ scripts/developer/utilities/lib/jet/jet.js | 8 ++- .../utilities/lib/jet/qml/TaskList.qml | 2 +- .../utilities/lib/jet/qml/TaskPropView.qml | 2 +- .../developer/utilities/lib/prop/PropItem.qml | 4 +- .../utilities/lib/prop/PropScalar.qml | 18 +++-- .../utilities/lib/prop/style/Global.qml | 8 ++- .../utilities/render/engineInspector.js | 62 ++-------------- .../utilities/render/engineInspector.qml | 2 +- .../developer/utilities/render/engineList.js | 18 ++--- .../developer/utilities/render/engineList.qml | 2 +- 15 files changed, 144 insertions(+), 125 deletions(-) diff --git a/interface/src/scripting/RenderScriptingInterface.cpp b/interface/src/scripting/RenderScriptingInterface.cpp index 338a5ab883..f23dc598a9 100644 --- a/interface/src/scripting/RenderScriptingInterface.cpp +++ b/interface/src/scripting/RenderScriptingInterface.cpp @@ -54,7 +54,7 @@ void RenderScriptingInterface::forceRenderMethod(RenderMethod renderMethod) { _renderMethod = (int)renderMethod; _renderMethodSetting.set((int)renderMethod); - auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); + auto config = dynamic_cast(qApp->getRenderEngine()->getConfiguration()->getConfig("RenderMainView.DeferredForwardSwitch")); if (config) { config->setBranch((int)renderMethod); } diff --git a/libraries/render/src/render/Engine.h b/libraries/render/src/render/Engine.h index 130ed6533f..f1d59727d3 100644 --- a/libraries/render/src/render/Engine.h +++ b/libraries/render/src/render/Engine.h @@ -70,7 +70,7 @@ namespace render { GPUTaskConfig() = default; - GPUTaskConfig(bool enabled) : TaskConfig(enabled) {} + GPUTaskConfig(bool enabled) : render::TaskConfig(enabled) {} // Running Time measurement on GPU and for Batch execution void setGPUBatchRunTime(double msGpuTime, double msBatchTime) { _msGPURunTime = msGpuTime; _msBatchRunTime = msBatchTime; } diff --git a/libraries/task/src/task/Config.cpp b/libraries/task/src/task/Config.cpp index 79e0b9f7fb..bcf5eb7d1f 100644 --- a/libraries/task/src/task/Config.cpp +++ b/libraries/task/src/task/Config.cpp @@ -79,8 +79,8 @@ void JobConfig::refresh() { _jobConcept->applyConfiguration(); } -TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& jobName) const { - TaskConfig* root = const_cast (this); +JobConfig* JobConfig::getRootConfig(const std::string& jobPath, std::string& jobName) const { + JobConfig* root = const_cast (this); std::list tokens; std::size_t pos = 0, sepPos; @@ -105,7 +105,7 @@ TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& j while (tokens.size() > 1) { auto taskName = tokens.front(); tokens.pop_front(); - root = root->findChild((taskName.empty() ? QString() : QString(taskName.c_str()))); + root = root->findChild((taskName.empty() ? QString() : QString(taskName.c_str()))); if (!root) { return nullptr; } @@ -115,7 +115,7 @@ TaskConfig* TaskConfig::getRootConfig(const std::string& jobPath, std::string& j return root; } -JobConfig* TaskConfig::getJobConfig(const std::string& jobPath) const { +JobConfig* JobConfig::getJobConfig(const std::string& jobPath) const { std::string jobName; auto root = getRootConfig(jobPath, jobName); @@ -134,10 +134,10 @@ JobConfig* TaskConfig::getJobConfig(const std::string& jobPath) const { } } -void SwitchConfig::setBranch(uint8_t branch) { +void JobConfig::setBranch(uint8_t branch) { if (_branch != branch) { _branch = branch; // We can re-use this signal here emit dirtyEnabled(); } -} \ No newline at end of file +} diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index ab76bc5fba..8c674da31c 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -83,11 +83,19 @@ protected: Setting::Handle _preset; }; +class JobConfig; + +class TConfigProxy { +public: + using Config = JobConfig; +}; + // A default Config is always on; to create an enableable Config, use the ctor JobConfig(bool enabled) class JobConfig : public QObject { Q_OBJECT Q_PROPERTY(double cpuRunTime READ getCPURunTime NOTIFY newStats()) //ms Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY dirtyEnabled()) + Q_PROPERTY(int branch READ getBranch WRITE setBranch NOTIFY dirtyEnabled) double _msCPURunTime{ 0.0 }; @@ -96,7 +104,11 @@ protected: bool _isEnabled{ true }; + uint8_t _branch { 0 }; public: + bool _isTask{ false }; + bool _isSwitch{ false }; + using Persistent = PersistentConfig; JobConfig() = default; @@ -121,44 +133,86 @@ public: */ Q_INVOKABLE void load(const QVariantMap& map) { qObjectFromJsonValue(QJsonObject::fromVariantMap(map), *this); emit loaded(); } - Q_INVOKABLE QObject* getConfig(const QString& name) { return nullptr; } + //Q_INVOKABLE QObject* getConfig(const QString& name) { return nullptr; } // Running Time measurement // The new stats signal is emitted once per run time of a job when stats (cpu runtime) are updated void setCPURunTime(const std::chrono::nanoseconds& runtime) { _msCPURunTime = std::chrono::duration(runtime).count(); emit newStats(); } double getCPURunTime() const { return _msCPURunTime; } + /**jsdoc + * @function Render.getConfig + * @param {string} name + * @returns {object} + */ + // Get a sub job config through task.getConfig(path) + // where path can be: + // - search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) + // - .[.] + // Allowing 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 were found) + // + // getter for qml integration, prefer the templated getter + Q_INVOKABLE QObject* getConfig(const QString& name) { return getConfig(name.toStdString()); } + + // getter for cpp (strictly typed), prefer this getter + JobConfig* getRootConfig(const std::string& jobPath, std::string& jobName) const; + JobConfig* getJobConfig(const std::string& jobPath) const; + template typename T::Config* getConfig(std::string jobPath = "") const { + return dynamic_cast(getJobConfig(jobPath)); + } + + Q_INVOKABLE bool isTask() const { return _isTask; } + Q_INVOKABLE bool isSwitch() const { return _isSwitch; } + + Q_INVOKABLE QObjectList getSubConfigs() const { + auto list = findChildren(QRegExp(".*"), Qt::FindDirectChildrenOnly); + QObjectList returned; + for (int i = 0; i < list.size(); i++) { + returned.push_back(list[i]); + } + return returned; + } + Q_INVOKABLE int getNumSubs() const { return getSubConfigs().size(); } + Q_INVOKABLE QObject* getSubConfig(int i) const { + auto subs = getSubConfigs(); + return ((i < 0 || i >= subs.size()) ? nullptr : subs[i]); + } + // Describe the node graph data connections of the associated Job/Task /**jsdoc * @function Render.isTask * @returns {boolean} */ - Q_INVOKABLE virtual bool isTask() const { return false; } + //Q_INVOKABLE virtual bool isTask() const { return false; } /**jsdoc * @function Render.getSubConfigs * @returns {object[]} */ - Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); } + // Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); } /**jsdoc * @function Render.getNumSubs * @returns {number} */ - Q_INVOKABLE virtual int getNumSubs() const { return 0; } + // Q_INVOKABLE virtual int getNumSubs() const { return 0; } /**jsdoc * @function Render.getSubConfig * @param {number} index * @returns {object} */ - Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; } + //Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; } void connectChildConfig(std::shared_ptr childConfig, const std::string& name); void transferChildrenConfigs(std::shared_ptr source); JobConcept* _jobConcept; + uint8_t getBranch() const { return _branch; } + void setBranch(uint8_t index); + public slots: /**jsdoc @@ -195,12 +249,9 @@ signals: using QConfigPointer = std::shared_ptr; -class TConfigProxy { -public: - using Config = JobConfig; -}; +#ifdef SPECIALIZE_CONFIG /**jsdoc * @namespace Render * @@ -270,7 +321,7 @@ public: protected: uint8_t _branch { 0 }; }; - +#endif } #endif // hifi_task_Config_h diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index cdc279ff36..0871cb5982 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -69,7 +69,7 @@ class JobConcept { public: using Config = JobConfig; - JobConcept(const std::string& name, QConfigPointer config) : _config(config), _name(name) {} + JobConcept(const std::string& name, QConfigPointer config) : _config(config), _name(name) { config->_jobConcept = this; } virtual ~JobConcept() = default; const std::string& getName() const { return _name; } @@ -80,7 +80,8 @@ public: virtual QConfigPointer& getConfiguration() { return _config; } virtual void applyConfiguration() = 0; - void setCPURunTime(const std::chrono::nanoseconds& runtime) { std::static_pointer_cast(_config)->setCPURunTime(runtime); } + void setCPURunTime(const std::chrono::nanoseconds& runtime) { + /*std::static_pointer_cast*/(_config)->setCPURunTime(runtime); } QConfigPointer _config; protected: @@ -94,9 +95,9 @@ template void jobConfigure(T& data, const C& configuration) { template void jobConfigure(T&, const JobConfig&) { // nop, as the default JobConfig was used, so the data does not need a configure method } -template void jobConfigure(T&, const TaskConfig&) { +/*template void jobConfigure(T&, const TaskConfig&) { // nop, as the default TaskConfig was used, so the data does not need a configure method -} +}*/ template void jobRun(T& data, const JC& jobContext, const JobNoIO& input, JobNoIO& output) { data.run(jobContext); @@ -158,7 +159,17 @@ public: return std::make_shared(name, input, std::make_shared(), std::forward(args)...); } - + void createConfiguration() { + // A brand new config + auto config = std::make_shared(); + // Make sure we transfer the former children configs to the new config + config->transferChildrenConfigs(Concept::_config); + // swap + Concept::_config = config; + // Capture this + Concept::_config->_jobConcept = this; + } + void applyConfiguration() override { TimeProfiler probe(("configure::" + JobConcept::getName())); @@ -228,7 +239,7 @@ public: using Context = JC; using TimeProfiler = TP; using ContextPointer = std::shared_ptr; - using Config = TaskConfig; + using Config = JobConfig; //TaskConfig; using JobType = Job; using None = typename JobType::None; using Concept = typename JobType::Concept; @@ -247,14 +258,15 @@ public: const Varying getOutput() const override { return _output; } Varying& editInput() override { return _input; } - TaskConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {} + TaskConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {config->_isTask = true;} // Create a new job in the container's queue; returns the job's output template const Varying addJob(std::string name, const Varying& input, NA&&... args) { _jobs.emplace_back((NT::JobModel::create(name, input, std::forward(args)...))); // Conect the child config to this task's config - std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); + // std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); + std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); return _jobs.back().getOutput(); } @@ -285,8 +297,8 @@ public: model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } // Recreate the Config to use the templated type - model->createConfiguration(); - model->applyConfiguration(); + // model->createConfiguration(); + // model->applyConfiguration(); return model; } @@ -369,7 +381,7 @@ public: using Context = JC; using TimeProfiler = TP; using ContextPointer = std::shared_ptr; - using Config = SwitchConfig; + using Config = JobConfig; //SwitchConfig; using JobType = Job; using None = typename JobType::None; using Concept = typename JobType::Concept; @@ -388,14 +400,15 @@ public: const Varying getOutput() const override { return _output; } Varying& editInput() override { return _input; } - SwitchConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) {} + SwitchConcept(const std::string& name, const Varying& input, QConfigPointer config) : Concept(name, config), _input(input) + {config->_isTask = true; config->_isSwitch = true; } template const Varying addBranch(std::string name, uint8_t index, const Varying& input, NA&&... args) { auto& branch = _branches[index]; branch = JobType(NT::JobModel::create(name, input, std::forward(args)...)); // Conect the child config to this task's config - std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(branch.getConfiguration(), name); + std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(branch.getConfiguration(), name); return branch.getOutput(); } @@ -405,7 +418,7 @@ public: } }; - template class SwitchModel : public SwitchConcept { + template class SwitchModel : public SwitchConcept { public: using Data = T; using Input = I; @@ -427,8 +440,8 @@ public: model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } // Recreate the Config to use the templated type - model->createConfiguration(); - model->applyConfiguration(); + // model->createConfiguration(); + // model->applyConfiguration(); return model; } @@ -475,8 +488,8 @@ public: } } }; - template using Model = SwitchModel; - template using ModelI = SwitchModel; + template using Model = SwitchModel; + template using ModelI = SwitchModel; // TODO: Switches don't support Outputs yet //template using ModelO = SwitchModel; //template using ModelIO = SwitchModel; @@ -500,7 +513,7 @@ class Engine : public Task { public: using Context = JC; using ContextPointer = std::shared_ptr; - using Config = TaskConfig; + using Config = JobConfig; //TaskConfig; using TaskType = Task; using ConceptPointer = typename TaskType::ConceptPointer; @@ -526,10 +539,11 @@ protected: } + #define Task_DeclareTypeAliases(ContextType, TimeProfiler) \ using JobConfig = task::JobConfig; \ - using TaskConfig = task::TaskConfig; \ - using SwitchConfig = task::SwitchConfig; \ + using TaskConfig = task::JobConfig; \ + using SwitchConfig = task::JobConfig; \ template using PersistentConfig = task::PersistentConfig; \ using Job = task::Job; \ using Switch = task::Switch; \ diff --git a/scripts/developer/utilities/lib/jet/jet.js b/scripts/developer/utilities/lib/jet/jet.js index 52c13c5279..4c3188a5cf 100644 --- a/scripts/developer/utilities/lib/jet/jet.js +++ b/scripts/developer/utilities/lib/jet/jet.js @@ -18,7 +18,7 @@ // @param depth: the depth of the recurse loop since the initial call. function task_traverse(root, functor, depth) { if (root.isTask()) { - depth++; + depth++; for (var i = 0; i Date: Wed, 31 Jul 2019 10:04:34 -0700 Subject: [PATCH 02/21] reduce locking necessary for render updates --- interface/src/octree/SafeLanding.cpp | 3 - .../src/RenderableEntityItem.cpp | 23 +- .../src/RenderableEntityItem.h | 1 - .../src/RenderableGizmoEntityItem.cpp | 20 +- .../src/RenderableGizmoEntityItem.h | 1 - .../src/RenderableGridEntityItem.cpp | 36 -- .../src/RenderableGridEntityItem.h | 2 - .../src/RenderableImageEntityItem.cpp | 40 -- .../src/RenderableImageEntityItem.h | 1 - .../src/RenderableLightEntityItem.cpp | 9 - .../src/RenderableLightEntityItem.h | 1 - .../src/RenderableLineEntityItem.cpp | 5 - .../src/RenderableLineEntityItem.h | 1 - .../src/RenderableMaterialEntityItem.cpp | 22 - .../src/RenderableModelEntityItem.cpp | 12 - .../RenderableParticleEffectEntityItem.cpp | 26 - .../src/RenderableParticleEffectEntityItem.h | 2 - .../src/RenderablePolyLineEntityItem.cpp | 10 +- .../src/RenderablePolyVoxEntityItem.cpp | 14 - .../src/RenderableShapeEntityItem.cpp | 17 +- .../src/RenderableTextEntityItem.cpp | 52 -- .../src/RenderableWebEntityItem.cpp | 36 -- libraries/entities/src/EntityItem.cpp | 68 +-- libraries/entities/src/EntityItem.h | 6 +- libraries/entities/src/GizmoEntityItem.cpp | 5 + libraries/entities/src/GridEntityItem.cpp | 33 +- libraries/entities/src/ImageEntityItem.cpp | 29 + libraries/entities/src/LightEntityItem.cpp | 45 +- libraries/entities/src/LightEntityItem.h | 5 - libraries/entities/src/LineEntityItem.cpp | 20 +- libraries/entities/src/LineEntityItem.h | 4 +- libraries/entities/src/MaterialEntityItem.cpp | 40 ++ libraries/entities/src/MaterialEntityItem.h | 4 +- libraries/entities/src/ModelEntityItem.cpp | 9 + .../entities/src/ParticleEffectEntityItem.cpp | 568 ++++++++++++++---- .../entities/src/ParticleEffectEntityItem.h | 70 +-- libraries/entities/src/PolyLineEntityItem.cpp | 15 + libraries/entities/src/PolyLineEntityItem.h | 6 +- libraries/entities/src/PolyVoxEntityItem.cpp | 82 ++- libraries/entities/src/ShapeEntityItem.cpp | 10 + libraries/entities/src/TextEntityItem.cpp | 57 +- libraries/entities/src/WebEntityItem.cpp | 50 +- 42 files changed, 853 insertions(+), 607 deletions(-) diff --git a/interface/src/octree/SafeLanding.cpp b/interface/src/octree/SafeLanding.cpp index ed779787c9..fbc35f2732 100644 --- a/interface/src/octree/SafeLanding.cpp +++ b/interface/src/octree/SafeLanding.cpp @@ -121,9 +121,6 @@ void SafeLanding::updateTracking() { if (isEntityPhysicsReady(entity) && isVisuallyReady) { entityMapIter = _trackedEntities.erase(entityMapIter); } else { - if (!isVisuallyReady) { - entity->requestRenderUpdate(); - } entityMapIter++; } } diff --git a/libraries/entities-renderer/src/RenderableEntityItem.cpp b/libraries/entities-renderer/src/RenderableEntityItem.cpp index 11e369b532..a822f030af 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableEntityItem.cpp @@ -128,12 +128,7 @@ std::shared_ptr make_renderer(const EntityItemPointer& entity) { return std::shared_ptr(new T(entity), [](T* ptr) { ptr->deleteLater(); }); } -EntityRenderer::EntityRenderer(const EntityItemPointer& entity) : _created(entity->getCreated()), _entity(entity) { - connect(entity.get(), &EntityItem::requestRenderUpdate, this, [&] { - _needsRenderUpdate = true; - emit requestRenderUpdate(); - }); -} +EntityRenderer::EntityRenderer(const EntityItemPointer& entity) : _created(entity->getCreated()), _entity(entity) {} EntityRenderer::~EntityRenderer() {} @@ -349,10 +344,6 @@ void EntityRenderer::updateInScene(const ScenePointer& scene, Transaction& trans // Returns true if the item needs to have updateInscene called because of internal rendering // changes (animation, fading, etc) bool EntityRenderer::needsRenderUpdate() const { - if (_needsRenderUpdate) { - return true; - } - if (isFading()) { return true; } @@ -365,6 +356,14 @@ bool EntityRenderer::needsRenderUpdate() const { // Returns true if the item in question needs to have updateInScene called because of changes in the entity bool EntityRenderer::needsRenderUpdateFromEntity(const EntityItemPointer& entity) const { + if (entity->needsRenderUpdate()) { + return true; + } + + if (!entity->isVisuallyReady()) { + return true; + } + bool success = false; auto bound = _entity->getAABox(success); if (success && _bound != bound) { @@ -403,7 +402,7 @@ void EntityRenderer::doRenderUpdateSynchronous(const ScenePointer& scene, Transa withWriteLock([&] { auto transparent = isTransparent(); auto fading = isFading(); - if (fading || _prevIsTransparent != transparent) { + if (fading || _prevIsTransparent != transparent || !entity->isVisuallyReady()) { emit requestRenderUpdate(); } if (fading) { @@ -421,7 +420,7 @@ void EntityRenderer::doRenderUpdateSynchronous(const ScenePointer& scene, Transa setPrimitiveMode(entity->getPrimitiveMode()); _canCastShadow = entity->getCanCastShadow(); _cauterized = entity->getCauterized(); - _needsRenderUpdate = false; + entity->setNeedsRenderUpdate(false); }); } diff --git a/libraries/entities-renderer/src/RenderableEntityItem.h b/libraries/entities-renderer/src/RenderableEntityItem.h index 1db4cfdf53..e365a16831 100644 --- a/libraries/entities-renderer/src/RenderableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableEntityItem.h @@ -143,7 +143,6 @@ protected: PrimitiveMode _primitiveMode { PrimitiveMode::SOLID }; bool _cauterized { false }; bool _moving { false }; - bool _needsRenderUpdate { false }; // Only touched on the rendering thread bool _renderUpdateQueued{ false }; Transform _renderTransform; diff --git a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp index 9468fdf3ef..a066107a15 100644 --- a/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableGizmoEntityItem.cpp @@ -14,9 +14,7 @@ using namespace render; using namespace render::entities; -GizmoEntityRenderer::GizmoEntityRenderer(const EntityItemPointer& entity) : Parent(entity) -{ -} +GizmoEntityRenderer::GizmoEntityRenderer(const EntityItemPointer& entity) : Parent(entity) {} GizmoEntityRenderer::~GizmoEntityRenderer() { auto geometryCache = DependencyManager::get(); @@ -41,22 +39,6 @@ bool GizmoEntityRenderer::isTransparent() const { return Parent::isTransparent() || ringTransparent; } -bool GizmoEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - bool needsUpdate = resultWithReadLock([&] { - if (_gizmoType != entity->getGizmoType()) { - return true; - } - - if (_ringProperties != entity->getRingProperties()) { - return true; - } - - return false; - }); - - return needsUpdate; -} - void GizmoEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) { bool dirty = false; RingGizmoPropertyGroup ringProperties = entity->getRingProperties(); diff --git a/libraries/entities-renderer/src/RenderableGizmoEntityItem.h b/libraries/entities-renderer/src/RenderableGizmoEntityItem.h index ba59fdc728..c072f482cd 100644 --- a/libraries/entities-renderer/src/RenderableGizmoEntityItem.h +++ b/libraries/entities-renderer/src/RenderableGizmoEntityItem.h @@ -29,7 +29,6 @@ protected: bool isTransparent() const override; private: - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override; virtual void doRender(RenderArgs* args) override; diff --git a/libraries/entities-renderer/src/RenderableGridEntityItem.cpp b/libraries/entities-renderer/src/RenderableGridEntityItem.cpp index d8f0d93bb6..0b074f7a81 100644 --- a/libraries/entities-renderer/src/RenderableGridEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableGridEntityItem.cpp @@ -29,42 +29,6 @@ bool GridEntityRenderer::isTransparent() const { return Parent::isTransparent() || _alpha < 1.0f || _pulseProperties.getAlphaMode() != PulseMode::NONE; } -bool GridEntityRenderer::needsRenderUpdate() const { - return Parent::needsRenderUpdate(); -} - -bool GridEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - bool needsUpdate = resultWithReadLock([&] { - if (_color != entity->getColor()) { - return true; - } - - if (_alpha != entity->getAlpha()) { - return true; - } - - if (_followCamera != entity->getFollowCamera()) { - return true; - } - - if (_majorGridEvery != entity->getMajorGridEvery()) { - return true; - } - - if (_minorGridEvery != entity->getMinorGridEvery()) { - return true; - } - - if (_pulseProperties != entity->getPulseProperties()) { - return true; - } - - return false; - }); - - return needsUpdate; -} - void GridEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { withWriteLock([&] { _color = entity->getColor(); diff --git a/libraries/entities-renderer/src/RenderableGridEntityItem.h b/libraries/entities-renderer/src/RenderableGridEntityItem.h index 45124fdb94..2ecff01d01 100644 --- a/libraries/entities-renderer/src/RenderableGridEntityItem.h +++ b/libraries/entities-renderer/src/RenderableGridEntityItem.h @@ -29,8 +29,6 @@ protected: bool isTransparent() const override; private: - virtual bool needsRenderUpdate() const override; - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override; virtual void doRender(RenderArgs* args) override; diff --git a/libraries/entities-renderer/src/RenderableImageEntityItem.cpp b/libraries/entities-renderer/src/RenderableImageEntityItem.cpp index 3a4dbf5c6f..acdf5a35de 100644 --- a/libraries/entities-renderer/src/RenderableImageEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableImageEntityItem.cpp @@ -41,46 +41,6 @@ bool ImageEntityRenderer::needsRenderUpdate() const { return Parent::needsRenderUpdate(); } -bool ImageEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - bool needsUpdate = resultWithReadLock([&] { - if (_imageURL != entity->getImageURL()) { - return true; - } - - if (_emissive != entity->getEmissive()) { - return true; - } - - if (_keepAspectRatio != entity->getKeepAspectRatio()) { - return true; - } - - if (_billboardMode != entity->getBillboardMode()) { - return true; - } - - if (_subImage != entity->getSubImage()) { - return true; - } - - if (_color != entity->getColor()) { - return true; - } - - if (_alpha != entity->getAlpha()) { - return true; - } - - if (_pulseProperties != entity->getPulseProperties()) { - return true; - } - - return false; - }); - - return needsUpdate; -} - void ImageEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { withWriteLock([&] { auto imageURL = entity->getImageURL(); diff --git a/libraries/entities-renderer/src/RenderableImageEntityItem.h b/libraries/entities-renderer/src/RenderableImageEntityItem.h index e686452fa5..d73bc9bc05 100644 --- a/libraries/entities-renderer/src/RenderableImageEntityItem.h +++ b/libraries/entities-renderer/src/RenderableImageEntityItem.h @@ -30,7 +30,6 @@ protected: private: virtual bool needsRenderUpdate() const override; - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override; virtual void doRender(RenderArgs* args) override; diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index d746ec1ea9..9eb2e8428d 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -18,11 +18,6 @@ using namespace render; using namespace render::entities; void LightEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) { - // Reset the value before reading the data! - // otherwise there could be a race condition where the value changes - // after we read it but before we reset, and we never see the change - entity->resetLightPropertiesChanged(); - auto& lightPayload = *_lightPayload; lightPayload.setVisible(_visible); @@ -69,10 +64,6 @@ Item::Bound LightEntityRenderer::getBound() { return payloadGetBound(_lightPayload); } -bool LightEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - return entity->lightPropertiesChanged(); -} - void LightEntityRenderer::doRender(RenderArgs* args) { _lightPayload->render(args); } diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.h b/libraries/entities-renderer/src/RenderableLightEntityItem.h index 7d75261d03..323f280795 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.h @@ -26,7 +26,6 @@ public: LightEntityRenderer(const EntityItemPointer& entity) : Parent(entity) { } protected: - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override; virtual ItemKey getKey() override; diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp index cbe2a98166..aaef0b3f7d 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.cpp @@ -26,12 +26,7 @@ void LineEntityRenderer::onRemoveFromSceneTyped(const TypedEntityPointer& entity } } -bool LineEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - return entity->pointsChanged(); -} - void LineEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) { - entity->resetPointsChanged(); _linePoints = entity->getLinePoints(); auto geometryCache = DependencyManager::get(); if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { diff --git a/libraries/entities-renderer/src/RenderableLineEntityItem.h b/libraries/entities-renderer/src/RenderableLineEntityItem.h index 799ba5b78c..c310da8271 100644 --- a/libraries/entities-renderer/src/RenderableLineEntityItem.h +++ b/libraries/entities-renderer/src/RenderableLineEntityItem.h @@ -28,7 +28,6 @@ public: protected: virtual void onRemoveFromSceneTyped(const TypedEntityPointer& entity) override; - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override; virtual void doRender(RenderArgs* args) override; diff --git a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp index 22e3205531..eae0561343 100644 --- a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp @@ -26,37 +26,15 @@ bool MaterialEntityRenderer::needsRenderUpdate() const { bool MaterialEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { if (resultWithReadLock([&] { - if (entity->getMaterialMappingMode() != _materialMappingMode) { - return true; - } - if (entity->getMaterialRepeat() != _materialRepeat) { - return true; - } - if (entity->getMaterialMappingPos() != _materialMappingPos || entity->getMaterialMappingScale() != _materialMappingScale || entity->getMaterialMappingRot() != _materialMappingRot) { - return true; - } if (entity->getTransform() != _transform) { return true; } if (entity->getUnscaledDimensions() != _dimensions) { return true; } - - if (entity->getMaterialURL() != _materialURL) { - return true; - } - if (entity->getMaterialData() != _materialData) { - return true; - } - if (entity->getParentMaterialName() != _parentMaterialName) { - return true; - } if (entity->getParentID() != _parentID) { return true; } - if (entity->getPriority() != _priority) { - return true; - } return false; })) { diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 9d23bd09ad..6314cc8ce4 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -1229,19 +1229,11 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin return true; } - if (_parsedModelURL != entity->getModelURL()) { - return true; - } - // No model to render, early exit if (!_hasModel) { return false; } - if (_textures != entity->getTextures()) { - return true; - } - if (_animating != entity->isAnimatingSomething()) { return true; } @@ -1275,10 +1267,6 @@ bool ModelEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPoin model->getRegistrationPoint() != entity->getRegistrationPoint()) { return true; } - - if (model->isGroupCulled() != entity->getGroupCulled()) { - return true; - } } return false; diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp index 36f8ccf8f6..e3528e2291 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.cpp @@ -64,32 +64,6 @@ ParticleEffectEntityRenderer::ParticleEffectEntityRenderer(const EntityItemPoint }); } -bool ParticleEffectEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - entity->updateQueryAACube(); - - if (_emitting != entity->getIsEmitting()) { - return true; - } - - if (_particleProperties != entity->getParticleProperties()) { - return true; - } - - if (_pulseProperties != entity->getPulseProperties()) { - return true; - } - - if (_shapeType != entity->getShapeType()) { - return true; - } - - if (_compoundShapeURL != entity->getCompoundShapeURL()) { - return true; - } - - return false; -} - void ParticleEffectEntityRenderer::doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) { auto newParticleProperties = entity->getParticleProperties(); if (!newParticleProperties.valid()) { diff --git a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h index d13c966e96..cc907f2b1d 100644 --- a/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h +++ b/libraries/entities-renderer/src/RenderableParticleEffectEntityItem.h @@ -25,8 +25,6 @@ public: ParticleEffectEntityRenderer(const EntityItemPointer& entity); protected: - virtual bool needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const override; - virtual void doRenderUpdateSynchronousTyped(const ScenePointer& scene, Transaction& transaction, const TypedEntityPointer& entity) override; virtual void doRenderUpdateAsynchronousTyped(const TypedEntityPointer& entity) override; diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 6cdc25d7b3..f3d0e6a5eb 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -75,11 +75,9 @@ ShapeKey PolyLineEntityRenderer::getShapeKey() { } bool PolyLineEntityRenderer::needsRenderUpdate() const { - bool textureLoadedChanged = resultWithReadLock([&] { + if (resultWithReadLock([&] { return (!_textureLoaded && _texture && _texture->isLoaded()); - }); - - if (textureLoadedChanged) { + })) { return true; } @@ -91,10 +89,6 @@ bool PolyLineEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityP return true; } - if (_isUVModeStretch != entity->getIsUVModeStretch() || _glow != entity->getGlow() || _faceCamera != entity->getFaceCamera()) { - return true; - } - return Parent::needsRenderUpdateFromTypedEntity(entity); } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 3adeecabcc..3574544bba 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -1616,20 +1616,6 @@ ShapeKey PolyVoxEntityRenderer::getShapeKey() { } bool PolyVoxEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - std::array xyzTextureURLs{ { - entity->getXTextureURL(), - entity->getYTextureURL(), - entity->getZTextureURL() - } }; - - if (xyzTextureURLs != _xyzTextureUrls) { - return true; - } - - if (entity->getVoxelVolumeSize() != _lastVoxelVolumeSize) { - return true; - } - if (entity->voxelToWorldMatrix() != _lastVoxelToWorldMatrix) { return true; } diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 032e8e1892..4f1ebaecb9 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -63,26 +63,11 @@ bool ShapeEntityRenderer::needsRenderUpdate() const { } bool ShapeEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - if (_lastUserData != entity->getUserData()) { - return true; - } - - if (_color != toGlm(entity->getColor())) { - return true; - } - if (_alpha != entity->getAlpha()) { - return true; - } - - if (_shape != entity->getShape()) { - return true; - } - if (_dimensions != entity->getScaledDimensions()) { return true; } - if (_pulseProperties != entity->getPulseProperties()) { + if (_lastUserData != entity->getUserData()) { return true; } diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 0ead1de71a..e6237fc0d0 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -93,62 +93,10 @@ uint32_t TextEntityRenderer::metaFetchMetaSubItems(ItemIDs& subItems) const { } bool TextEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointer& entity) const { - if (_text != entity->getText()) { - return true; - } - - if (_lineHeight != entity->getLineHeight()) { - return true; - } - - if (_textColor != toGlm(entity->getTextColor())) { - return true; - } - - if (_textAlpha != entity->getTextAlpha()) { - return true; - } - - if (_backgroundColor != toGlm(entity->getBackgroundColor())) { - return true; - } - - if (_backgroundAlpha != entity->getBackgroundAlpha()) { - return true; - } - if (_dimensions != entity->getScaledDimensions()) { return true; } - if (_billboardMode != entity->getBillboardMode()) { - return true; - } - - if (_leftMargin != entity->getLeftMargin()) { - return true; - } - - if (_rightMargin != entity->getRightMargin()) { - return true; - } - - if (_topMargin != entity->getTopMargin()) { - return true; - } - - if (_bottomMargin != entity->getBottomMargin()) { - return true; - } - - if (_unlit != entity->getUnlit()) { - return true; - } - - if (_pulseProperties != entity->getPulseProperties()) { - return true; - } - return false; } diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index 00be4a2f7d..a1d24fe52e 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -111,42 +111,6 @@ bool WebEntityRenderer::needsRenderUpdateFromTypedEntity(const TypedEntityPointe return true; } - if (_color != entity->getColor()) { - return true; - } - - if (_alpha != entity->getAlpha()) { - return true; - } - - if (_billboardMode != entity->getBillboardMode()) { - return true; - } - - if (_sourceURL != entity->getSourceUrl()) { - return true; - } - - if (_dpi != entity->getDPI()) { - return true; - } - - if (_scriptURL != entity->getScriptURL()) { - return true; - } - - if (_maxFPS != entity->getMaxFPS()) { - return true; - } - - if (_inputMode != entity->getInputMode()) { - return true; - } - - if (_pulseProperties != entity->getPulseProperties()) { - return true; - } - return false; })) { return true; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index d39924dcd3..fc45572aea 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -2943,17 +2943,15 @@ bool EntityItem::getVisible() const { } void EntityItem::setVisible(bool value) { - bool changed = false; + bool changed; withWriteLock([&] { - if (_visible != value) { - changed = true; - _visible = value; - } + changed = _visible != value; + _visible = value; }); + _needsRenderUpdate |= changed; if (changed) { bumpAncestorChainRenderableVersion(); - emit requestRenderUpdate(); } } @@ -2966,17 +2964,13 @@ bool EntityItem::isVisibleInSecondaryCamera() const { } void EntityItem::setIsVisibleInSecondaryCamera(bool value) { - bool changed = false; + bool changed; withWriteLock([&] { - if (_isVisibleInSecondaryCamera != value) { - changed = true; - _isVisibleInSecondaryCamera = value; - } + changed = _isVisibleInSecondaryCamera != value; + _isVisibleInSecondaryCamera = value; }); - if (changed) { - emit requestRenderUpdate(); - } + _needsRenderUpdate |= changed; } RenderLayer EntityItem::getRenderLayer() const { @@ -2986,17 +2980,13 @@ RenderLayer EntityItem::getRenderLayer() const { } void EntityItem::setRenderLayer(RenderLayer value) { - bool changed = false; + bool changed; withWriteLock([&] { - if (_renderLayer != value) { - changed = true; - _renderLayer = value; - } + changed = _renderLayer != value; + _renderLayer = value; }); - if (changed) { - emit requestRenderUpdate(); - } + _needsRenderUpdate |= changed; } PrimitiveMode EntityItem::getPrimitiveMode() const { @@ -3008,15 +2998,11 @@ PrimitiveMode EntityItem::getPrimitiveMode() const { void EntityItem::setPrimitiveMode(PrimitiveMode value) { bool changed = false; withWriteLock([&] { - if (_primitiveMode != value) { - changed = true; - _primitiveMode = value; - } + changed = _primitiveMode != value; + _primitiveMode = value; }); - if (changed) { - emit requestRenderUpdate(); - } + _needsRenderUpdate |= changed; } bool EntityItem::getCauterized() const { @@ -3026,17 +3012,13 @@ bool EntityItem::getCauterized() const { } void EntityItem::setCauterized(bool value) { - bool changed = false; + bool changed; withWriteLock([&] { - if (_cauterized != value) { - changed = true; - _cauterized = value; - } + changed = _cauterized != value; + _cauterized = value; }); - if (changed) { - emit requestRenderUpdate(); - } + _needsRenderUpdate |= changed; } bool EntityItem::getIgnorePickIntersection() const { @@ -3060,17 +3042,13 @@ bool EntityItem::getCanCastShadow() const { } void EntityItem::setCanCastShadow(bool value) { - bool changed = false; + bool changed; withWriteLock([&] { - if (_canCastShadow != value) { - changed = true; - _canCastShadow = value; - } + changed = _canCastShadow != value; + _canCastShadow = value; }); - if (changed) { - emit requestRenderUpdate(); - } + _needsRenderUpdate |= changed; } bool EntityItem::isChildOfMyAvatar() const { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index d137f84e16..8114fa0c2f 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -571,8 +571,10 @@ public: bool stillHasMyGrabAction() const; + bool needsRenderUpdate() const { return _needsRenderUpdate; } + void setNeedsRenderUpdate(bool needsRenderUpdate) { _needsRenderUpdate = needsRenderUpdate; } + signals: - void requestRenderUpdate(); void spaceUpdate(std::pair data); protected: @@ -760,6 +762,8 @@ protected: QHash _grabActions; + mutable bool _needsRenderUpdate { false }; + private: static std::function _getBillboardRotationOperator; static std::function _getPrimaryViewFrustumPositionOperator; diff --git a/libraries/entities/src/GizmoEntityItem.cpp b/libraries/entities/src/GizmoEntityItem.cpp index f2bef0cb80..671e6e5543 100644 --- a/libraries/entities/src/GizmoEntityItem.cpp +++ b/libraries/entities/src/GizmoEntityItem.cpp @@ -46,6 +46,7 @@ bool GizmoEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool ringPropertiesChanged = _ringProperties.setProperties(properties); somethingChanged |= ringPropertiesChanged; + _needsRenderUpdate |= ringPropertiesChanged; }); if (somethingChanged) { @@ -184,9 +185,13 @@ bool GizmoEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, } void GizmoEntityItem::setGizmoType(GizmoType value) { + bool changed; withWriteLock([&] { + changed = _gizmoType != value; _gizmoType = value; }); + + _needsRenderUpdate |= changed; } GizmoType GizmoEntityItem::getGizmoType() const { diff --git a/libraries/entities/src/GridEntityItem.cpp b/libraries/entities/src/GridEntityItem.cpp index d8d070416b..e826962572 100644 --- a/libraries/entities/src/GridEntityItem.cpp +++ b/libraries/entities/src/GridEntityItem.cpp @@ -54,6 +54,7 @@ bool GridEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(followCamera, setFollowCamera); @@ -135,9 +136,13 @@ void GridEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits } void GridEntityItem::setColor(const glm::u8vec3& color) { + bool changed; withWriteLock([&] { + changed = _color != color; _color = color; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 GridEntityItem::getColor() const { @@ -147,9 +152,13 @@ glm::u8vec3 GridEntityItem::getColor() const { } void GridEntityItem::setAlpha(float alpha) { + bool changed; withWriteLock([&] { + changed = _alpha != alpha; _alpha = alpha; }); + + _needsRenderUpdate |= changed; } float GridEntityItem::getAlpha() const { @@ -159,9 +168,13 @@ float GridEntityItem::getAlpha() const { } void GridEntityItem::setFollowCamera(bool followCamera) { + bool changed; withWriteLock([&] { + changed = _followCamera != followCamera; _followCamera = followCamera; }); + + _needsRenderUpdate |= changed; } bool GridEntityItem::getFollowCamera() const { @@ -171,10 +184,16 @@ bool GridEntityItem::getFollowCamera() const { } void GridEntityItem::setMajorGridEvery(uint32_t majorGridEvery) { + const uint32_t MAJOR_GRID_EVERY_MIN = 1; + majorGridEvery = std::max(majorGridEvery, MAJOR_GRID_EVERY_MIN); + + bool changed; withWriteLock([&] { - const uint32_t MAJOR_GRID_EVERY_MIN = 1; - _majorGridEvery = std::max(majorGridEvery, MAJOR_GRID_EVERY_MIN); + changed = _majorGridEvery != majorGridEvery; + _majorGridEvery = majorGridEvery; }); + + _needsRenderUpdate |= changed; } uint32_t GridEntityItem::getMajorGridEvery() const { @@ -184,10 +203,16 @@ uint32_t GridEntityItem::getMajorGridEvery() const { } void GridEntityItem::setMinorGridEvery(float minorGridEvery) { + const float MINOR_GRID_EVERY_MIN = 0.01f; + minorGridEvery = std::max(minorGridEvery, MINOR_GRID_EVERY_MIN); + + bool changed; withWriteLock([&] { - const float MINOR_GRID_EVERY_MIN = 0.01f; - _minorGridEvery = std::max(minorGridEvery, MINOR_GRID_EVERY_MIN); + changed = _minorGridEvery != minorGridEvery; + _minorGridEvery = minorGridEvery; }); + + _needsRenderUpdate |= changed; } float GridEntityItem::getMinorGridEvery() const { diff --git a/libraries/entities/src/ImageEntityItem.cpp b/libraries/entities/src/ImageEntityItem.cpp index 090ae91277..80c526b31b 100644 --- a/libraries/entities/src/ImageEntityItem.cpp +++ b/libraries/entities/src/ImageEntityItem.cpp @@ -53,6 +53,7 @@ bool ImageEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(billboardMode, setBillboardMode); @@ -213,9 +214,13 @@ QString ImageEntityItem::getImageURL() const { } void ImageEntityItem::setImageURL(const QString& url) { + bool changed; withWriteLock([&] { + changed = _imageURL != url; _imageURL = url; }); + + _needsRenderUpdate |= changed; } bool ImageEntityItem::getEmissive() const { @@ -227,9 +232,13 @@ bool ImageEntityItem::getEmissive() const { } void ImageEntityItem::setEmissive(bool emissive) { + bool changed; withWriteLock([&] { + changed = _emissive != emissive; _emissive = emissive; }); + + _needsRenderUpdate |= changed; } bool ImageEntityItem::getKeepAspectRatio() const { @@ -241,9 +250,13 @@ bool ImageEntityItem::getKeepAspectRatio() const { } void ImageEntityItem::setKeepAspectRatio(bool keepAspectRatio) { + bool changed; withWriteLock([&] { + changed = _keepAspectRatio != keepAspectRatio; _keepAspectRatio = keepAspectRatio; }); + + _needsRenderUpdate |= changed; } BillboardMode ImageEntityItem::getBillboardMode() const { @@ -255,9 +268,13 @@ BillboardMode ImageEntityItem::getBillboardMode() const { } void ImageEntityItem::setBillboardMode(BillboardMode value) { + bool changed; withWriteLock([&] { + changed = _billboardMode != value; _billboardMode = value; }); + + _needsRenderUpdate |= changed; } QRect ImageEntityItem::getSubImage() const { @@ -269,15 +286,23 @@ QRect ImageEntityItem::getSubImage() const { } void ImageEntityItem::setSubImage(const QRect& subImage) { + bool changed; withWriteLock([&] { + changed = _subImage != subImage; _subImage = subImage; }); + + _needsRenderUpdate |= changed; } void ImageEntityItem::setColor(const glm::u8vec3& color) { + bool changed; withWriteLock([&] { + changed = _color != color; _color = color; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 ImageEntityItem::getColor() const { @@ -287,9 +312,13 @@ glm::u8vec3 ImageEntityItem::getColor() const { } void ImageEntityItem::setAlpha(float alpha) { + bool changed; withWriteLock([&] { + changed = _alpha != alpha; _alpha = alpha; }); + + _needsRenderUpdate |= changed; } float ImageEntityItem::getAlpha() const { diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index fcfda66319..c7638a8488 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -57,16 +57,12 @@ void LightEntityItem::setUnscaledDimensions(const glm::vec3& value) { void LightEntityItem::locationChanged(bool tellPhysics, bool tellChildren) { EntityItem::locationChanged(tellPhysics, tellChildren); - withWriteLock([&] { - _lightPropertiesChanged = true; - }); + _needsRenderUpdate = true; } void LightEntityItem::dimensionsChanged() { EntityItem::dimensionsChanged(); - withWriteLock([&] { - _lightPropertiesChanged = true; - }); + _needsRenderUpdate = true; } @@ -85,13 +81,14 @@ EntityItemProperties LightEntityItem::getProperties(const EntityPropertyFlags& d void LightEntityItem::setFalloffRadius(float value) { value = glm::max(value, 0.0f); - if (value == getFalloffRadius()) { - return; - } + + bool changed; withWriteLock([&] { + changed = _falloffRadius != value; _falloffRadius = value; - _lightPropertiesChanged = true; }); + + _needsRenderUpdate |= changed; } void LightEntityItem::setIsSpotlight(bool value) { @@ -111,9 +108,10 @@ void LightEntityItem::setIsSpotlight(bool value) { withWriteLock([&] { _isSpotlight = value; - _lightPropertiesChanged = true; }); setScaledDimensions(newDimensions); + + _needsRenderUpdate = true; } void LightEntityItem::setCutoff(float value) { @@ -133,10 +131,8 @@ void LightEntityItem::setCutoff(float value) { const float width = length * glm::sin(glm::radians(_cutoff)); setScaledDimensions(glm::vec3(width, width, length)); } - - withWriteLock([&] { - _lightPropertiesChanged = true; - }); + + _needsRenderUpdate = true; } bool LightEntityItem::setProperties(const EntityItemProperties& properties) { @@ -222,10 +218,13 @@ glm::u8vec3 LightEntityItem::getColor() const { } void LightEntityItem::setColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _color != value; _color = value; - _lightPropertiesChanged = true; }); + + _needsRenderUpdate |= changed; } bool LightEntityItem::getIsSpotlight() const { @@ -245,10 +244,13 @@ float LightEntityItem::getIntensity() const { } void LightEntityItem::setIntensity(float value) { + bool changed; withWriteLock([&] { + changed = _intensity != value; _intensity = value; - _lightPropertiesChanged = true; }); + + _needsRenderUpdate |= changed; } float LightEntityItem::getFalloffRadius() const { @@ -268,10 +270,13 @@ float LightEntityItem::getExponent() const { } void LightEntityItem::setExponent(float value) { + bool changed; withWriteLock([&] { + changed = _exponent != value; _exponent = value; - _lightPropertiesChanged = true; }); + + _needsRenderUpdate |= changed; } float LightEntityItem::getCutoff() const { @@ -282,10 +287,6 @@ float LightEntityItem::getCutoff() const { return result; } -void LightEntityItem::resetLightPropertiesChanged() { - withWriteLock([&] { _lightPropertiesChanged = false; }); -} - bool LightEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, BoxFace& face, glm::vec3& surfaceNormal, diff --git a/libraries/entities/src/LightEntityItem.h b/libraries/entities/src/LightEntityItem.h index cc64121cb3..8194ff8308 100644 --- a/libraries/entities/src/LightEntityItem.h +++ b/libraries/entities/src/LightEntityItem.h @@ -77,9 +77,6 @@ public: virtual void locationChanged(bool tellPhysics, bool tellChildren) override; virtual void dimensionsChanged() override; - bool lightPropertiesChanged() const { return _lightPropertiesChanged; } - void resetLightPropertiesChanged(); - virtual bool supportsDetailedIntersection() const override { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, OctreeElementPointer& element, float& distance, @@ -98,8 +95,6 @@ private: float _falloffRadius { DEFAULT_FALLOFF_RADIUS }; float _exponent { DEFAULT_EXPONENT }; float _cutoff { DEFAULT_CUTOFF }; - // Dirty flag turn true when either light properties is changing values. - bool _lightPropertiesChanged { false }; static bool _lightsArePickable; }; diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index acb5bc08f6..ad2b5ef1b8 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -77,8 +77,10 @@ bool LineEntityItem::appendPoint(const glm::vec3& point) { } withWriteLock([&] { _points << point; - _pointsChanged = true; }); + + _needsRenderUpdate = true; + return true; } @@ -97,8 +99,10 @@ bool LineEntityItem::setLinePoints(const QVector& points) { withWriteLock([&] { _points = points; - _pointsChanged = true; }); + + _needsRenderUpdate = true; + return true; } @@ -154,9 +158,13 @@ glm::u8vec3 LineEntityItem::getColor() const { } void LineEntityItem::setColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _color != value; _color = value; }); + + _needsRenderUpdate |= changed; } QVector LineEntityItem::getLinePoints() const { @@ -165,10 +173,4 @@ QVector LineEntityItem::getLinePoints() const { result = _points; }); return result; -} - -void LineEntityItem::resetPointsChanged() { - withWriteLock([&] { - _pointsChanged = false; - }); -} +} \ No newline at end of file diff --git a/libraries/entities/src/LineEntityItem.h b/libraries/entities/src/LineEntityItem.h index 098183299f..ee473225fe 100644 --- a/libraries/entities/src/LineEntityItem.h +++ b/libraries/entities/src/LineEntityItem.h @@ -61,15 +61,13 @@ class LineEntityItem : public EntityItem { BoxFace& face, glm::vec3& surfaceNormal, QVariantMap& extraInfo, bool precisionPicking) const override { return false; } - bool pointsChanged() const { return _pointsChanged; } - void resetPointsChanged(); + virtual void debugDump() const override; static const int MAX_POINTS_PER_LINE; private: glm::u8vec3 _color; QVector _points; - bool _pointsChanged { true }; }; #endif // hifi_LineEntityItem_h diff --git a/libraries/entities/src/MaterialEntityItem.cpp b/libraries/entities/src/MaterialEntityItem.cpp index 3a363f2e83..c4ad52ef95 100644 --- a/libraries/entities/src/MaterialEntityItem.cpp +++ b/libraries/entities/src/MaterialEntityItem.cpp @@ -153,9 +153,13 @@ QString MaterialEntityItem::getMaterialURL() const { } void MaterialEntityItem::setMaterialURL(const QString& materialURL) { + bool changed; withWriteLock([&] { + changed = _materialURL != materialURL; _materialURL = materialURL; }); + + _needsRenderUpdate |= changed; } QString MaterialEntityItem::getMaterialData() const { @@ -165,9 +169,13 @@ QString MaterialEntityItem::getMaterialData() const { } void MaterialEntityItem::setMaterialData(const QString& materialData) { + bool changed; withWriteLock([&] { + changed = _materialData != materialData; _materialData = materialData; }); + + _needsRenderUpdate |= changed; } MaterialMappingMode MaterialEntityItem::getMaterialMappingMode() const { @@ -177,9 +185,12 @@ MaterialMappingMode MaterialEntityItem::getMaterialMappingMode() const { } void MaterialEntityItem::setMaterialMappingMode(MaterialMappingMode mode) { + bool changed; withWriteLock([&] { + changed = _materialMappingMode != mode; _materialMappingMode = mode; }); + _needsRenderUpdate |= changed; setUnscaledDimensions(_desiredDimensions); } @@ -190,9 +201,13 @@ quint16 MaterialEntityItem::getPriority() const { } void MaterialEntityItem::setPriority(quint16 priority) { + bool changed; withWriteLock([&] { + changed = _priority != priority; _priority = priority; }); + + _needsRenderUpdate |= changed; } QString MaterialEntityItem::getParentMaterialName() const { @@ -202,9 +217,13 @@ QString MaterialEntityItem::getParentMaterialName() const { } void MaterialEntityItem::setParentMaterialName(const QString& parentMaterialName) { + bool changed; withWriteLock([&] { + changed = _parentMaterialName != parentMaterialName; _parentMaterialName = parentMaterialName; }); + + _needsRenderUpdate |= changed; } glm::vec2 MaterialEntityItem::getMaterialMappingPos() const { @@ -214,9 +233,13 @@ glm::vec2 MaterialEntityItem::getMaterialMappingPos() const { } void MaterialEntityItem::setMaterialMappingPos(const glm::vec2& materialMappingPos) { + bool changed; withWriteLock([&] { + changed = _materialMappingPos != materialMappingPos; _materialMappingPos = materialMappingPos; }); + + _needsRenderUpdate |= changed; } glm::vec2 MaterialEntityItem::getMaterialMappingScale() const { @@ -226,9 +249,13 @@ glm::vec2 MaterialEntityItem::getMaterialMappingScale() const { } void MaterialEntityItem::setMaterialMappingScale(const glm::vec2& materialMappingScale) { + bool changed; withWriteLock([&] { + changed = _materialMappingScale != materialMappingScale; _materialMappingScale = materialMappingScale; }); + + _needsRenderUpdate |= changed; } float MaterialEntityItem::getMaterialMappingRot() const { @@ -238,9 +265,22 @@ float MaterialEntityItem::getMaterialMappingRot() const { } void MaterialEntityItem::setMaterialMappingRot(float materialMappingRot) { + bool changed; withWriteLock([&] { + changed = _materialMappingRot != materialMappingRot; _materialMappingRot = materialMappingRot; }); + + _needsRenderUpdate |= changed; +} + +bool MaterialEntityItem::getMaterialRepeat() const { + return _materialRepeat; +} + +void MaterialEntityItem::setMaterialRepeat(bool value) { + _needsRenderUpdate |= _materialRepeat != value; + _materialRepeat = value; } AACube MaterialEntityItem::calculateInitialQueryAACube(bool& success) { diff --git a/libraries/entities/src/MaterialEntityItem.h b/libraries/entities/src/MaterialEntityItem.h index 717ceb4ee0..3f32486f0b 100644 --- a/libraries/entities/src/MaterialEntityItem.h +++ b/libraries/entities/src/MaterialEntityItem.h @@ -55,8 +55,8 @@ public: MaterialMappingMode getMaterialMappingMode() const; void setMaterialMappingMode(MaterialMappingMode mode); - bool getMaterialRepeat() const { return _materialRepeat; } - void setMaterialRepeat(bool repeat) { _materialRepeat = repeat; } + bool getMaterialRepeat() const; + void setMaterialRepeat(bool repeat); quint16 getPriority() const; void setPriority(quint16 priority); diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index f276bea05d..71068c3d0d 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -49,9 +49,13 @@ const QString ModelEntityItem::getTextures() const { } void ModelEntityItem::setTextures(const QString& textures) { + bool changed; withWriteLock([&] { + changed = _textures != textures; _textures = textures; }); + + _needsRenderUpdate |= changed; } EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const { @@ -295,6 +299,7 @@ void ModelEntityItem::setModelURL(const QString& url) { if (_modelURL != url) { _modelURL = url; _flags |= Simulation::DIRTY_SHAPE | Simulation::DIRTY_MASS; + _needsRenderUpdate = true; } }); } @@ -575,9 +580,13 @@ bool ModelEntityItem::getRelayParentJoints() const { } void ModelEntityItem::setGroupCulled(bool value) { + bool changed; withWriteLock([&] { + changed = _groupCulled != value; _groupCulled = value; }); + + _needsRenderUpdate |= changed; } bool ModelEntityItem::getGroupCulled() const { diff --git a/libraries/entities/src/ParticleEffectEntityItem.cpp b/libraries/entities/src/ParticleEffectEntityItem.cpp index 12119f1466..1dbfaff2b3 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.cpp +++ b/libraries/entities/src/ParticleEffectEntityItem.cpp @@ -167,211 +167,499 @@ ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityIte } void ParticleEffectEntityItem::setAlpha(float alpha) { + alpha = glm::clamp(alpha, MINIMUM_ALPHA, MAXIMUM_ALPHA); + + bool changed; withWriteLock([&] { - _particleProperties.alpha.gradient.target = glm::clamp(alpha, MINIMUM_ALPHA, MAXIMUM_ALPHA); + changed = _particleProperties.alpha.gradient.target != alpha; + _particleProperties.alpha.gradient.target = alpha; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAlpha() const { + return resultWithReadLock([&] { + return _particleProperties.alpha.gradient.target; }); } void ParticleEffectEntityItem::setAlphaStart(float alphaStart) { + alphaStart = glm::isnan(alphaStart) ? alphaStart : glm::clamp(alphaStart, MINIMUM_ALPHA, MAXIMUM_ALPHA); + + bool changed; withWriteLock([&] { - _particleProperties.alpha.range.start = glm::isnan(alphaStart) ? alphaStart : glm::clamp(alphaStart, MINIMUM_ALPHA, MAXIMUM_ALPHA); + changed = _particleProperties.alpha.range.start != alphaStart; + _particleProperties.alpha.range.start = alphaStart; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAlphaStart() const { + return resultWithReadLock([&] { + return _particleProperties.alpha.range.start; }); } void ParticleEffectEntityItem::setAlphaFinish(float alphaFinish) { + alphaFinish = glm::isnan(alphaFinish) ? alphaFinish : glm::clamp(alphaFinish, MINIMUM_ALPHA, MAXIMUM_ALPHA); + + bool changed; withWriteLock([&] { - _particleProperties.alpha.range.finish = glm::isnan(alphaFinish) ? alphaFinish : glm::clamp(alphaFinish, MINIMUM_ALPHA, MAXIMUM_ALPHA); + changed = _particleProperties.alpha.range.finish != alphaFinish; + _particleProperties.alpha.range.finish = alphaFinish; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAlphaFinish() const { + return resultWithReadLock([&] { + return _particleProperties.alpha.range.finish; }); } void ParticleEffectEntityItem::setAlphaSpread(float alphaSpread) { + alphaSpread = glm::clamp(alphaSpread, MINIMUM_ALPHA, MAXIMUM_ALPHA); + + bool changed; withWriteLock([&] { - _particleProperties.alpha.gradient.spread = glm::clamp(alphaSpread, MINIMUM_ALPHA, MAXIMUM_ALPHA); + changed = _particleProperties.alpha.gradient.spread != alphaSpread; + _particleProperties.alpha.gradient.spread = alphaSpread; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAlphaSpread() const { + return resultWithReadLock([&] { + return _particleProperties.alpha.gradient.spread; }); } void ParticleEffectEntityItem::setLifespan(float lifespan) { lifespan = glm::clamp(lifespan, MINIMUM_LIFESPAN, MAXIMUM_LIFESPAN); - if (lifespan != _particleProperties.lifespan) { - withWriteLock([&] { - _particleProperties.lifespan = lifespan; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.lifespan != lifespan; + _particleProperties.lifespan = lifespan; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getLifespan() const { + return resultWithReadLock([&] { + return _particleProperties.lifespan; + }); +} + void ParticleEffectEntityItem::setEmitRate(float emitRate) { + emitRate = glm::clamp(emitRate, MINIMUM_EMIT_RATE, MAXIMUM_EMIT_RATE); + + bool changed; withWriteLock([&] { - _particleProperties.emission.rate = glm::clamp(emitRate, MINIMUM_EMIT_RATE, MAXIMUM_EMIT_RATE); + changed = _particleProperties.emission.rate != emitRate; + _particleProperties.emission.rate = emitRate; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getEmitRate() const { + return resultWithReadLock([&] { + return _particleProperties.emission.rate; }); } void ParticleEffectEntityItem::setEmitSpeed(float emitSpeed) { emitSpeed = glm::clamp(emitSpeed, MINIMUM_EMIT_SPEED, MAXIMUM_EMIT_SPEED); - if (emitSpeed != _particleProperties.emission.speed.target) { - withWriteLock([&] { - _particleProperties.emission.speed.target = emitSpeed; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.speed.target != emitSpeed; + _particleProperties.emission.speed.target = emitSpeed; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getEmitSpeed() const { + return resultWithReadLock([&] { + return _particleProperties.emission.speed.target; + }); +} + void ParticleEffectEntityItem::setSpeedSpread(float speedSpread) { speedSpread = glm::clamp(speedSpread, MINIMUM_EMIT_SPEED, MAXIMUM_EMIT_SPEED); - if (speedSpread != _particleProperties.emission.speed.spread) { - withWriteLock([&] { - _particleProperties.emission.speed.spread = speedSpread; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.speed.spread != speedSpread; + _particleProperties.emission.speed.spread = speedSpread; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getSpeedSpread() const { + return resultWithReadLock([&] { + return _particleProperties.emission.speed.spread; + }); +} + void ParticleEffectEntityItem::setEmitOrientation(const glm::quat& emitOrientation_) { auto emitOrientation = glm::normalize(emitOrientation_); - if (emitOrientation != _particleProperties.emission.orientation) { - withWriteLock([&] { - _particleProperties.emission.orientation = emitOrientation; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.orientation != emitOrientation; + _particleProperties.emission.orientation = emitOrientation; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +glm::quat ParticleEffectEntityItem::getEmitOrientation() const { + return resultWithReadLock([&] { + return _particleProperties.emission.orientation; + }); +} + void ParticleEffectEntityItem::setEmitDimensions(const glm::vec3& emitDimensions_) { auto emitDimensions = glm::clamp(emitDimensions_, vec3(MINIMUM_EMIT_DIMENSION), vec3(MAXIMUM_EMIT_DIMENSION)); - if (emitDimensions != _particleProperties.emission.dimensions) { - withWriteLock([&] { - _particleProperties.emission.dimensions = emitDimensions; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.dimensions != emitDimensions; + _particleProperties.emission.dimensions = emitDimensions; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +glm::vec3 ParticleEffectEntityItem::getEmitDimensions() const { + return resultWithReadLock([&] { + return _particleProperties.emission.dimensions; + }); +} + void ParticleEffectEntityItem::setEmitRadiusStart(float emitRadiusStart) { + emitRadiusStart = glm::clamp(emitRadiusStart, MINIMUM_EMIT_RADIUS_START, MAXIMUM_EMIT_RADIUS_START); + + bool changed; withWriteLock([&] { - _particleProperties.radiusStart = glm::clamp(emitRadiusStart, MINIMUM_EMIT_RADIUS_START, MAXIMUM_EMIT_RADIUS_START); + changed = _particleProperties.radiusStart != emitRadiusStart; + _particleProperties.radiusStart = emitRadiusStart; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getEmitRadiusStart() const { + return resultWithReadLock([&] { + return _particleProperties.radiusStart; }); } void ParticleEffectEntityItem::setPolarStart(float polarStart) { + polarStart = glm::clamp(polarStart, MINIMUM_POLAR, MAXIMUM_POLAR); + + bool changed; withWriteLock([&] { - _particleProperties.polar.start = glm::clamp(polarStart, MINIMUM_POLAR, MAXIMUM_POLAR); + changed = _particleProperties.polar.start != polarStart; + _particleProperties.polar.start = polarStart; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getPolarStart() const { + return resultWithReadLock([&] { + return _particleProperties.polar.start; }); } void ParticleEffectEntityItem::setPolarFinish(float polarFinish) { + polarFinish = glm::clamp(polarFinish, MINIMUM_POLAR, MAXIMUM_POLAR); + + bool changed; withWriteLock([&] { - _particleProperties.polar.finish = glm::clamp(polarFinish, MINIMUM_POLAR, MAXIMUM_POLAR); + changed = _particleProperties.polar.finish != polarFinish; + _particleProperties.polar.finish = polarFinish; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getPolarFinish() const { + return resultWithReadLock([&] { + return _particleProperties.polar.finish; }); } void ParticleEffectEntityItem::setAzimuthStart(float azimuthStart) { + azimuthStart = glm::clamp(azimuthStart, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); + + bool changed; withWriteLock([&] { - _particleProperties.azimuth.start = glm::clamp(azimuthStart, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); + changed = _particleProperties.azimuth.start != azimuthStart; + _particleProperties.azimuth.start = azimuthStart; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAzimuthStart() const { + return resultWithReadLock([&] { + return _particleProperties.azimuth.start; }); } void ParticleEffectEntityItem::setAzimuthFinish(float azimuthFinish) { + azimuthFinish = glm::clamp(azimuthFinish, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); + + bool changed; withWriteLock([&] { - _particleProperties.azimuth.finish = glm::clamp(azimuthFinish, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); + changed = _particleProperties.azimuth.finish != azimuthFinish; + _particleProperties.azimuth.finish = azimuthFinish; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getAzimuthFinish() const { + return resultWithReadLock([&] { + return _particleProperties.azimuth.finish; }); } void ParticleEffectEntityItem::setEmitAcceleration(const glm::vec3& emitAcceleration_) { auto emitAcceleration = glm::clamp(emitAcceleration_, vec3(MINIMUM_EMIT_ACCELERATION), vec3(MAXIMUM_EMIT_ACCELERATION)); - if (emitAcceleration != _particleProperties.emission.acceleration.target) { - withWriteLock([&] { - _particleProperties.emission.acceleration.target = emitAcceleration; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.acceleration.target != emitAcceleration; + _particleProperties.emission.acceleration.target = emitAcceleration; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +glm::vec3 ParticleEffectEntityItem::getEmitAcceleration() const { + return resultWithReadLock([&] { + return _particleProperties.emission.acceleration.target; + }); +} + void ParticleEffectEntityItem::setAccelerationSpread(const glm::vec3& accelerationSpread_){ auto accelerationSpread = glm::clamp(accelerationSpread_, vec3(MINIMUM_ACCELERATION_SPREAD), vec3(MAXIMUM_ACCELERATION_SPREAD)); - if (accelerationSpread != _particleProperties.emission.acceleration.spread) { - withWriteLock([&] { - _particleProperties.emission.acceleration.spread = accelerationSpread; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.emission.acceleration.spread != accelerationSpread; + _particleProperties.emission.acceleration.spread = accelerationSpread; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +glm::vec3 ParticleEffectEntityItem::getAccelerationSpread() const { + return resultWithReadLock([&] { + return _particleProperties.emission.acceleration.spread; + }); +} + void ParticleEffectEntityItem::setParticleRadius(float particleRadius) { particleRadius = glm::clamp(particleRadius, MINIMUM_PARTICLE_RADIUS, MAXIMUM_PARTICLE_RADIUS); - if (particleRadius != _particleProperties.radius.gradient.target) { - withWriteLock([&] { - _particleProperties.radius.gradient.target = particleRadius; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.radius.gradient.target != particleRadius; + _particleProperties.radius.gradient.target = particleRadius; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getParticleRadius() const { + return resultWithReadLock([&] { + return _particleProperties.radius.gradient.target; + }); +} + void ParticleEffectEntityItem::setRadiusStart(float radiusStart) { radiusStart = glm::isnan(radiusStart) ? radiusStart : glm::clamp(radiusStart, MINIMUM_PARTICLE_RADIUS, MAXIMUM_PARTICLE_RADIUS); - if (radiusStart != _particleProperties.radius.range.start) { - withWriteLock([&] { - _particleProperties.radius.range.start = radiusStart; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.radius.range.start != radiusStart; + _particleProperties.radius.range.start = radiusStart; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getRadiusStart() const { + return resultWithReadLock([&] { + return _particleProperties.radius.range.start; + }); +} + void ParticleEffectEntityItem::setRadiusFinish(float radiusFinish) { radiusFinish = glm::isnan(radiusFinish) ? radiusFinish : glm::clamp(radiusFinish, MINIMUM_PARTICLE_RADIUS, MAXIMUM_PARTICLE_RADIUS); - if (radiusFinish != _particleProperties.radius.range.finish) { - withWriteLock([&] { - _particleProperties.radius.range.finish = radiusFinish; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.radius.range.finish != radiusFinish; + _particleProperties.radius.range.finish = radiusFinish; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getRadiusFinish() const { + return resultWithReadLock([&] { + return _particleProperties.radius.range.finish; + }); +} + void ParticleEffectEntityItem::setRadiusSpread(float radiusSpread) { radiusSpread = glm::clamp(radiusSpread, MINIMUM_PARTICLE_RADIUS, MAXIMUM_PARTICLE_RADIUS); - if (radiusSpread != _particleProperties.radius.gradient.spread) { - withWriteLock([&] { - _particleProperties.radius.gradient.spread = radiusSpread; - }); + + bool changed; + withWriteLock([&] { + changed = _particleProperties.radius.gradient.spread != radiusSpread; + _particleProperties.radius.gradient.spread = radiusSpread; + }); + + _needsRenderUpdate |= changed; + + if (changed) { computeAndUpdateDimensions(); } } +float ParticleEffectEntityItem::getRadiusSpread() const { + return resultWithReadLock([&] { + return _particleProperties.radius.gradient.spread; + }); +} + void ParticleEffectEntityItem::setParticleSpin(float particleSpin) { particleSpin = glm::clamp(particleSpin, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - if (particleSpin != _particleProperties.spin.gradient.target) { - withWriteLock([&] { - _particleProperties.spin.gradient.target = particleSpin; - }); - } + + bool changed; + withWriteLock([&] { + changed = _particleProperties.spin.gradient.target != particleSpin; + _particleProperties.spin.gradient.target = particleSpin; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getParticleSpin() const { + return resultWithReadLock([&] { + return _particleProperties.spin.gradient.target; + }); } void ParticleEffectEntityItem::setSpinStart(float spinStart) { spinStart = glm::isnan(spinStart) ? spinStart : glm::clamp(spinStart, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - if (spinStart != _particleProperties.spin.range.start) { - withWriteLock([&] { - _particleProperties.spin.range.start = spinStart; - }); - } + + bool changed; + withWriteLock([&] { + changed = _particleProperties.spin.range.start != spinStart; + _particleProperties.spin.range.start = spinStart; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getSpinStart() const { + return resultWithReadLock([&] { + return _particleProperties.spin.range.start; + }); } void ParticleEffectEntityItem::setSpinFinish(float spinFinish) { spinFinish = glm::isnan(spinFinish) ? spinFinish : glm::clamp(spinFinish, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - if (spinFinish != _particleProperties.spin.range.finish) { - withWriteLock([&] { - _particleProperties.spin.range.finish = spinFinish; - }); - } + + bool changed; + withWriteLock([&] { + changed = _particleProperties.spin.range.finish != spinFinish; + _particleProperties.spin.range.finish = spinFinish; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getSpinFinish() const { + return resultWithReadLock([&] { + return _particleProperties.spin.range.finish; + }); } void ParticleEffectEntityItem::setSpinSpread(float spinSpread) { spinSpread = glm::clamp(spinSpread, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - if (spinSpread != _particleProperties.spin.gradient.spread) { - withWriteLock([&] { - _particleProperties.spin.gradient.spread = spinSpread; - }); - } + + bool changed; + withWriteLock([&] { + changed = _particleProperties.spin.gradient.spread != spinSpread; + _particleProperties.spin.gradient.spread = spinSpread; + }); + + _needsRenderUpdate |= changed; +} + +float ParticleEffectEntityItem::getSpinSpread() const { + return resultWithReadLock([&] { + return _particleProperties.spin.gradient.spread; + }); } void ParticleEffectEntityItem::computeAndUpdateDimensions() { @@ -471,6 +759,7 @@ bool ParticleEffectEntityItem::setProperties(const EntityItemProperties& propert withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(textures, setTextures); @@ -528,9 +817,19 @@ bool ParticleEffectEntityItem::setProperties(const EntityItemProperties& propert } void ParticleEffectEntityItem::setColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _particleProperties.color.gradient.target != glm::vec3(value); _particleProperties.color.gradient.target = value; }); + + _needsRenderUpdate |= changed; +} + +glm::u8vec3 ParticleEffectEntityItem::getColor() const { + return resultWithReadLock([&] { + return _particleProperties.color.gradient.target; + }); } int ParticleEffectEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead, @@ -739,9 +1038,13 @@ void ParticleEffectEntityItem::setShapeType(ShapeType type) { break; } + bool changed; withWriteLock([&] { + changed = _shapeType != type; _shapeType = type; }); + + _needsRenderUpdate |= changed; } ShapeType ParticleEffectEntityItem::getShapeType() const { @@ -751,9 +1054,13 @@ ShapeType ParticleEffectEntityItem::getShapeType() const { } void ParticleEffectEntityItem::setCompoundShapeURL(const QString& compoundShapeURL) { + bool changed; withWriteLock([&] { + changed = _compoundShapeURL != compoundShapeURL; _compoundShapeURL = compoundShapeURL; }); + + _needsRenderUpdate |= changed; } QString ParticleEffectEntityItem::getCompoundShapeURL() const { @@ -762,44 +1069,103 @@ QString ParticleEffectEntityItem::getCompoundShapeURL() const { }); } +void ParticleEffectEntityItem::setIsEmitting(bool isEmitting) { + _needsRenderUpdate |= _isEmitting != isEmitting; + _isEmitting = isEmitting; +} + void ParticleEffectEntityItem::setMaxParticles(quint32 maxParticles) { + maxParticles = glm::clamp(maxParticles, MINIMUM_MAX_PARTICLES, MAXIMUM_MAX_PARTICLES); + + bool changed; withWriteLock([&] { - _particleProperties.maxParticles = glm::clamp(maxParticles, MINIMUM_MAX_PARTICLES, MAXIMUM_MAX_PARTICLES); + changed = _particleProperties.maxParticles != maxParticles; + _particleProperties.maxParticles = maxParticles; + }); + + _needsRenderUpdate |= changed; +} + +quint32 ParticleEffectEntityItem::getMaxParticles() const { + return resultWithReadLock([&] { + return _particleProperties.maxParticles; }); } void ParticleEffectEntityItem::setTextures(const QString& textures) { + bool changed; withWriteLock([&] { + changed = _particleProperties.textures != textures; _particleProperties.textures = textures; }); + + _needsRenderUpdate |= changed; +} + +QString ParticleEffectEntityItem::getTextures() const { + return resultWithReadLock([&] { + return _particleProperties.textures; + }); } void ParticleEffectEntityItem::setColorStart(const vec3& colorStart) { + bool changed; withWriteLock([&] { + changed = _particleProperties.color.range.start != colorStart; _particleProperties.color.range.start = colorStart; }); + + _needsRenderUpdate |= changed; +} + +glm::vec3 ParticleEffectEntityItem::getColorStart() const { + return resultWithReadLock([&] { + return _particleProperties.color.range.start; + }); } void ParticleEffectEntityItem::setColorFinish(const vec3& colorFinish) { + bool changed; withWriteLock([&] { + changed = _particleProperties.color.range.finish != colorFinish; _particleProperties.color.range.finish = colorFinish; }); + + _needsRenderUpdate |= changed; +} + +glm::vec3 ParticleEffectEntityItem::getColorFinish() const { + return resultWithReadLock([&] { + return _particleProperties.color.range.finish; + }); } void ParticleEffectEntityItem::setColorSpread(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _particleProperties.color.gradient.spread != glm::vec3(value); _particleProperties.color.gradient.spread = value; }); + + _needsRenderUpdate |= changed; +} + +glm::u8vec3 ParticleEffectEntityItem::getColorSpread() const { + return resultWithReadLock([&] { + return _particleProperties.color.gradient.spread; + }); } void ParticleEffectEntityItem::setEmitterShouldTrail(bool emitterShouldTrail) { withWriteLock([&] { + _needsRenderUpdate |= _particleProperties.emission.shouldTrail != emitterShouldTrail; _particleProperties.emission.shouldTrail = emitterShouldTrail; }); } void ParticleEffectEntityItem::setRotateWithEntity(bool rotateWithEntity) { withWriteLock([&] { + _needsRenderUpdate |= _particleProperties.rotateWithEntity != rotateWithEntity; _particleProperties.rotateWithEntity = rotateWithEntity; }); } @@ -808,34 +1174,34 @@ particle::Properties ParticleEffectEntityItem::getParticleProperties() const { particle::Properties result; withReadLock([&] { result = _particleProperties; - - // Special case the properties that get treated differently if they're unintialized - if (glm::any(glm::isnan(result.color.range.start))) { - result.color.range.start = getColor(); - } - if (glm::any(glm::isnan(result.color.range.finish))) { - result.color.range.finish = getColor(); - } - if (glm::isnan(result.alpha.range.start)) { - result.alpha.range.start = getAlpha(); - } - if (glm::isnan(result.alpha.range.finish)) { - result.alpha.range.finish = getAlpha(); - } - if (glm::isnan(result.radius.range.start)) { - result.radius.range.start = getParticleRadius(); - } - if (glm::isnan(result.radius.range.finish)) { - result.radius.range.finish = getParticleRadius(); - } - if (glm::isnan(result.spin.range.start)) { - result.spin.range.start = getParticleSpin(); - } - if (glm::isnan(result.spin.range.finish)) { - result.spin.range.finish = getParticleSpin(); - } }); + // Special case the properties that get treated differently if they're unintialized + if (glm::any(glm::isnan(result.color.range.start))) { + result.color.range.start = getColor(); + } + if (glm::any(glm::isnan(result.color.range.finish))) { + result.color.range.finish = getColor(); + } + if (glm::isnan(result.alpha.range.start)) { + result.alpha.range.start = getAlpha(); + } + if (glm::isnan(result.alpha.range.finish)) { + result.alpha.range.finish = getAlpha(); + } + if (glm::isnan(result.radius.range.start)) { + result.radius.range.start = getParticleRadius(); + } + if (glm::isnan(result.radius.range.finish)) { + result.radius.range.finish = getParticleRadius(); + } + if (glm::isnan(result.spin.range.start)) { + result.spin.range.start = getParticleSpin(); + } + if (glm::isnan(result.spin.range.finish)) { + result.spin.range.finish = getParticleSpin(); + } + if (!result.valid()) { qCWarning(entities) << "failed validation"; } diff --git a/libraries/entities/src/ParticleEffectEntityItem.h b/libraries/entities/src/ParticleEffectEntityItem.h index b526298a4b..358e5a6b6d 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.h +++ b/libraries/entities/src/ParticleEffectEntityItem.h @@ -233,29 +233,31 @@ public: bool shouldBePhysical() const override { return false; } + virtual void debugDump() const override; + void setColor(const glm::u8vec3& value); - glm::u8vec3 getColor() const { return _particleProperties.color.gradient.target; } + glm::u8vec3 getColor() const; void setColorStart(const vec3& colorStart); - vec3 getColorStart() const { return _particleProperties.color.range.start; } + vec3 getColorStart() const; void setColorFinish(const vec3& colorFinish); - vec3 getColorFinish() const { return _particleProperties.color.range.finish; } + vec3 getColorFinish() const; void setColorSpread(const glm::u8vec3& colorSpread); - glm::u8vec3 getColorSpread() const { return _particleProperties.color.gradient.spread; } + glm::u8vec3 getColorSpread() const; void setAlpha(float alpha); - float getAlpha() const { return _particleProperties.alpha.gradient.target; } + float getAlpha() const; void setAlphaStart(float alphaStart); - float getAlphaStart() const { return _particleProperties.alpha.range.start; } + float getAlphaStart() const; void setAlphaFinish(float alphaFinish); - float getAlphaFinish() const { return _particleProperties.alpha.range.finish; } + float getAlphaFinish() const; void setAlphaSpread(float alphaSpread); - float getAlphaSpread() const { return _particleProperties.alpha.gradient.spread; } + float getAlphaSpread() const; void setShapeType(ShapeType type) override; virtual ShapeType getShapeType() const override; @@ -263,76 +265,74 @@ public: QString getCompoundShapeURL() const; virtual void setCompoundShapeURL(const QString& url); - virtual void debugDump() const override; - bool getIsEmitting() const { return _isEmitting; } - void setIsEmitting(bool isEmitting) { _isEmitting = isEmitting; } + void setIsEmitting(bool isEmitting); void setMaxParticles(quint32 maxParticles); - quint32 getMaxParticles() const { return _particleProperties.maxParticles; } + quint32 getMaxParticles() const; void setLifespan(float lifespan); - float getLifespan() const { return _particleProperties.lifespan; } + float getLifespan() const; void setEmitRate(float emitRate); - float getEmitRate() const { return _particleProperties.emission.rate; } + float getEmitRate() const; void setEmitSpeed(float emitSpeed); - float getEmitSpeed() const { return _particleProperties.emission.speed.target; } + float getEmitSpeed() const; void setSpeedSpread(float speedSpread); - float getSpeedSpread() const { return _particleProperties.emission.speed.spread; } + float getSpeedSpread() const; void setEmitOrientation(const glm::quat& emitOrientation); - const glm::quat& getEmitOrientation() const { return _particleProperties.emission.orientation; } + glm::quat getEmitOrientation() const; void setEmitDimensions(const glm::vec3& emitDimensions); - const glm::vec3& getEmitDimensions() const { return _particleProperties.emission.dimensions; } + glm::vec3 getEmitDimensions() const; void setEmitRadiusStart(float emitRadiusStart); - float getEmitRadiusStart() const { return _particleProperties.radiusStart; } + float getEmitRadiusStart() const; void setPolarStart(float polarStart); - float getPolarStart() const { return _particleProperties.polar.start; } + float getPolarStart() const; void setPolarFinish(float polarFinish); - float getPolarFinish() const { return _particleProperties.polar.finish; } + float getPolarFinish() const; void setAzimuthStart(float azimuthStart); - float getAzimuthStart() const { return _particleProperties.azimuth.start; } + float getAzimuthStart() const; void setAzimuthFinish(float azimuthFinish); - float getAzimuthFinish() const { return _particleProperties.azimuth.finish; } + float getAzimuthFinish() const; void setEmitAcceleration(const glm::vec3& emitAcceleration); - const glm::vec3& getEmitAcceleration() const { return _particleProperties.emission.acceleration.target; } + glm::vec3 getEmitAcceleration() const; void setAccelerationSpread(const glm::vec3& accelerationSpread); - const glm::vec3& getAccelerationSpread() const { return _particleProperties.emission.acceleration.spread; } + glm::vec3 getAccelerationSpread() const; void setParticleRadius(float particleRadius); - float getParticleRadius() const { return _particleProperties.radius.gradient.target; } + float getParticleRadius() const; void setRadiusStart(float radiusStart); - float getRadiusStart() const { return _particleProperties.radius.range.start; } + float getRadiusStart() const; void setRadiusFinish(float radiusFinish); - float getRadiusFinish() const { return _particleProperties.radius.range.finish; } + float getRadiusFinish() const; void setRadiusSpread(float radiusSpread); - float getRadiusSpread() const { return _particleProperties.radius.gradient.spread; } + float getRadiusSpread() const; void setParticleSpin(float particleSpin); - float getParticleSpin() const { return _particleProperties.spin.gradient.target; } + float getParticleSpin() const; void setSpinStart(float spinStart); - float getSpinStart() const { return _particleProperties.spin.range.start; } + float getSpinStart() const; void setSpinFinish(float spinFinish); - float getSpinFinish() const { return _particleProperties.spin.range.finish; } + float getSpinFinish() const; void setSpinSpread(float spinSpread); - float getSpinSpread() const { return _particleProperties.spin.gradient.spread; } + float getSpinSpread() const; void setRotateWithEntity(bool rotateWithEntity); bool getRotateWithEntity() const { return _particleProperties.rotateWithEntity; } @@ -340,10 +340,10 @@ public: void computeAndUpdateDimensions(); void setTextures(const QString& textures); - QString getTextures() const { return _particleProperties.textures; } + QString getTextures() const; - bool getEmitterShouldTrail() const { return _particleProperties.emission.shouldTrail; } void setEmitterShouldTrail(bool emitterShouldTrail); + bool getEmitterShouldTrail() const { return _particleProperties.emission.shouldTrail; } virtual bool supportsDetailedIntersection() const override { return false; } diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 6ab885b32b..3c53281690 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -247,3 +247,18 @@ glm::u8vec3 PolyLineEntityItem::getColor() const { return _color; }); } + +void PolyLineEntityItem::setIsUVModeStretch(bool isUVModeStretch) { + _needsRenderUpdate = _isUVModeStretch != isUVModeStretch; + _isUVModeStretch = isUVModeStretch; +} + +void PolyLineEntityItem::setGlow(bool glow) { + _needsRenderUpdate = _glow != glow; + _glow = glow; +} + +void PolyLineEntityItem::setFaceCamera(bool faceCamera) { + _needsRenderUpdate = _faceCamera != faceCamera; + _faceCamera = faceCamera; +} \ No newline at end of file diff --git a/libraries/entities/src/PolyLineEntityItem.h b/libraries/entities/src/PolyLineEntityItem.h index 41acc6d6d8..fc3b085cf1 100644 --- a/libraries/entities/src/PolyLineEntityItem.h +++ b/libraries/entities/src/PolyLineEntityItem.h @@ -58,16 +58,16 @@ class PolyLineEntityItem : public EntityItem { void setStrokeColors(const QVector& strokeColors); QVector getStrokeColors() const; - void setIsUVModeStretch(bool isUVModeStretch){ _isUVModeStretch = isUVModeStretch; } + void setIsUVModeStretch(bool isUVModeStretch); bool getIsUVModeStretch() const{ return _isUVModeStretch; } QString getTextures() const; void setTextures(const QString& textures); - void setGlow(bool glow) { _glow = glow; } + void setGlow(bool glow); bool getGlow() const { return _glow; } - void setFaceCamera(bool faceCamera) { _faceCamera = faceCamera; } + void setFaceCamera(bool faceCamera); bool getFaceCamera() const { return _faceCamera; } bool pointsChanged() const { return _pointsChanged; } diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index e65742b36c..8d8ed87ebb 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -70,38 +70,16 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID) : EntityI _type = EntityTypes::PolyVox; } -void PolyVoxEntityItem::setVoxelVolumeSize(const glm::vec3& voxelVolumeSize) { +void PolyVoxEntityItem::setVoxelVolumeSize(const glm::vec3& voxelVolumeSize_) { + auto voxelVolumeSize = glm::clamp(glm::round(voxelVolumeSize_), glm::vec3(1.0f), glm::vec3(MAX_VOXEL_DIMENSION)); + + bool changed; withWriteLock([&] { - assert(!glm::any(glm::isnan(voxelVolumeSize))); - - _voxelVolumeSize = glm::vec3(roundf(voxelVolumeSize.x), roundf(voxelVolumeSize.y), roundf(voxelVolumeSize.z)); - if (_voxelVolumeSize.x < 1) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to 1"; - _voxelVolumeSize.x = 1; - } - if (_voxelVolumeSize.x > MAX_VOXEL_DIMENSION) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping x of" << _voxelVolumeSize.x << "to max"; - _voxelVolumeSize.x = MAX_VOXEL_DIMENSION; - } - - if (_voxelVolumeSize.y < 1) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to 1"; - _voxelVolumeSize.y = 1; - } - if (_voxelVolumeSize.y > MAX_VOXEL_DIMENSION) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping y of" << _voxelVolumeSize.y << "to max"; - _voxelVolumeSize.y = MAX_VOXEL_DIMENSION; - } - - if (_voxelVolumeSize.z < 1) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to 1"; - _voxelVolumeSize.z = 1; - } - if (_voxelVolumeSize.z > MAX_VOXEL_DIMENSION) { - qCDebug(entities) << "PolyVoxEntityItem::setVoxelVolumeSize clamping z of" << _voxelVolumeSize.z << "to max"; - _voxelVolumeSize.z = MAX_VOXEL_DIMENSION; - } + changed = _voxelVolumeSize != voxelVolumeSize; + _voxelVolumeSize = voxelVolumeSize; }); + + _needsRenderUpdate |= changed; } glm::vec3 PolyVoxEntityItem::getVoxelVolumeSize() const { @@ -247,13 +225,17 @@ QByteArray PolyVoxEntityItem::getVoxelData() const { } -void PolyVoxEntityItem::setXTextureURL(const QString& xTextureURL) { +void PolyVoxEntityItem::setXTextureURL(const QString& xTextureURL) { + bool changed; withWriteLock([&] { + changed = _xTextureURL != xTextureURL; _xTextureURL = xTextureURL; }); + + _needsRenderUpdate |= changed; } -QString PolyVoxEntityItem::getXTextureURL() const { +QString PolyVoxEntityItem::getXTextureURL() const { QString result; withReadLock([&] { result = _xTextureURL; @@ -262,12 +244,16 @@ QString PolyVoxEntityItem::getXTextureURL() const { } void PolyVoxEntityItem::setYTextureURL(const QString& yTextureURL) { + bool changed; withWriteLock([&] { + changed = _yTextureURL != yTextureURL; _yTextureURL = yTextureURL; }); + + _needsRenderUpdate |= changed; } -QString PolyVoxEntityItem::getYTextureURL() const { +QString PolyVoxEntityItem::getYTextureURL() const { QString result; withReadLock([&] { result = _yTextureURL; @@ -276,11 +262,15 @@ QString PolyVoxEntityItem::getYTextureURL() const { } void PolyVoxEntityItem::setZTextureURL(const QString& zTextureURL) { + bool changed; withWriteLock([&] { + changed = _zTextureURL != zTextureURL; _zTextureURL = zTextureURL; }); + + _needsRenderUpdate |= changed; } -QString PolyVoxEntityItem::getZTextureURL() const { +QString PolyVoxEntityItem::getZTextureURL() const { QString result; withReadLock([&] { result = _zTextureURL; @@ -288,13 +278,13 @@ QString PolyVoxEntityItem::getZTextureURL() const { return result; } -void PolyVoxEntityItem::setXNNeighborID(const EntityItemID& xNNeighborID) { +void PolyVoxEntityItem::setXNNeighborID(const EntityItemID& xNNeighborID) { withWriteLock([&] { _xNNeighborID = xNNeighborID; }); } -EntityItemID PolyVoxEntityItem::getXNNeighborID() const { +EntityItemID PolyVoxEntityItem::getXNNeighborID() const { EntityItemID result; withReadLock([&] { result = _xNNeighborID; @@ -302,13 +292,13 @@ EntityItemID PolyVoxEntityItem::getXNNeighborID() const { return result; } -void PolyVoxEntityItem::setYNNeighborID(const EntityItemID& yNNeighborID) { +void PolyVoxEntityItem::setYNNeighborID(const EntityItemID& yNNeighborID) { withWriteLock([&] { _yNNeighborID = yNNeighborID; }); } -EntityItemID PolyVoxEntityItem::getYNNeighborID() const { +EntityItemID PolyVoxEntityItem::getYNNeighborID() const { EntityItemID result; withReadLock([&] { result = _yNNeighborID; @@ -316,13 +306,13 @@ EntityItemID PolyVoxEntityItem::getYNNeighborID() const { return result; } -void PolyVoxEntityItem::setZNNeighborID(const EntityItemID& zNNeighborID) { +void PolyVoxEntityItem::setZNNeighborID(const EntityItemID& zNNeighborID) { withWriteLock([&] { _zNNeighborID = zNNeighborID; }); } -EntityItemID PolyVoxEntityItem::getZNNeighborID() const { +EntityItemID PolyVoxEntityItem::getZNNeighborID() const { EntityItemID result; withReadLock([&] { result = _zNNeighborID; @@ -330,13 +320,13 @@ EntityItemID PolyVoxEntityItem::getZNNeighborID() const { return result; } -void PolyVoxEntityItem::setXPNeighborID(const EntityItemID& xPNeighborID) { +void PolyVoxEntityItem::setXPNeighborID(const EntityItemID& xPNeighborID) { withWriteLock([&] { _xPNeighborID = xPNeighborID; }); } -EntityItemID PolyVoxEntityItem::getXPNeighborID() const { +EntityItemID PolyVoxEntityItem::getXPNeighborID() const { EntityItemID result; withReadLock([&] { result = _xPNeighborID; @@ -344,13 +334,13 @@ EntityItemID PolyVoxEntityItem::getXPNeighborID() const { return result; } -void PolyVoxEntityItem::setYPNeighborID(const EntityItemID& yPNeighborID) { +void PolyVoxEntityItem::setYPNeighborID(const EntityItemID& yPNeighborID) { withWriteLock([&] { _yPNeighborID = yPNeighborID; }); } -EntityItemID PolyVoxEntityItem::getYPNeighborID() const { +EntityItemID PolyVoxEntityItem::getYPNeighborID() const { EntityItemID result; withReadLock([&] { result = _yPNeighborID; @@ -358,13 +348,13 @@ EntityItemID PolyVoxEntityItem::getYPNeighborID() const { return result; } -void PolyVoxEntityItem::setZPNeighborID(const EntityItemID& zPNeighborID) { +void PolyVoxEntityItem::setZPNeighborID(const EntityItemID& zPNeighborID) { withWriteLock([&] { _zPNeighborID = zPNeighborID; }); } -EntityItemID PolyVoxEntityItem::getZPNeighborID() const { +EntityItemID PolyVoxEntityItem::getZPNeighborID() const { EntityItemID result; withReadLock([&] { result = _zPNeighborID; diff --git a/libraries/entities/src/ShapeEntityItem.cpp b/libraries/entities/src/ShapeEntityItem.cpp index ae4d17fa66..47a78fb1d6 100644 --- a/libraries/entities/src/ShapeEntityItem.cpp +++ b/libraries/entities/src/ShapeEntityItem.cpp @@ -154,6 +154,7 @@ void ShapeEntityItem::setShape(const entity::Shape& shape) { if (_shape != prevShape) { // Internally grabs writeLock markDirtyFlags(Simulation::DIRTY_SHAPE); + _needsRenderUpdate = true; } } @@ -165,6 +166,7 @@ bool ShapeEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(shape, setShape); @@ -231,9 +233,13 @@ void ShapeEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit } void ShapeEntityItem::setColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _color != value; _color = value; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 ShapeEntityItem::getColor() const { @@ -243,9 +249,13 @@ glm::u8vec3 ShapeEntityItem::getColor() const { } void ShapeEntityItem::setAlpha(float alpha) { + bool changed; withWriteLock([&] { + changed = _alpha != alpha; _alpha = alpha; }); + + _needsRenderUpdate |= changed; } float ShapeEntityItem::getAlpha() const { diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp index 08200084f4..a5dc93a573 100644 --- a/libraries/entities/src/TextEntityItem.cpp +++ b/libraries/entities/src/TextEntityItem.cpp @@ -75,6 +75,7 @@ bool TextEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(billboardMode, setBillboardMode); @@ -163,7 +164,7 @@ void TextEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits EntityPropertyFlags& propertyFlags, EntityPropertyFlags& propertiesDidntFit, int& propertyCount, - OctreeElement::AppendState& appendState) const { + OctreeElement::AppendState& appendState) const { bool successPropertyFits = true; @@ -250,12 +251,16 @@ bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, c } void TextEntityItem::setText(const QString& value) { + bool changed; withWriteLock([&] { + changed = _text != value; _text = value; }); + + _needsRenderUpdate |= changed; } -QString TextEntityItem::getText() const { +QString TextEntityItem::getText() const { QString result; withReadLock([&] { result = _text; @@ -263,13 +268,17 @@ QString TextEntityItem::getText() const { return result; } -void TextEntityItem::setLineHeight(float value) { +void TextEntityItem::setLineHeight(float value) { + bool changed; withWriteLock([&] { + changed = _lineHeight != value; _lineHeight = value; }); + + _needsRenderUpdate |= changed; } -float TextEntityItem::getLineHeight() const { +float TextEntityItem::getLineHeight() const { float result; withReadLock([&] { result = _lineHeight; @@ -278,9 +287,13 @@ float TextEntityItem::getLineHeight() const { } void TextEntityItem::setTextColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _textColor != value; _textColor = value; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 TextEntityItem::getTextColor() const { @@ -290,9 +303,13 @@ glm::u8vec3 TextEntityItem::getTextColor() const { } void TextEntityItem::setTextAlpha(float value) { + bool changed; withWriteLock([&] { + changed = _textAlpha != value; _textAlpha = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getTextAlpha() const { @@ -302,9 +319,13 @@ float TextEntityItem::getTextAlpha() const { } void TextEntityItem::setBackgroundColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _backgroundColor != value; _backgroundColor = value; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 TextEntityItem::getBackgroundColor() const { @@ -314,9 +335,13 @@ glm::u8vec3 TextEntityItem::getBackgroundColor() const { } void TextEntityItem::setBackgroundAlpha(float value) { + bool changed; withWriteLock([&] { + changed = _backgroundAlpha != value; _backgroundAlpha = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getBackgroundAlpha() const { @@ -334,15 +359,23 @@ BillboardMode TextEntityItem::getBillboardMode() const { } void TextEntityItem::setBillboardMode(BillboardMode value) { + bool changed; withWriteLock([&] { + changed = _billboardMode != value; _billboardMode = value; }); + + _needsRenderUpdate |= changed; } void TextEntityItem::setLeftMargin(float value) { + bool changed; withWriteLock([&] { + changed = _leftMargin != value; _leftMargin = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getLeftMargin() const { @@ -352,9 +385,13 @@ float TextEntityItem::getLeftMargin() const { } void TextEntityItem::setRightMargin(float value) { + bool changed; withWriteLock([&] { + changed = _rightMargin != value; _rightMargin = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getRightMargin() const { @@ -364,9 +401,13 @@ float TextEntityItem::getRightMargin() const { } void TextEntityItem::setTopMargin(float value) { + bool changed; withWriteLock([&] { + changed = _topMargin != value; _topMargin = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getTopMargin() const { @@ -376,9 +417,13 @@ float TextEntityItem::getTopMargin() const { } void TextEntityItem::setBottomMargin(float value) { + bool changed; withWriteLock([&] { + changed = _bottomMargin != value; _bottomMargin = value; }); + + _needsRenderUpdate |= changed; } float TextEntityItem::getBottomMargin() const { @@ -388,9 +433,13 @@ float TextEntityItem::getBottomMargin() const { } void TextEntityItem::setUnlit(bool value) { + bool changed; withWriteLock([&] { + changed = _unlit != value; _unlit = value; }); + + _needsRenderUpdate |= changed; } bool TextEntityItem::getUnlit() const { diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index b40de7e42a..8bdaa8bd31 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -68,6 +68,7 @@ bool WebEntityItem::setProperties(const EntityItemProperties& properties) { withWriteLock([&] { bool pulsePropertiesChanged = _pulseProperties.setProperties(properties); somethingChanged |= pulsePropertiesChanged; + _needsRenderUpdate |= pulsePropertiesChanged; }); SET_ENTITY_PROPERTY_FROM_PROPERTIES(billboardMode, setBillboardMode); @@ -228,9 +229,13 @@ bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, co } void WebEntityItem::setColor(const glm::u8vec3& value) { + bool changed; withWriteLock([&] { + changed = _color != value; _color = value; }); + + _needsRenderUpdate |= changed; } glm::u8vec3 WebEntityItem::getColor() const { @@ -240,9 +245,13 @@ glm::u8vec3 WebEntityItem::getColor() const { } void WebEntityItem::setAlpha(float alpha) { + bool changed; withWriteLock([&] { + changed = _alpha != alpha; _alpha = alpha; }); + + _needsRenderUpdate |= changed; } float WebEntityItem::getAlpha() const { @@ -258,15 +267,23 @@ BillboardMode WebEntityItem::getBillboardMode() const { } void WebEntityItem::setBillboardMode(BillboardMode value) { + bool changed; withWriteLock([&] { + changed = _billboardMode != value; _billboardMode = value; }); + + _needsRenderUpdate |= changed; } void WebEntityItem::setSourceUrl(const QString& value) { + bool changed; withWriteLock([&] { + changed = _sourceUrl != value; _sourceUrl = value; }); + + _needsRenderUpdate |= changed; } QString WebEntityItem::getSourceUrl() const { @@ -276,9 +293,13 @@ QString WebEntityItem::getSourceUrl() const { } void WebEntityItem::setDPI(uint16_t value) { + bool changed; withWriteLock([&] { + changed = _dpi != value; _dpi = value; }); + + _needsRenderUpdate |= changed; } uint16_t WebEntityItem::getDPI() const { @@ -288,17 +309,22 @@ uint16_t WebEntityItem::getDPI() const { } void WebEntityItem::setScriptURL(const QString& value) { - withWriteLock([&] { - if (_scriptURL != value) { - auto newURL = QUrl::fromUserInput(value); + auto newURL = QUrl::fromUserInput(value); - if (newURL.isValid()) { - _scriptURL = newURL.toDisplayString(); - } else { + if (!newURL.isValid()) { qCDebug(entities) << "Not setting web entity script URL since" << value << "cannot be parsed to a valid URL."; - } - } + return; + } + + auto urlString = newURL.toDisplayString(); + + bool changed; + withWriteLock([&] { + changed = _scriptURL != urlString; + _scriptURL = urlString; }); + + _needsRenderUpdate |= changed; } QString WebEntityItem::getScriptURL() const { @@ -308,9 +334,13 @@ QString WebEntityItem::getScriptURL() const { } void WebEntityItem::setMaxFPS(uint8_t value) { + bool changed; withWriteLock([&] { + changed = _maxFPS != value; _maxFPS = value; }); + + _needsRenderUpdate |= changed; } uint8_t WebEntityItem::getMaxFPS() const { @@ -320,9 +350,13 @@ uint8_t WebEntityItem::getMaxFPS() const { } void WebEntityItem::setInputMode(const WebInputMode& value) { + bool changed; withWriteLock([&] { + changed = _inputMode != value; _inputMode = value; }); + + _needsRenderUpdate |= changed; } WebInputMode WebEntityItem::getInputMode() const { From 6e2ffe14a00aad0821df080423e22ea1d439318b Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 31 Jul 2019 11:44:42 -0700 Subject: [PATCH 03/21] better ui --- .../utilities/lib/jet/qml/TaskPropView.qml | 5 ++-- .../utilities/render/engineInspector.qml | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml index ea5af4896f..04a18f8e2a 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml @@ -12,9 +12,6 @@ import QtQuick 2.7 import QtQuick.Controls 1.4 as Original import QtQuick.Controls.Styles 1.4 -import stylesUit 1.0 -import controlsUit 1.0 as HifiControls - import "../../prop" as Prop import "../jet.js" as Jet @@ -23,6 +20,8 @@ Prop.PropGroup { id: root; + Prop.Global { id: global;} + property var rootConfig : Render property var jobPath: "" property alias label: root.label diff --git a/scripts/developer/utilities/render/engineInspector.qml b/scripts/developer/utilities/render/engineInspector.qml index fabbbe449b..a4b23ad33e 100644 --- a/scripts/developer/utilities/render/engineInspector.qml +++ b/scripts/developer/utilities/render/engineInspector.qml @@ -8,23 +8,32 @@ // See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html // import QtQuick 2.7 -import QtQuick.Controls 1.4 +import QtQuick.Controls 2.5 import QtQuick.Layouts 1.3 -import stylesUit 1.0 -import controlsUit 1.0 as HifiControls import "../lib/jet/qml" as Jet Item { - HifiConstants { id: hifi;} + anchors.fill: parent id: root; - anchors.fill: parent - + property var rootConfig: Render.getConfig("") - Jet.TaskPropView { - rootConfig: root.rootConfig - anchors.fill: root + ScrollView { + id: scrollView + anchors.fill: parent + contentWidth: parent.width + clip: true + + Column { + anchors.left: parent.left + anchors.right: parent.right + + Jet.TaskPropView { + rootConfig: root.rootConfig + anchors.fill: root + } + } } } \ No newline at end of file From 62bb4e1d463f77438311a750c0f62dc0529d589c Mon Sep 17 00:00:00 2001 From: HifiExperiments Date: Wed, 31 Jul 2019 21:02:21 -0700 Subject: [PATCH 04/21] simplify render update check, threadsafety --- libraries/entities/src/EntityItem.cpp | 27 +--- libraries/entities/src/EntityItem.h | 4 +- libraries/entities/src/GizmoEntityItem.cpp | 5 +- libraries/entities/src/GridEntityItem.cpp | 25 +-- libraries/entities/src/ImageEntityItem.cpp | 35 +--- libraries/entities/src/LightEntityItem.cpp | 34 ++-- libraries/entities/src/LineEntityItem.cpp | 11 +- libraries/entities/src/MaterialEntityItem.cpp | 49 ++---- libraries/entities/src/ModelEntityItem.cpp | 10 +- .../entities/src/ParticleEffectEntityItem.cpp | 149 +++++------------- libraries/entities/src/PolyLineEntityItem.cpp | 18 ++- libraries/entities/src/PolyVoxEntityItem.cpp | 20 +-- libraries/entities/src/ShapeEntityItem.cpp | 27 ++-- libraries/entities/src/ShapeEntityItem.h | 2 +- libraries/entities/src/TextEntityItem.cpp | 60 ++----- libraries/entities/src/WebEntityItem.cpp | 40 +---- 16 files changed, 141 insertions(+), 375 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index fc45572aea..747d1e9a77 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -2946,10 +2946,10 @@ void EntityItem::setVisible(bool value) { bool changed; withWriteLock([&] { changed = _visible != value; + _needsRenderUpdate |= changed; _visible = value; }); - _needsRenderUpdate |= changed; if (changed) { bumpAncestorChainRenderableVersion(); } @@ -2964,13 +2964,10 @@ bool EntityItem::isVisibleInSecondaryCamera() const { } void EntityItem::setIsVisibleInSecondaryCamera(bool value) { - bool changed; withWriteLock([&] { - changed = _isVisibleInSecondaryCamera != value; + _needsRenderUpdate |= _isVisibleInSecondaryCamera != value; _isVisibleInSecondaryCamera = value; }); - - _needsRenderUpdate |= changed; } RenderLayer EntityItem::getRenderLayer() const { @@ -2980,13 +2977,10 @@ RenderLayer EntityItem::getRenderLayer() const { } void EntityItem::setRenderLayer(RenderLayer value) { - bool changed; withWriteLock([&] { - changed = _renderLayer != value; + _needsRenderUpdate |= _renderLayer != value; _renderLayer = value; }); - - _needsRenderUpdate |= changed; } PrimitiveMode EntityItem::getPrimitiveMode() const { @@ -2996,13 +2990,10 @@ PrimitiveMode EntityItem::getPrimitiveMode() const { } void EntityItem::setPrimitiveMode(PrimitiveMode value) { - bool changed = false; withWriteLock([&] { - changed = _primitiveMode != value; + _needsRenderUpdate |= _primitiveMode != value; _primitiveMode = value; }); - - _needsRenderUpdate |= changed; } bool EntityItem::getCauterized() const { @@ -3012,13 +3003,10 @@ bool EntityItem::getCauterized() const { } void EntityItem::setCauterized(bool value) { - bool changed; withWriteLock([&] { - changed = _cauterized != value; + _needsRenderUpdate |= _cauterized != value; _cauterized = value; }); - - _needsRenderUpdate |= changed; } bool EntityItem::getIgnorePickIntersection() const { @@ -3042,13 +3030,10 @@ bool EntityItem::getCanCastShadow() const { } void EntityItem::setCanCastShadow(bool value) { - bool changed; withWriteLock([&] { - changed = _canCastShadow != value; + _needsRenderUpdate |= _canCastShadow != value; _canCastShadow = value; }); - - _needsRenderUpdate |= changed; } bool EntityItem::isChildOfMyAvatar() const { diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 8114fa0c2f..5c7596f6dc 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -571,8 +571,8 @@ public: bool stillHasMyGrabAction() const; - bool needsRenderUpdate() const { return _needsRenderUpdate; } - void setNeedsRenderUpdate(bool needsRenderUpdate) { _needsRenderUpdate = needsRenderUpdate; } + bool needsRenderUpdate() const { return resultWithReadLock([&] { return _needsRenderUpdate; }); } + void setNeedsRenderUpdate(bool needsRenderUpdate) { withWriteLock([&] { _needsRenderUpdate = needsRenderUpdate; }); } signals: void spaceUpdate(std::pair data); diff --git a/libraries/entities/src/GizmoEntityItem.cpp b/libraries/entities/src/GizmoEntityItem.cpp index 671e6e5543..a2fc691387 100644 --- a/libraries/entities/src/GizmoEntityItem.cpp +++ b/libraries/entities/src/GizmoEntityItem.cpp @@ -185,13 +185,10 @@ bool GizmoEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, } void GizmoEntityItem::setGizmoType(GizmoType value) { - bool changed; withWriteLock([&] { - changed = _gizmoType != value; + _needsRenderUpdate |= _gizmoType != value; _gizmoType = value; }); - - _needsRenderUpdate |= changed; } GizmoType GizmoEntityItem::getGizmoType() const { diff --git a/libraries/entities/src/GridEntityItem.cpp b/libraries/entities/src/GridEntityItem.cpp index e826962572..e45ab89b69 100644 --- a/libraries/entities/src/GridEntityItem.cpp +++ b/libraries/entities/src/GridEntityItem.cpp @@ -136,13 +136,10 @@ void GridEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBits } void GridEntityItem::setColor(const glm::u8vec3& color) { - bool changed; withWriteLock([&] { - changed = _color != color; + _needsRenderUpdate |= _color != color; _color = color; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 GridEntityItem::getColor() const { @@ -152,13 +149,10 @@ glm::u8vec3 GridEntityItem::getColor() const { } void GridEntityItem::setAlpha(float alpha) { - bool changed; withWriteLock([&] { - changed = _alpha != alpha; + _needsRenderUpdate |= _alpha != alpha; _alpha = alpha; }); - - _needsRenderUpdate |= changed; } float GridEntityItem::getAlpha() const { @@ -168,13 +162,10 @@ float GridEntityItem::getAlpha() const { } void GridEntityItem::setFollowCamera(bool followCamera) { - bool changed; withWriteLock([&] { - changed = _followCamera != followCamera; + _needsRenderUpdate |= _followCamera != followCamera; _followCamera = followCamera; }); - - _needsRenderUpdate |= changed; } bool GridEntityItem::getFollowCamera() const { @@ -187,13 +178,10 @@ void GridEntityItem::setMajorGridEvery(uint32_t majorGridEvery) { const uint32_t MAJOR_GRID_EVERY_MIN = 1; majorGridEvery = std::max(majorGridEvery, MAJOR_GRID_EVERY_MIN); - bool changed; withWriteLock([&] { - changed = _majorGridEvery != majorGridEvery; + _needsRenderUpdate |= _majorGridEvery != majorGridEvery; _majorGridEvery = majorGridEvery; }); - - _needsRenderUpdate |= changed; } uint32_t GridEntityItem::getMajorGridEvery() const { @@ -206,13 +194,10 @@ void GridEntityItem::setMinorGridEvery(float minorGridEvery) { const float MINOR_GRID_EVERY_MIN = 0.01f; minorGridEvery = std::max(minorGridEvery, MINOR_GRID_EVERY_MIN); - bool changed; withWriteLock([&] { - changed = _minorGridEvery != minorGridEvery; + _needsRenderUpdate |= _minorGridEvery != minorGridEvery; _minorGridEvery = minorGridEvery; }); - - _needsRenderUpdate |= changed; } float GridEntityItem::getMinorGridEvery() const { diff --git a/libraries/entities/src/ImageEntityItem.cpp b/libraries/entities/src/ImageEntityItem.cpp index 80c526b31b..2d942cc25d 100644 --- a/libraries/entities/src/ImageEntityItem.cpp +++ b/libraries/entities/src/ImageEntityItem.cpp @@ -214,13 +214,10 @@ QString ImageEntityItem::getImageURL() const { } void ImageEntityItem::setImageURL(const QString& url) { - bool changed; withWriteLock([&] { - changed = _imageURL != url; + _needsRenderUpdate |= _imageURL != url; _imageURL = url; }); - - _needsRenderUpdate |= changed; } bool ImageEntityItem::getEmissive() const { @@ -232,13 +229,10 @@ bool ImageEntityItem::getEmissive() const { } void ImageEntityItem::setEmissive(bool emissive) { - bool changed; withWriteLock([&] { - changed = _emissive != emissive; + _needsRenderUpdate |= _emissive != emissive; _emissive = emissive; }); - - _needsRenderUpdate |= changed; } bool ImageEntityItem::getKeepAspectRatio() const { @@ -250,13 +244,10 @@ bool ImageEntityItem::getKeepAspectRatio() const { } void ImageEntityItem::setKeepAspectRatio(bool keepAspectRatio) { - bool changed; withWriteLock([&] { - changed = _keepAspectRatio != keepAspectRatio; + _needsRenderUpdate |= _keepAspectRatio != keepAspectRatio; _keepAspectRatio = keepAspectRatio; }); - - _needsRenderUpdate |= changed; } BillboardMode ImageEntityItem::getBillboardMode() const { @@ -268,13 +259,10 @@ BillboardMode ImageEntityItem::getBillboardMode() const { } void ImageEntityItem::setBillboardMode(BillboardMode value) { - bool changed; withWriteLock([&] { - changed = _billboardMode != value; + _needsRenderUpdate |= _billboardMode != value; _billboardMode = value; }); - - _needsRenderUpdate |= changed; } QRect ImageEntityItem::getSubImage() const { @@ -286,23 +274,17 @@ QRect ImageEntityItem::getSubImage() const { } void ImageEntityItem::setSubImage(const QRect& subImage) { - bool changed; withWriteLock([&] { - changed = _subImage != subImage; + _needsRenderUpdate |= _subImage != subImage; _subImage = subImage; }); - - _needsRenderUpdate |= changed; } void ImageEntityItem::setColor(const glm::u8vec3& color) { - bool changed; withWriteLock([&] { - changed = _color != color; + _needsRenderUpdate |= _color != color; _color = color; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 ImageEntityItem::getColor() const { @@ -312,13 +294,10 @@ glm::u8vec3 ImageEntityItem::getColor() const { } void ImageEntityItem::setAlpha(float alpha) { - bool changed; withWriteLock([&] { - changed = _alpha != alpha; + _needsRenderUpdate |= _alpha != alpha; _alpha = alpha; }); - - _needsRenderUpdate |= changed; } float ImageEntityItem::getAlpha() const { diff --git a/libraries/entities/src/LightEntityItem.cpp b/libraries/entities/src/LightEntityItem.cpp index c7638a8488..2df2136639 100644 --- a/libraries/entities/src/LightEntityItem.cpp +++ b/libraries/entities/src/LightEntityItem.cpp @@ -57,12 +57,16 @@ void LightEntityItem::setUnscaledDimensions(const glm::vec3& value) { void LightEntityItem::locationChanged(bool tellPhysics, bool tellChildren) { EntityItem::locationChanged(tellPhysics, tellChildren); - _needsRenderUpdate = true; + withWriteLock([&] { + _needsRenderUpdate = true; + }); } void LightEntityItem::dimensionsChanged() { EntityItem::dimensionsChanged(); - _needsRenderUpdate = true; + withWriteLock([&] { + _needsRenderUpdate = true; + }); } @@ -82,13 +86,10 @@ EntityItemProperties LightEntityItem::getProperties(const EntityPropertyFlags& d void LightEntityItem::setFalloffRadius(float value) { value = glm::max(value, 0.0f); - bool changed; withWriteLock([&] { - changed = _falloffRadius != value; + _needsRenderUpdate |= _falloffRadius != value; _falloffRadius = value; }); - - _needsRenderUpdate |= changed; } void LightEntityItem::setIsSpotlight(bool value) { @@ -107,11 +108,10 @@ void LightEntityItem::setIsSpotlight(bool value) { } withWriteLock([&] { + _needsRenderUpdate = true; _isSpotlight = value; }); setScaledDimensions(newDimensions); - - _needsRenderUpdate = true; } void LightEntityItem::setCutoff(float value) { @@ -121,6 +121,7 @@ void LightEntityItem::setCutoff(float value) { } withWriteLock([&] { + _needsRenderUpdate = true; _cutoff = value; }); @@ -131,8 +132,6 @@ void LightEntityItem::setCutoff(float value) { const float width = length * glm::sin(glm::radians(_cutoff)); setScaledDimensions(glm::vec3(width, width, length)); } - - _needsRenderUpdate = true; } bool LightEntityItem::setProperties(const EntityItemProperties& properties) { @@ -218,13 +217,10 @@ glm::u8vec3 LightEntityItem::getColor() const { } void LightEntityItem::setColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _color != value; + _needsRenderUpdate |= _color != value; _color = value; }); - - _needsRenderUpdate |= changed; } bool LightEntityItem::getIsSpotlight() const { @@ -244,13 +240,10 @@ float LightEntityItem::getIntensity() const { } void LightEntityItem::setIntensity(float value) { - bool changed; withWriteLock([&] { - changed = _intensity != value; + _needsRenderUpdate |= _intensity != value; _intensity = value; }); - - _needsRenderUpdate |= changed; } float LightEntityItem::getFalloffRadius() const { @@ -270,13 +263,10 @@ float LightEntityItem::getExponent() const { } void LightEntityItem::setExponent(float value) { - bool changed; withWriteLock([&] { - changed = _exponent != value; + _needsRenderUpdate |= _exponent != value; _exponent = value; }); - - _needsRenderUpdate |= changed; } float LightEntityItem::getCutoff() const { diff --git a/libraries/entities/src/LineEntityItem.cpp b/libraries/entities/src/LineEntityItem.cpp index ad2b5ef1b8..1cd09c1a0c 100644 --- a/libraries/entities/src/LineEntityItem.cpp +++ b/libraries/entities/src/LineEntityItem.cpp @@ -76,11 +76,10 @@ bool LineEntityItem::appendPoint(const glm::vec3& point) { return false; } withWriteLock([&] { + _needsRenderUpdate = true; _points << point; }); - _needsRenderUpdate = true; - return true; } @@ -98,11 +97,10 @@ bool LineEntityItem::setLinePoints(const QVector& points) { } withWriteLock([&] { + _needsRenderUpdate = true; _points = points; }); - _needsRenderUpdate = true; - return true; } @@ -158,13 +156,10 @@ glm::u8vec3 LineEntityItem::getColor() const { } void LineEntityItem::setColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _color != value; + _needsRenderUpdate |= _color != value; _color = value; }); - - _needsRenderUpdate |= changed; } QVector LineEntityItem::getLinePoints() const { diff --git a/libraries/entities/src/MaterialEntityItem.cpp b/libraries/entities/src/MaterialEntityItem.cpp index c4ad52ef95..1a7c3c601b 100644 --- a/libraries/entities/src/MaterialEntityItem.cpp +++ b/libraries/entities/src/MaterialEntityItem.cpp @@ -153,13 +153,10 @@ QString MaterialEntityItem::getMaterialURL() const { } void MaterialEntityItem::setMaterialURL(const QString& materialURL) { - bool changed; withWriteLock([&] { - changed = _materialURL != materialURL; + _needsRenderUpdate |= _materialURL != materialURL; _materialURL = materialURL; }); - - _needsRenderUpdate |= changed; } QString MaterialEntityItem::getMaterialData() const { @@ -169,13 +166,10 @@ QString MaterialEntityItem::getMaterialData() const { } void MaterialEntityItem::setMaterialData(const QString& materialData) { - bool changed; withWriteLock([&] { - changed = _materialData != materialData; + _needsRenderUpdate |= _materialData != materialData; _materialData = materialData; }); - - _needsRenderUpdate |= changed; } MaterialMappingMode MaterialEntityItem::getMaterialMappingMode() const { @@ -185,12 +179,10 @@ MaterialMappingMode MaterialEntityItem::getMaterialMappingMode() const { } void MaterialEntityItem::setMaterialMappingMode(MaterialMappingMode mode) { - bool changed; withWriteLock([&] { - changed = _materialMappingMode != mode; + _needsRenderUpdate |= _materialMappingMode != mode; _materialMappingMode = mode; }); - _needsRenderUpdate |= changed; setUnscaledDimensions(_desiredDimensions); } @@ -201,13 +193,10 @@ quint16 MaterialEntityItem::getPriority() const { } void MaterialEntityItem::setPriority(quint16 priority) { - bool changed; withWriteLock([&] { - changed = _priority != priority; + _needsRenderUpdate |= _priority != priority; _priority = priority; }); - - _needsRenderUpdate |= changed; } QString MaterialEntityItem::getParentMaterialName() const { @@ -217,13 +206,10 @@ QString MaterialEntityItem::getParentMaterialName() const { } void MaterialEntityItem::setParentMaterialName(const QString& parentMaterialName) { - bool changed; withWriteLock([&] { - changed = _parentMaterialName != parentMaterialName; + _needsRenderUpdate |= _parentMaterialName != parentMaterialName; _parentMaterialName = parentMaterialName; }); - - _needsRenderUpdate |= changed; } glm::vec2 MaterialEntityItem::getMaterialMappingPos() const { @@ -233,13 +219,10 @@ glm::vec2 MaterialEntityItem::getMaterialMappingPos() const { } void MaterialEntityItem::setMaterialMappingPos(const glm::vec2& materialMappingPos) { - bool changed; withWriteLock([&] { - changed = _materialMappingPos != materialMappingPos; + _needsRenderUpdate |= _materialMappingPos != materialMappingPos; _materialMappingPos = materialMappingPos; }); - - _needsRenderUpdate |= changed; } glm::vec2 MaterialEntityItem::getMaterialMappingScale() const { @@ -249,13 +232,10 @@ glm::vec2 MaterialEntityItem::getMaterialMappingScale() const { } void MaterialEntityItem::setMaterialMappingScale(const glm::vec2& materialMappingScale) { - bool changed; withWriteLock([&] { - changed = _materialMappingScale != materialMappingScale; + _needsRenderUpdate |= _materialMappingScale != materialMappingScale; _materialMappingScale = materialMappingScale; }); - - _needsRenderUpdate |= changed; } float MaterialEntityItem::getMaterialMappingRot() const { @@ -265,22 +245,23 @@ float MaterialEntityItem::getMaterialMappingRot() const { } void MaterialEntityItem::setMaterialMappingRot(float materialMappingRot) { - bool changed; withWriteLock([&] { - changed = _materialMappingRot != materialMappingRot; + _needsRenderUpdate |= _materialMappingRot != materialMappingRot; _materialMappingRot = materialMappingRot; }); - - _needsRenderUpdate |= changed; } bool MaterialEntityItem::getMaterialRepeat() const { - return _materialRepeat; + return resultWithReadLock([&] { + return _materialRepeat; + }); } void MaterialEntityItem::setMaterialRepeat(bool value) { - _needsRenderUpdate |= _materialRepeat != value; - _materialRepeat = value; + withWriteLock([&] { + _needsRenderUpdate |= _materialRepeat != value; + _materialRepeat = value; + }); } AACube MaterialEntityItem::calculateInitialQueryAACube(bool& success) { diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 71068c3d0d..0b6e62e89e 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -49,13 +49,10 @@ const QString ModelEntityItem::getTextures() const { } void ModelEntityItem::setTextures(const QString& textures) { - bool changed; withWriteLock([&] { - changed = _textures != textures; + _needsRenderUpdate |= _textures != textures; _textures = textures; }); - - _needsRenderUpdate |= changed; } EntityItemProperties ModelEntityItem::getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const { @@ -580,13 +577,10 @@ bool ModelEntityItem::getRelayParentJoints() const { } void ModelEntityItem::setGroupCulled(bool value) { - bool changed; withWriteLock([&] { - changed = _groupCulled != value; + _needsRenderUpdate |= _groupCulled != value; _groupCulled = value; }); - - _needsRenderUpdate |= changed; } bool ModelEntityItem::getGroupCulled() const { diff --git a/libraries/entities/src/ParticleEffectEntityItem.cpp b/libraries/entities/src/ParticleEffectEntityItem.cpp index 1dbfaff2b3..c20ae87276 100644 --- a/libraries/entities/src/ParticleEffectEntityItem.cpp +++ b/libraries/entities/src/ParticleEffectEntityItem.cpp @@ -169,13 +169,10 @@ ParticleEffectEntityItem::ParticleEffectEntityItem(const EntityItemID& entityIte void ParticleEffectEntityItem::setAlpha(float alpha) { alpha = glm::clamp(alpha, MINIMUM_ALPHA, MAXIMUM_ALPHA); - bool changed; withWriteLock([&] { - changed = _particleProperties.alpha.gradient.target != alpha; + _needsRenderUpdate |= _particleProperties.alpha.gradient.target != alpha; _particleProperties.alpha.gradient.target = alpha; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAlpha() const { @@ -187,13 +184,10 @@ float ParticleEffectEntityItem::getAlpha() const { void ParticleEffectEntityItem::setAlphaStart(float alphaStart) { alphaStart = glm::isnan(alphaStart) ? alphaStart : glm::clamp(alphaStart, MINIMUM_ALPHA, MAXIMUM_ALPHA); - bool changed; withWriteLock([&] { - changed = _particleProperties.alpha.range.start != alphaStart; + _needsRenderUpdate |= _particleProperties.alpha.range.start != alphaStart; _particleProperties.alpha.range.start = alphaStart; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAlphaStart() const { @@ -205,13 +199,10 @@ float ParticleEffectEntityItem::getAlphaStart() const { void ParticleEffectEntityItem::setAlphaFinish(float alphaFinish) { alphaFinish = glm::isnan(alphaFinish) ? alphaFinish : glm::clamp(alphaFinish, MINIMUM_ALPHA, MAXIMUM_ALPHA); - bool changed; withWriteLock([&] { - changed = _particleProperties.alpha.range.finish != alphaFinish; + _needsRenderUpdate |= _particleProperties.alpha.range.finish != alphaFinish; _particleProperties.alpha.range.finish = alphaFinish; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAlphaFinish() const { @@ -223,13 +214,10 @@ float ParticleEffectEntityItem::getAlphaFinish() const { void ParticleEffectEntityItem::setAlphaSpread(float alphaSpread) { alphaSpread = glm::clamp(alphaSpread, MINIMUM_ALPHA, MAXIMUM_ALPHA); - bool changed; withWriteLock([&] { - changed = _particleProperties.alpha.gradient.spread != alphaSpread; + _needsRenderUpdate |= _particleProperties.alpha.gradient.spread != alphaSpread; _particleProperties.alpha.gradient.spread = alphaSpread; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAlphaSpread() const { @@ -244,11 +232,10 @@ void ParticleEffectEntityItem::setLifespan(float lifespan) { bool changed; withWriteLock([&] { changed = _particleProperties.lifespan != lifespan; + _needsRenderUpdate |= changed; _particleProperties.lifespan = lifespan; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -263,13 +250,10 @@ float ParticleEffectEntityItem::getLifespan() const { void ParticleEffectEntityItem::setEmitRate(float emitRate) { emitRate = glm::clamp(emitRate, MINIMUM_EMIT_RATE, MAXIMUM_EMIT_RATE); - bool changed; withWriteLock([&] { - changed = _particleProperties.emission.rate != emitRate; + _needsRenderUpdate |= _particleProperties.emission.rate != emitRate; _particleProperties.emission.rate = emitRate; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getEmitRate() const { @@ -284,11 +268,10 @@ void ParticleEffectEntityItem::setEmitSpeed(float emitSpeed) { bool changed; withWriteLock([&] { changed = _particleProperties.emission.speed.target != emitSpeed; + _needsRenderUpdate |= changed; _particleProperties.emission.speed.target = emitSpeed; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -306,11 +289,10 @@ void ParticleEffectEntityItem::setSpeedSpread(float speedSpread) { bool changed; withWriteLock([&] { changed = _particleProperties.emission.speed.spread != speedSpread; + _needsRenderUpdate |= changed; _particleProperties.emission.speed.spread = speedSpread; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -328,11 +310,10 @@ void ParticleEffectEntityItem::setEmitOrientation(const glm::quat& emitOrientati bool changed; withWriteLock([&] { changed = _particleProperties.emission.orientation != emitOrientation; + _needsRenderUpdate |= changed; _particleProperties.emission.orientation = emitOrientation; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -350,11 +331,10 @@ void ParticleEffectEntityItem::setEmitDimensions(const glm::vec3& emitDimensions bool changed; withWriteLock([&] { changed = _particleProperties.emission.dimensions != emitDimensions; + _needsRenderUpdate |= changed; _particleProperties.emission.dimensions = emitDimensions; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -369,13 +349,10 @@ glm::vec3 ParticleEffectEntityItem::getEmitDimensions() const { void ParticleEffectEntityItem::setEmitRadiusStart(float emitRadiusStart) { emitRadiusStart = glm::clamp(emitRadiusStart, MINIMUM_EMIT_RADIUS_START, MAXIMUM_EMIT_RADIUS_START); - bool changed; withWriteLock([&] { - changed = _particleProperties.radiusStart != emitRadiusStart; + _needsRenderUpdate |= _particleProperties.radiusStart != emitRadiusStart; _particleProperties.radiusStart = emitRadiusStart; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getEmitRadiusStart() const { @@ -387,13 +364,10 @@ float ParticleEffectEntityItem::getEmitRadiusStart() const { void ParticleEffectEntityItem::setPolarStart(float polarStart) { polarStart = glm::clamp(polarStart, MINIMUM_POLAR, MAXIMUM_POLAR); - bool changed; withWriteLock([&] { - changed = _particleProperties.polar.start != polarStart; + _needsRenderUpdate |= _particleProperties.polar.start != polarStart; _particleProperties.polar.start = polarStart; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getPolarStart() const { @@ -405,13 +379,10 @@ float ParticleEffectEntityItem::getPolarStart() const { void ParticleEffectEntityItem::setPolarFinish(float polarFinish) { polarFinish = glm::clamp(polarFinish, MINIMUM_POLAR, MAXIMUM_POLAR); - bool changed; withWriteLock([&] { - changed = _particleProperties.polar.finish != polarFinish; + _needsRenderUpdate |= _particleProperties.polar.finish != polarFinish; _particleProperties.polar.finish = polarFinish; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getPolarFinish() const { @@ -423,13 +394,10 @@ float ParticleEffectEntityItem::getPolarFinish() const { void ParticleEffectEntityItem::setAzimuthStart(float azimuthStart) { azimuthStart = glm::clamp(azimuthStart, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); - bool changed; withWriteLock([&] { - changed = _particleProperties.azimuth.start != azimuthStart; + _needsRenderUpdate |= _particleProperties.azimuth.start != azimuthStart; _particleProperties.azimuth.start = azimuthStart; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAzimuthStart() const { @@ -441,13 +409,10 @@ float ParticleEffectEntityItem::getAzimuthStart() const { void ParticleEffectEntityItem::setAzimuthFinish(float azimuthFinish) { azimuthFinish = glm::clamp(azimuthFinish, MINIMUM_AZIMUTH, MAXIMUM_AZIMUTH); - bool changed; withWriteLock([&] { - changed = _particleProperties.azimuth.finish != azimuthFinish; + _needsRenderUpdate |= _particleProperties.azimuth.finish != azimuthFinish; _particleProperties.azimuth.finish = azimuthFinish; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getAzimuthFinish() const { @@ -462,11 +427,10 @@ void ParticleEffectEntityItem::setEmitAcceleration(const glm::vec3& emitAccelera bool changed; withWriteLock([&] { changed = _particleProperties.emission.acceleration.target != emitAcceleration; + _needsRenderUpdate |= changed; _particleProperties.emission.acceleration.target = emitAcceleration; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -484,11 +448,10 @@ void ParticleEffectEntityItem::setAccelerationSpread(const glm::vec3& accelerati bool changed; withWriteLock([&] { changed = _particleProperties.emission.acceleration.spread != accelerationSpread; + _needsRenderUpdate |= changed; _particleProperties.emission.acceleration.spread = accelerationSpread; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -506,11 +469,10 @@ void ParticleEffectEntityItem::setParticleRadius(float particleRadius) { bool changed; withWriteLock([&] { changed = _particleProperties.radius.gradient.target != particleRadius; + _needsRenderUpdate |= changed; _particleProperties.radius.gradient.target = particleRadius; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -528,11 +490,10 @@ void ParticleEffectEntityItem::setRadiusStart(float radiusStart) { bool changed; withWriteLock([&] { changed = _particleProperties.radius.range.start != radiusStart; + _needsRenderUpdate |= changed; _particleProperties.radius.range.start = radiusStart; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -550,11 +511,10 @@ void ParticleEffectEntityItem::setRadiusFinish(float radiusFinish) { bool changed; withWriteLock([&] { changed = _particleProperties.radius.range.finish != radiusFinish; + _needsRenderUpdate |= changed; _particleProperties.radius.range.finish = radiusFinish; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -572,11 +532,10 @@ void ParticleEffectEntityItem::setRadiusSpread(float radiusSpread) { bool changed; withWriteLock([&] { changed = _particleProperties.radius.gradient.spread != radiusSpread; + _needsRenderUpdate |= changed; _particleProperties.radius.gradient.spread = radiusSpread; }); - _needsRenderUpdate |= changed; - if (changed) { computeAndUpdateDimensions(); } @@ -591,13 +550,10 @@ float ParticleEffectEntityItem::getRadiusSpread() const { void ParticleEffectEntityItem::setParticleSpin(float particleSpin) { particleSpin = glm::clamp(particleSpin, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - bool changed; withWriteLock([&] { - changed = _particleProperties.spin.gradient.target != particleSpin; + _needsRenderUpdate |= _particleProperties.spin.gradient.target != particleSpin; _particleProperties.spin.gradient.target = particleSpin; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getParticleSpin() const { @@ -610,13 +566,10 @@ void ParticleEffectEntityItem::setSpinStart(float spinStart) { spinStart = glm::isnan(spinStart) ? spinStart : glm::clamp(spinStart, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - bool changed; withWriteLock([&] { - changed = _particleProperties.spin.range.start != spinStart; + _needsRenderUpdate |= _particleProperties.spin.range.start != spinStart; _particleProperties.spin.range.start = spinStart; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getSpinStart() const { @@ -629,13 +582,10 @@ void ParticleEffectEntityItem::setSpinFinish(float spinFinish) { spinFinish = glm::isnan(spinFinish) ? spinFinish : glm::clamp(spinFinish, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - bool changed; withWriteLock([&] { - changed = _particleProperties.spin.range.finish != spinFinish; + _needsRenderUpdate |= _particleProperties.spin.range.finish != spinFinish; _particleProperties.spin.range.finish = spinFinish; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getSpinFinish() const { @@ -647,13 +597,10 @@ float ParticleEffectEntityItem::getSpinFinish() const { void ParticleEffectEntityItem::setSpinSpread(float spinSpread) { spinSpread = glm::clamp(spinSpread, MINIMUM_PARTICLE_SPIN, MAXIMUM_PARTICLE_SPIN); - bool changed; withWriteLock([&] { - changed = _particleProperties.spin.gradient.spread != spinSpread; + _needsRenderUpdate |= _particleProperties.spin.gradient.spread != spinSpread; _particleProperties.spin.gradient.spread = spinSpread; }); - - _needsRenderUpdate |= changed; } float ParticleEffectEntityItem::getSpinSpread() const { @@ -817,13 +764,10 @@ bool ParticleEffectEntityItem::setProperties(const EntityItemProperties& propert } void ParticleEffectEntityItem::setColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _particleProperties.color.gradient.target != glm::vec3(value); + _needsRenderUpdate |= _particleProperties.color.gradient.target != glm::vec3(value); _particleProperties.color.gradient.target = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 ParticleEffectEntityItem::getColor() const { @@ -1038,13 +982,10 @@ void ParticleEffectEntityItem::setShapeType(ShapeType type) { break; } - bool changed; withWriteLock([&] { - changed = _shapeType != type; + _needsRenderUpdate |= _shapeType != type; _shapeType = type; }); - - _needsRenderUpdate |= changed; } ShapeType ParticleEffectEntityItem::getShapeType() const { @@ -1054,13 +995,10 @@ ShapeType ParticleEffectEntityItem::getShapeType() const { } void ParticleEffectEntityItem::setCompoundShapeURL(const QString& compoundShapeURL) { - bool changed; withWriteLock([&] { - changed = _compoundShapeURL != compoundShapeURL; + _needsRenderUpdate |= _compoundShapeURL != compoundShapeURL; _compoundShapeURL = compoundShapeURL; }); - - _needsRenderUpdate |= changed; } QString ParticleEffectEntityItem::getCompoundShapeURL() const { @@ -1070,20 +1008,19 @@ QString ParticleEffectEntityItem::getCompoundShapeURL() const { } void ParticleEffectEntityItem::setIsEmitting(bool isEmitting) { - _needsRenderUpdate |= _isEmitting != isEmitting; - _isEmitting = isEmitting; + withWriteLock([&] { + _needsRenderUpdate |= _isEmitting != isEmitting; + _isEmitting = isEmitting; + }); } void ParticleEffectEntityItem::setMaxParticles(quint32 maxParticles) { maxParticles = glm::clamp(maxParticles, MINIMUM_MAX_PARTICLES, MAXIMUM_MAX_PARTICLES); - bool changed; withWriteLock([&] { - changed = _particleProperties.maxParticles != maxParticles; + _needsRenderUpdate |= _particleProperties.maxParticles != maxParticles; _particleProperties.maxParticles = maxParticles; }); - - _needsRenderUpdate |= changed; } quint32 ParticleEffectEntityItem::getMaxParticles() const { @@ -1093,13 +1030,10 @@ quint32 ParticleEffectEntityItem::getMaxParticles() const { } void ParticleEffectEntityItem::setTextures(const QString& textures) { - bool changed; withWriteLock([&] { - changed = _particleProperties.textures != textures; + _needsRenderUpdate |= _particleProperties.textures != textures; _particleProperties.textures = textures; }); - - _needsRenderUpdate |= changed; } QString ParticleEffectEntityItem::getTextures() const { @@ -1109,13 +1043,10 @@ QString ParticleEffectEntityItem::getTextures() const { } void ParticleEffectEntityItem::setColorStart(const vec3& colorStart) { - bool changed; withWriteLock([&] { - changed = _particleProperties.color.range.start != colorStart; + _needsRenderUpdate |= _particleProperties.color.range.start != colorStart; _particleProperties.color.range.start = colorStart; }); - - _needsRenderUpdate |= changed; } glm::vec3 ParticleEffectEntityItem::getColorStart() const { @@ -1125,13 +1056,10 @@ glm::vec3 ParticleEffectEntityItem::getColorStart() const { } void ParticleEffectEntityItem::setColorFinish(const vec3& colorFinish) { - bool changed; withWriteLock([&] { - changed = _particleProperties.color.range.finish != colorFinish; + _needsRenderUpdate |= _particleProperties.color.range.finish != colorFinish; _particleProperties.color.range.finish = colorFinish; }); - - _needsRenderUpdate |= changed; } glm::vec3 ParticleEffectEntityItem::getColorFinish() const { @@ -1141,13 +1069,10 @@ glm::vec3 ParticleEffectEntityItem::getColorFinish() const { } void ParticleEffectEntityItem::setColorSpread(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _particleProperties.color.gradient.spread != glm::vec3(value); + _needsRenderUpdate |= _particleProperties.color.gradient.spread != glm::vec3(value); _particleProperties.color.gradient.spread = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 ParticleEffectEntityItem::getColorSpread() const { diff --git a/libraries/entities/src/PolyLineEntityItem.cpp b/libraries/entities/src/PolyLineEntityItem.cpp index 3c53281690..645d2b39f8 100644 --- a/libraries/entities/src/PolyLineEntityItem.cpp +++ b/libraries/entities/src/PolyLineEntityItem.cpp @@ -249,16 +249,22 @@ glm::u8vec3 PolyLineEntityItem::getColor() const { } void PolyLineEntityItem::setIsUVModeStretch(bool isUVModeStretch) { - _needsRenderUpdate = _isUVModeStretch != isUVModeStretch; - _isUVModeStretch = isUVModeStretch; + withWriteLock([&] { + _needsRenderUpdate = _isUVModeStretch != isUVModeStretch; + _isUVModeStretch = isUVModeStretch; + }); } void PolyLineEntityItem::setGlow(bool glow) { - _needsRenderUpdate = _glow != glow; - _glow = glow; + withWriteLock([&] { + _needsRenderUpdate = _glow != glow; + _glow = glow; + }); } void PolyLineEntityItem::setFaceCamera(bool faceCamera) { - _needsRenderUpdate = _faceCamera != faceCamera; - _faceCamera = faceCamera; + withWriteLock([&] { + _needsRenderUpdate = _faceCamera != faceCamera; + _faceCamera = faceCamera; + }); } \ No newline at end of file diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 8d8ed87ebb..b424ba137f 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -73,13 +73,10 @@ PolyVoxEntityItem::PolyVoxEntityItem(const EntityItemID& entityItemID) : EntityI void PolyVoxEntityItem::setVoxelVolumeSize(const glm::vec3& voxelVolumeSize_) { auto voxelVolumeSize = glm::clamp(glm::round(voxelVolumeSize_), glm::vec3(1.0f), glm::vec3(MAX_VOXEL_DIMENSION)); - bool changed; withWriteLock([&] { - changed = _voxelVolumeSize != voxelVolumeSize; + _needsRenderUpdate |= _voxelVolumeSize != voxelVolumeSize; _voxelVolumeSize = voxelVolumeSize; }); - - _needsRenderUpdate |= changed; } glm::vec3 PolyVoxEntityItem::getVoxelVolumeSize() const { @@ -226,13 +223,10 @@ QByteArray PolyVoxEntityItem::getVoxelData() const { void PolyVoxEntityItem::setXTextureURL(const QString& xTextureURL) { - bool changed; withWriteLock([&] { - changed = _xTextureURL != xTextureURL; + _needsRenderUpdate |= _xTextureURL != xTextureURL; _xTextureURL = xTextureURL; }); - - _needsRenderUpdate |= changed; } QString PolyVoxEntityItem::getXTextureURL() const { @@ -244,13 +238,10 @@ QString PolyVoxEntityItem::getXTextureURL() const { } void PolyVoxEntityItem::setYTextureURL(const QString& yTextureURL) { - bool changed; withWriteLock([&] { - changed = _yTextureURL != yTextureURL; + _needsRenderUpdate |= _yTextureURL != yTextureURL; _yTextureURL = yTextureURL; }); - - _needsRenderUpdate |= changed; } QString PolyVoxEntityItem::getYTextureURL() const { @@ -262,13 +253,10 @@ QString PolyVoxEntityItem::getYTextureURL() const { } void PolyVoxEntityItem::setZTextureURL(const QString& zTextureURL) { - bool changed; withWriteLock([&] { - changed = _zTextureURL != zTextureURL; + _needsRenderUpdate |= _zTextureURL != zTextureURL; _zTextureURL = zTextureURL; }); - - _needsRenderUpdate |= changed; } QString PolyVoxEntityItem::getZTextureURL() const { QString result; diff --git a/libraries/entities/src/ShapeEntityItem.cpp b/libraries/entities/src/ShapeEntityItem.cpp index 47a78fb1d6..882ab26901 100644 --- a/libraries/entities/src/ShapeEntityItem.cpp +++ b/libraries/entities/src/ShapeEntityItem.cpp @@ -129,9 +129,7 @@ EntityItemProperties ShapeEntityItem::getProperties(const EntityPropertyFlags& d } void ShapeEntityItem::setShape(const entity::Shape& shape) { - const entity::Shape prevShape = _shape; - _shape = shape; - switch (_shape) { + switch (shape) { case entity::Shape::Cube: _type = EntityTypes::Box; break; @@ -151,13 +149,22 @@ void ShapeEntityItem::setShape(const entity::Shape& shape) { break; } - if (_shape != prevShape) { + if (shape != getShape()) { // Internally grabs writeLock markDirtyFlags(Simulation::DIRTY_SHAPE); - _needsRenderUpdate = true; + withWriteLock([&] { + _needsRenderUpdate = true; + _shape = shape; + }); } } +entity::Shape ShapeEntityItem::getShape() const { + return resultWithReadLock([&] { + return _shape; + }); +} + bool ShapeEntityItem::setProperties(const EntityItemProperties& properties) { bool somethingChanged = EntityItem::setProperties(properties); // set the properties in our base class @@ -233,13 +240,10 @@ void ShapeEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBit } void ShapeEntityItem::setColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _color != value; + _needsRenderUpdate |= _color != value; _color = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 ShapeEntityItem::getColor() const { @@ -249,13 +253,10 @@ glm::u8vec3 ShapeEntityItem::getColor() const { } void ShapeEntityItem::setAlpha(float alpha) { - bool changed; withWriteLock([&] { - changed = _alpha != alpha; + _needsRenderUpdate |= _alpha != alpha; _alpha = alpha; }); - - _needsRenderUpdate |= changed; } float ShapeEntityItem::getAlpha() const { diff --git a/libraries/entities/src/ShapeEntityItem.h b/libraries/entities/src/ShapeEntityItem.h index 3622c74f50..43c2ce2a1f 100644 --- a/libraries/entities/src/ShapeEntityItem.h +++ b/libraries/entities/src/ShapeEntityItem.h @@ -72,7 +72,7 @@ public: EntityPropertyFlags& propertyFlags, bool overwriteLocalData, bool& somethingChanged) override; - entity::Shape getShape() const { return _shape; } + entity::Shape getShape() const; void setShape(const entity::Shape& shape); void setShape(const QString& shape) { setShape(entity::shapeFromString(shape)); } diff --git a/libraries/entities/src/TextEntityItem.cpp b/libraries/entities/src/TextEntityItem.cpp index a5dc93a573..b33edb28f3 100644 --- a/libraries/entities/src/TextEntityItem.cpp +++ b/libraries/entities/src/TextEntityItem.cpp @@ -251,13 +251,10 @@ bool TextEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, c } void TextEntityItem::setText(const QString& value) { - bool changed; withWriteLock([&] { - changed = _text != value; + _needsRenderUpdate |= _text != value; _text = value; }); - - _needsRenderUpdate |= changed; } QString TextEntityItem::getText() const { @@ -269,13 +266,10 @@ QString TextEntityItem::getText() const { } void TextEntityItem::setLineHeight(float value) { - bool changed; withWriteLock([&] { - changed = _lineHeight != value; + _needsRenderUpdate |= _lineHeight != value; _lineHeight = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getLineHeight() const { @@ -287,13 +281,10 @@ float TextEntityItem::getLineHeight() const { } void TextEntityItem::setTextColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _textColor != value; + _needsRenderUpdate |= _textColor != value; _textColor = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 TextEntityItem::getTextColor() const { @@ -303,13 +294,10 @@ glm::u8vec3 TextEntityItem::getTextColor() const { } void TextEntityItem::setTextAlpha(float value) { - bool changed; withWriteLock([&] { - changed = _textAlpha != value; + _needsRenderUpdate |= _textAlpha != value; _textAlpha = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getTextAlpha() const { @@ -319,13 +307,10 @@ float TextEntityItem::getTextAlpha() const { } void TextEntityItem::setBackgroundColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _backgroundColor != value; + _needsRenderUpdate |= _backgroundColor != value; _backgroundColor = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 TextEntityItem::getBackgroundColor() const { @@ -335,13 +320,10 @@ glm::u8vec3 TextEntityItem::getBackgroundColor() const { } void TextEntityItem::setBackgroundAlpha(float value) { - bool changed; withWriteLock([&] { - changed = _backgroundAlpha != value; + _needsRenderUpdate |= _backgroundAlpha != value; _backgroundAlpha = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getBackgroundAlpha() const { @@ -359,23 +341,17 @@ BillboardMode TextEntityItem::getBillboardMode() const { } void TextEntityItem::setBillboardMode(BillboardMode value) { - bool changed; withWriteLock([&] { - changed = _billboardMode != value; + _needsRenderUpdate |= _billboardMode != value; _billboardMode = value; }); - - _needsRenderUpdate |= changed; } void TextEntityItem::setLeftMargin(float value) { - bool changed; withWriteLock([&] { - changed = _leftMargin != value; + _needsRenderUpdate |= _leftMargin != value; _leftMargin = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getLeftMargin() const { @@ -385,13 +361,10 @@ float TextEntityItem::getLeftMargin() const { } void TextEntityItem::setRightMargin(float value) { - bool changed; withWriteLock([&] { - changed = _rightMargin != value; + _needsRenderUpdate |= _rightMargin != value; _rightMargin = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getRightMargin() const { @@ -401,13 +374,10 @@ float TextEntityItem::getRightMargin() const { } void TextEntityItem::setTopMargin(float value) { - bool changed; withWriteLock([&] { - changed = _topMargin != value; + _needsRenderUpdate |= _topMargin != value; _topMargin = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getTopMargin() const { @@ -417,13 +387,10 @@ float TextEntityItem::getTopMargin() const { } void TextEntityItem::setBottomMargin(float value) { - bool changed; withWriteLock([&] { - changed = _bottomMargin != value; + _needsRenderUpdate |= _bottomMargin != value; _bottomMargin = value; }); - - _needsRenderUpdate |= changed; } float TextEntityItem::getBottomMargin() const { @@ -433,13 +400,10 @@ float TextEntityItem::getBottomMargin() const { } void TextEntityItem::setUnlit(bool value) { - bool changed; withWriteLock([&] { - changed = _unlit != value; + _needsRenderUpdate |= _unlit != value; _unlit = value; }); - - _needsRenderUpdate |= changed; } bool TextEntityItem::getUnlit() const { diff --git a/libraries/entities/src/WebEntityItem.cpp b/libraries/entities/src/WebEntityItem.cpp index 8bdaa8bd31..186a8fa8b4 100644 --- a/libraries/entities/src/WebEntityItem.cpp +++ b/libraries/entities/src/WebEntityItem.cpp @@ -229,13 +229,10 @@ bool WebEntityItem::findDetailedParabolaIntersection(const glm::vec3& origin, co } void WebEntityItem::setColor(const glm::u8vec3& value) { - bool changed; withWriteLock([&] { - changed = _color != value; + _needsRenderUpdate |= _color != value; _color = value; }); - - _needsRenderUpdate |= changed; } glm::u8vec3 WebEntityItem::getColor() const { @@ -245,13 +242,10 @@ glm::u8vec3 WebEntityItem::getColor() const { } void WebEntityItem::setAlpha(float alpha) { - bool changed; withWriteLock([&] { - changed = _alpha != alpha; + _needsRenderUpdate |= _alpha != alpha; _alpha = alpha; }); - - _needsRenderUpdate |= changed; } float WebEntityItem::getAlpha() const { @@ -267,23 +261,17 @@ BillboardMode WebEntityItem::getBillboardMode() const { } void WebEntityItem::setBillboardMode(BillboardMode value) { - bool changed; withWriteLock([&] { - changed = _billboardMode != value; + _needsRenderUpdate |= _billboardMode != value; _billboardMode = value; }); - - _needsRenderUpdate |= changed; } void WebEntityItem::setSourceUrl(const QString& value) { - bool changed; withWriteLock([&] { - changed = _sourceUrl != value; + _needsRenderUpdate |= _sourceUrl != value; _sourceUrl = value; }); - - _needsRenderUpdate |= changed; } QString WebEntityItem::getSourceUrl() const { @@ -293,13 +281,10 @@ QString WebEntityItem::getSourceUrl() const { } void WebEntityItem::setDPI(uint16_t value) { - bool changed; withWriteLock([&] { - changed = _dpi != value; + _needsRenderUpdate |= _dpi != value; _dpi = value; }); - - _needsRenderUpdate |= changed; } uint16_t WebEntityItem::getDPI() const { @@ -318,13 +303,10 @@ void WebEntityItem::setScriptURL(const QString& value) { auto urlString = newURL.toDisplayString(); - bool changed; withWriteLock([&] { - changed = _scriptURL != urlString; + _needsRenderUpdate |= _scriptURL != urlString; _scriptURL = urlString; }); - - _needsRenderUpdate |= changed; } QString WebEntityItem::getScriptURL() const { @@ -334,13 +316,10 @@ QString WebEntityItem::getScriptURL() const { } void WebEntityItem::setMaxFPS(uint8_t value) { - bool changed; withWriteLock([&] { - changed = _maxFPS != value; + _needsRenderUpdate |= _maxFPS != value; _maxFPS = value; }); - - _needsRenderUpdate |= changed; } uint8_t WebEntityItem::getMaxFPS() const { @@ -350,13 +329,10 @@ uint8_t WebEntityItem::getMaxFPS() const { } void WebEntityItem::setInputMode(const WebInputMode& value) { - bool changed; withWriteLock([&] { - changed = _inputMode != value; + _needsRenderUpdate |= _inputMode != value; _inputMode = value; }); - - _needsRenderUpdate |= changed; } WebInputMode WebEntityItem::getInputMode() const { From 67a13ee7cd06df9b4d8b32c4097a33611cd68cdc Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 8 Aug 2019 17:10:46 -0700 Subject: [PATCH 05/21] Exploring differences in the polyline rendering --- .../entities-renderer/src/RenderablePolyLineEntityItem.cpp | 6 ++++-- scripts/developer/utilities/render/luci.qml | 4 ++-- scripts/developer/utilities/render/luci2.js | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 6cdc25d7b3..4f9a408191 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -63,11 +63,13 @@ void PolyLineEntityRenderer::buildPipelines() { } ItemKey PolyLineEntityRenderer::getKey() { - return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); + // return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); + return ItemKey::Builder::opaqueShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); } ShapeKey PolyLineEntityRenderer::getShapeKey() { - auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); + // auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); + auto builder = ShapeKey::Builder().withOwnPipeline().withoutCullFace(); if (_primitiveMode == PrimitiveMode::LINES) { builder.withWireframe(); } diff --git a/scripts/developer/utilities/render/luci.qml b/scripts/developer/utilities/render/luci.qml index 98fd3039d1..803c8f0cb2 100644 --- a/scripts/developer/utilities/render/luci.qml +++ b/scripts/developer/utilities/render/luci.qml @@ -69,7 +69,7 @@ Rectangle { Culling {} } } - Prop.PropFolderPanel { + /* Prop.PropFolderPanel { label: "Tools" panelFrameData: Component { Row { @@ -87,7 +87,7 @@ Rectangle { } } } - } + }*/ /* Jet.TaskPropView { id: "le" jobPath: "" diff --git a/scripts/developer/utilities/render/luci2.js b/scripts/developer/utilities/render/luci2.js index a34cf88415..ba0215569a 100644 --- a/scripts/developer/utilities/render/luci2.js +++ b/scripts/developer/utilities/render/luci2.js @@ -69,8 +69,8 @@ function openView() { } pages.addPage('Luci', 'Luci', '../luci.qml', 300, 420, openLuciWindow, closeLuciWindow); - pages.addPage('openEngineLODView', 'Render LOD', '../lod.qml', 300, 400); - pages.addPage('openMaterialInspectorView', 'Material Inspector', '../materialInspector.qml', 300, 400, MaterialInspector.setWindow, MaterialInspector.setWindow); + // pages.addPage('openEngineLODView', 'Render LOD', '../lod.qml', 300, 400); + // pages.addPage('openMaterialInspectorView', 'Material Inspector', '../materialInspector.qml', 300, 400, MaterialInspector.setWindow, MaterialInspector.setWindow); pages.open('Luci'); From a96ef7b5f00e4e2f773abdd1c6cd174f0ac5b2d5 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 9 Aug 2019 18:34:36 -0700 Subject: [PATCH 06/21] Exloring the why.... --- .../src/RenderablePolyLineEntityItem.cpp | 17 +++++++++-------- scripts/developer/utilities/render/luci.qml | 12 ++++++++++-- .../utilities/render/luci/Antialiasing.qml | 11 ++++++++++- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 4f9a408191..0c4e59ec18 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -52,24 +52,25 @@ void PolyLineEntityRenderer::buildPipelines() { gpu::ShaderPointer program = gpu::Shader::createProgram(key.first == render::Args::DEFERRED ? shader::entities_renderer::program::paintStroke : shader::entities_renderer::program::paintStroke_forward); gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setCullMode(gpu::State::CullMode::CULL_NONE); state->setDepthTest(true, !key.second, gpu::LESS_EQUAL); - PrepareStencil::testMask(*state); - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + PrepareStencil::testMaskDrawShape(*state); + + state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + _pipelines[key] = gpu::Pipeline::create(program, state); } } ItemKey PolyLineEntityRenderer::getKey() { - // return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); - return ItemKey::Builder::opaqueShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); + return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); + // return ItemKey::Builder::opaqueShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); } ShapeKey PolyLineEntityRenderer::getShapeKey() { - // auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); - auto builder = ShapeKey::Builder().withOwnPipeline().withoutCullFace(); + auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); + //auto builder = ShapeKey::Builder().withOwnPipeline().withoutCullFace(); if (_primitiveMode == PrimitiveMode::LINES) { builder.withWireframe(); } diff --git a/scripts/developer/utilities/render/luci.qml b/scripts/developer/utilities/render/luci.qml index 803c8f0cb2..3a61a0394d 100644 --- a/scripts/developer/utilities/render/luci.qml +++ b/scripts/developer/utilities/render/luci.qml @@ -33,6 +33,14 @@ Rectangle { Column { width: parent.width + Prop.PropFolderPanel { + label: "Render Settings" + isUnfold: false + panelFrameData: Component { + RenderSettings { + } + } + } Prop.PropFolderPanel { label: "Shading Model" panelFrameData: Component { @@ -69,7 +77,7 @@ Rectangle { Culling {} } } - /* Prop.PropFolderPanel { + Prop.PropFolderPanel { label: "Tools" panelFrameData: Component { Row { @@ -87,7 +95,7 @@ Rectangle { } } } - }*/ + } /* Jet.TaskPropView { id: "le" jobPath: "" diff --git a/scripts/developer/utilities/render/luci/Antialiasing.qml b/scripts/developer/utilities/render/luci/Antialiasing.qml index e29bca43eb..0cea509761 100644 --- a/scripts/developer/utilities/render/luci/Antialiasing.qml +++ b/scripts/developer/utilities/render/luci/Antialiasing.qml @@ -18,6 +18,8 @@ import controlsUit 1.0 as HifiControls import "../configSlider" import "../../lib/plotperf" +import "../../lib/prop" as Prop + Column{ HifiConstants { id: hifi; } @@ -28,7 +30,14 @@ Column{ anchors.right: parent.right spacing: 10 - + Prop.PropScalar { + label: "MSAA" + object: Render.getConfig("RenderMainView.PreparePrimaryBufferForward") + property: "numSamples" + min: 1 + max: 4 + integral: true + } Row { spacing: 10 id: fxaaOnOff From 9139edc8b116726759b2ccf5b78cd24460461c28 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 12 Aug 2019 00:44:14 -0700 Subject: [PATCH 07/21] Maybe fixed the problem, cannot render the gl41 version properly --- .../src/RenderablePolyLineEntityItem.cpp | 6 ++++-- libraries/entities-renderer/src/paintStroke.slf | 2 +- libraries/render-utils/src/RenderForwardTask.cpp | 12 ++++++++++++ libraries/render-utils/src/RenderForwardTask.h | 12 ++---------- .../developer/utilities/render/luci/Antialiasing.qml | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index 0c4e59ec18..ca0a924d91 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -55,9 +55,11 @@ void PolyLineEntityRenderer::buildPipelines() { state->setCullMode(gpu::State::CullMode::CULL_NONE); state->setDepthTest(true, !key.second, gpu::LESS_EQUAL); - PrepareStencil::testMaskDrawShape(*state); + // PrepareStencil::testMaskDrawShape(*state); + PrepareStencil::testMask(*state); - state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA); + state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); _pipelines[key] = gpu::Pipeline::create(program, state); } diff --git a/libraries/entities-renderer/src/paintStroke.slf b/libraries/entities-renderer/src/paintStroke.slf index 837291efe6..4ae242655c 100644 --- a/libraries/entities-renderer/src/paintStroke.slf +++ b/libraries/entities-renderer/src/paintStroke.slf @@ -31,7 +31,7 @@ layout(location=3) in float _distanceFromCenter; void main(void) { vec4 texel = texture(_texture, _texCoord); texel *= _color; - texel.a *= mix(1.0, pow(1.0 - abs(_distanceFromCenter), 10.0), _polylineData.faceCameraGlow.y); + texel.a *= mix(1.0, pow(1.0 - min(1.0, abs(_distanceFromCenter)), 10.0), _polylineData.faceCameraGlow.y); <@if not HIFI_USE_FORWARD@> packDeferredFragmentTranslucent((2.0 * float(gl_FrontFacing) - 1.0) * _normalWS, texel.a, texel.rgb, DEFAULT_ROUGHNESS); diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 14f2e51697..9b547b82bb 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -48,6 +48,18 @@ using namespace render; extern void initForwardPipelines(ShapePlumber& plumber); +void PreparePrimaryFramebufferMSAAConfig::setResolutionScale(float scale) { + const float SCALE_RANGE_MIN = 0.1f; + const float SCALE_RANGE_MAX = 2.0f; + resolutionScale = std::max(SCALE_RANGE_MIN, std::min(SCALE_RANGE_MAX, scale)); + // emit dirty(); +} + +void PreparePrimaryFramebufferMSAAConfig::setNumSamples(int num) { + numSamples = std::max(1, std::min(32, num)); + emit dirty(); +} + void RenderForwardTask::configure(const Config& config) { // Propagate resolution scale to sub jobs who need it auto preparePrimaryBufferConfig = config.getConfig("PreparePrimaryBufferForward"); diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index dd0abbc9ab..d225ffb648 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -46,18 +46,10 @@ class PreparePrimaryFramebufferMSAAConfig : public render::Job::Config { Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples) public: float getResolutionScale() const { return resolutionScale; } - void setResolutionScale(float scale) { - const float SCALE_RANGE_MIN = 0.1f; - const float SCALE_RANGE_MAX = 2.0f; - resolutionScale = std::max(SCALE_RANGE_MIN, std::min(SCALE_RANGE_MAX, scale)); - //emit dirty(); - } + void setResolutionScale(float scale); int getNumSamples() const { return numSamples; } - void setNumSamples(int num) { - numSamples = std::max(1, std::min(32, num)); - emit dirty(); - } + void setNumSamples(int num); signals: void dirty(); diff --git a/scripts/developer/utilities/render/luci/Antialiasing.qml b/scripts/developer/utilities/render/luci/Antialiasing.qml index 0cea509761..6d1209157f 100644 --- a/scripts/developer/utilities/render/luci/Antialiasing.qml +++ b/scripts/developer/utilities/render/luci/Antialiasing.qml @@ -35,7 +35,7 @@ Column{ object: Render.getConfig("RenderMainView.PreparePrimaryBufferForward") property: "numSamples" min: 1 - max: 4 + max: 32 integral: true } Row { From 0b470b9ab8912eac9a14145950e01d58f207702c Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 13 Aug 2019 00:22:17 -0700 Subject: [PATCH 08/21] Fixing the bad location assignment on gl41 on windows with Austin's help --- .../gpu-gl-common/src/gpu/gl/GLBackend.h | 1 + .../src/gpu/gl/GLBackendShader.cpp | 2 +- .../gpu-gl-common/src/gpu/gl/GLPipeline.cpp | 3 ++- .../gpu-gl/src/gpu/gl41/GL41BackendShader.cpp | 21 ++++++++------- libraries/gpu/src/gpu/Shader.cpp | 26 ++++++++++++------- libraries/gpu/src/gpu/Shader.h | 2 +- .../procedural/src/procedural/Procedural.cpp | 2 +- libraries/render/src/render/ShapePipeline.cpp | 2 +- libraries/shaders/src/shaders/Shaders.cpp | 2 -- libraries/shaders/src/shaders/Shaders.h | 3 --- 10 files changed, 35 insertions(+), 29 deletions(-) diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h index ffd0466b79..2532de31b0 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackend.h @@ -584,6 +584,7 @@ protected: friend class GLState; friend class GLTexture; friend class GLShader; + friend class GLPipeline; }; }} // namespace gpu::gl diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp index f737842ec0..10b573276e 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLBackendShader.cpp @@ -202,7 +202,7 @@ GLint GLBackend::getRealUniformLocation(GLint location) const { void GLBackend::postLinkProgram(ShaderObject& shaderObject, const Shader& program) const { const auto& glprogram = shaderObject.glprogram; - const auto& expectedUniforms = program.getReflection().uniforms; + auto expectedUniforms = program.getReflection(getShaderDialect(), getShaderVariant()).uniforms; auto& uniformRemap = shaderObject.uniformRemap; // initialize all the uniforms with an invalid location diff --git a/libraries/gpu-gl-common/src/gpu/gl/GLPipeline.cpp b/libraries/gpu-gl-common/src/gpu/gl/GLPipeline.cpp index e00dc9fc25..52e10eb417 100644 --- a/libraries/gpu-gl-common/src/gpu/gl/GLPipeline.cpp +++ b/libraries/gpu-gl-common/src/gpu/gl/GLPipeline.cpp @@ -52,7 +52,8 @@ GLPipeline* GLPipeline::sync(GLBackend& backend, const Pipeline& pipeline) { // Special case for view correction matrices, any pipeline that declares the correction buffer // uniform will automatically have it provided without any client code necessary. // Required for stable lighting in the HMD. - object->_cameraCorrection = shader->getReflection().validUniformBuffer(gpu::slot::buffer::CameraCorrection); + auto reflection = shader->getReflection(backend.getShaderDialect(), backend.getShaderVariant()); + object->_cameraCorrection = reflection.validUniformBuffer(gpu::slot::buffer::CameraCorrection); object->_program = programObject; object->_state = stateObject; diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp index f33dd91d03..1b21be2e73 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp @@ -15,7 +15,7 @@ using namespace gpu::gl41; void GL41Backend::postLinkProgram(ShaderObject& programObject, const Shader& program) const { Parent::postLinkProgram(programObject, program); const auto& glprogram = programObject.glprogram; - const auto& reflection = program.getReflection(); + auto reflection = program.getReflection(getShaderDialect(), getShaderVariant()); // For the UBOs, use glUniformBlockBinding to fixup the locations based on the reflection { const auto& expectedUbos = reflection.uniformBuffers; @@ -43,25 +43,26 @@ void GL41Backend::postLinkProgram(ShaderObject& programObject, const Shader& pro } // For the resource buffers, do the same as for the textures, since in GL 4.1 that's how they're implemented + static const std::string TRANSFORM_OBJECT_BUFFER = "transformObjectBuffer"; { const auto& expectedResourceBuffers = reflection.resourceBuffers; const auto names = Shader::Reflection::getNames(expectedResourceBuffers); const auto resourceBufferUniforms = ::gl::Uniform::loadByName(glprogram, names); for (const auto& resourceBuffer : resourceBufferUniforms) { + + // Special case for the transformObjectBuffer, which is filtered out of the reflection data at shader load time + if (resourceBuffer.name == TRANSFORM_OBJECT_BUFFER) { + glProgramUniform1i(glprogram, resourceBuffer.binding, ::gpu::slot::texture::ObjectTransforms); + continue; + } const auto& targetBinding = expectedResourceBuffers.at(resourceBuffer.name); + if (resourceBuffer.name == std::string("polylineVerticesBuffer")) { + qDebug() << "Setting texture unit for " << resourceBuffer.name.c_str() << " to " << targetBinding; + } glProgramUniform1i(glprogram, resourceBuffer.binding, targetBinding); } } - // Special case for the transformObjectBuffer, which is filtered out of the reflection data at shader load time - // - { - static const std::string TRANSFORM_OBJECT_BUFFER = "transformObjectBuffer"; - const auto uniform = ::gl::Uniform::loadByName(glprogram, TRANSFORM_OBJECT_BUFFER); - if (-1 != uniform.binding) { - glProgramUniform1i(glprogram, uniform.binding, ::gpu::slot::texture::ObjectTransforms); - } - } } diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index d4236ac66c..6fef768a08 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -43,17 +43,25 @@ Shader::Shader(Type type, const Pointer& vertex, const Pointer& geometry, const shaders[VERTEX] = vertex; shaders[PIXEL] = pixel; } +} - auto& reflection = const_cast(getReflection()); - for (const auto& subShader : _shaders) { - reflection.merge(subShader->getReflection()); - } - if (_shaders[VERTEX]) { - reflection.inputs = _shaders[VERTEX]->getReflection().inputs; - } - if (_shaders[PIXEL]) { - reflection.outputs = _shaders[PIXEL]->getReflection().outputs; +Shader::Reflection Shader::getReflection(shader::Dialect dialect, shader::Variant variant) const { + if (_type == Shader::Type::PROGRAM) { + Reflection reflection; + for (const auto& subShader : _shaders) { + reflection.merge(subShader->getReflection(dialect, variant)); + } + if (_shaders[VERTEX]) { + reflection.inputs = _shaders[VERTEX]->getReflection(dialect, variant).inputs; + } + if (_shaders[PIXEL]) { + reflection.outputs = _shaders[PIXEL]->getReflection(dialect, variant).outputs; + } + + return reflection; } + + return _source.getReflection(dialect, variant); } Shader::~Shader() diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index 987e632025..6461437971 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -91,7 +91,7 @@ public: const Shaders& getShaders() const { return _shaders; } - const Reflection& getReflection() const { return _source.reflection; } + Reflection getReflection(shader::Dialect dialect, shader::Variant variant) const; // Compilation Handler can be passed while compiling a shader (in the makeProgram call) to be able to give the hand to // the caller thread if the compilation fails and to provide a different version of the source for it diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index dbdf9cc7d1..7d0b7c05ea 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -268,7 +268,7 @@ void Procedural::prepare(gpu::Batch& batch, int customSlot = procedural::slot::uniform::Custom; for (const auto& key : _data.uniforms.keys()) { std::string uniformName = key.toLocal8Bit().data(); - fragmentSource.reflection.uniforms[uniformName] = customSlot; + // fragmentSource.reflection.uniforms[uniformName] = customSlot; ++customSlot; } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 12947f5291..9942f1a46c 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -86,7 +86,7 @@ void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state, BatchSetter batchSetter, ItemSetter itemSetter) { ShapeKey key{ filter._flags }; - const auto& reflection = program->getReflection(); + auto reflection = program->getReflection(shader::Dialect::glsl450, shader::Variant::Mono); auto locations = std::make_shared(); locations->albedoTextureUnit = reflection.validTexture(graphics::slot::texture::MaterialAlbedo); locations->roughnessTextureUnit = reflection.validTexture(graphics::slot::texture::MaterialRoughness); diff --git a/libraries/shaders/src/shaders/Shaders.cpp b/libraries/shaders/src/shaders/Shaders.cpp index a074c2f0c9..02a3c9587e 100644 --- a/libraries/shaders/src/shaders/Shaders.cpp +++ b/libraries/shaders/src/shaders/Shaders.cpp @@ -131,7 +131,6 @@ Source::Pointer Source::loadSource(uint32_t shaderId) { for (const auto& dialect : dialects) { result->dialectSources[dialect] = loadDialectSource(dialect, shaderId); } - result->reflection = result->dialectSources[DEFAULT_DIALECT].variantSources[Variant::Mono].reflection; return result; } @@ -140,7 +139,6 @@ Source& Source::operator=(const Source& other) { name = other.name; dialectSources = other.dialectSources; replacements = other.replacements; - reflection = other.reflection; return *this; } diff --git a/libraries/shaders/src/shaders/Shaders.h b/libraries/shaders/src/shaders/Shaders.h index 134b2bdcf8..7eb4241de4 100644 --- a/libraries/shaders/src/shaders/Shaders.h +++ b/libraries/shaders/src/shaders/Shaders.h @@ -140,9 +140,6 @@ struct Source { // The name of the shader file, with extension, i.e. DrawColor.frag std::string name; - // Generic reflection, copied from the 450 dialect / mono variant - Reflection reflection; - // Map of platforms to their specific shaders std::unordered_map dialectSources; From 224e9590ecb7ccf22be236ba013ef3d017606560 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 13 Aug 2019 15:45:24 -0700 Subject: [PATCH 09/21] avoid using explicit dialects when we want just a default one --- libraries/gpu/src/gpu/Shader.cpp | 19 +++++++++++++++++++ libraries/gpu/src/gpu/Shader.h | 1 + libraries/render/src/render/ShapePipeline.cpp | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index 6fef768a08..dcdbff56d2 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -64,6 +64,25 @@ Shader::Reflection Shader::getReflection(shader::Dialect dialect, shader::Varian return _source.getReflection(dialect, variant); } + +Shader::Reflection Shader::getReflection() const { + + // FOr sake of convenience i would like to be able to use a "default" dialect that represents the reflection + // of the source of the shader + // What i really want, is a reflection that is designed for the gpu lib interface but we don;t have that yet (glsl45 is the closest to that) + // Until we have an implementation for this, we will return such default reflection from the one available and platform specific + +#if defined(USE_GLES) + auto defaultDialect = shader::Dialect::glsl310es; +#elif defined(Q_OS_MAC) + // Mac only supports 4.1 + auto defaultDialect = shader::Dialect::glsl410; +#else + auto defaultDialect = shader::Dialect::glsl450; +#endif + return getReflection(defaultDialect, shader::Variant::Mono); +} + Shader::~Shader() { } diff --git a/libraries/gpu/src/gpu/Shader.h b/libraries/gpu/src/gpu/Shader.h index 6461437971..f4f37b1815 100755 --- a/libraries/gpu/src/gpu/Shader.h +++ b/libraries/gpu/src/gpu/Shader.h @@ -92,6 +92,7 @@ public: const Shaders& getShaders() const { return _shaders; } Reflection getReflection(shader::Dialect dialect, shader::Variant variant) const; + Reflection getReflection() const; // get the default version of the reflection // Compilation Handler can be passed while compiling a shader (in the makeProgram call) to be able to give the hand to // the caller thread if the compilation fails and to provide a different version of the source for it diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 9942f1a46c..048e08e959 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -86,7 +86,7 @@ void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state, BatchSetter batchSetter, ItemSetter itemSetter) { ShapeKey key{ filter._flags }; - auto reflection = program->getReflection(shader::Dialect::glsl450, shader::Variant::Mono); + auto reflection = program->getReflection(); auto locations = std::make_shared(); locations->albedoTextureUnit = reflection.validTexture(graphics::slot::texture::MaterialAlbedo); locations->roughnessTextureUnit = reflection.validTexture(graphics::slot::texture::MaterialRoughness); From 3e862950a8148ac9c7dc6fb947ad4faa7f9d5fe3 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 13 Aug 2019 15:47:59 -0700 Subject: [PATCH 10/21] BUGZ-1119: workaround for race condition crash in QML rendering --- libraries/qml/src/qml/impl/RenderEventHandler.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/qml/src/qml/impl/RenderEventHandler.cpp b/libraries/qml/src/qml/impl/RenderEventHandler.cpp index cc9fe34edc..c2e69d5a9b 100644 --- a/libraries/qml/src/qml/impl/RenderEventHandler.cpp +++ b/libraries/qml/src/qml/impl/RenderEventHandler.cpp @@ -136,7 +136,6 @@ void RenderEventHandler::qmlRender(bool sceneGraphSync) { resize(); - if (_currentSize != QSize()) { PROFILE_RANGE(render_qml_gl, "render"); GLuint texture = SharedObject::getTextureCache().acquireTexture(_currentSize); @@ -148,7 +147,15 @@ void RenderEventHandler::qmlRender(bool sceneGraphSync) { } else { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); _shared->setRenderTarget(_fbo, _currentSize); - _shared->_renderControl->render(); + + // workaround for https://highfidelity.atlassian.net/browse/BUGZ-1119 + { + // Serialize QML rendering because of a crash caused by Qt bug + // https://bugreports.qt.io/browse/QTBUG-77469 + static std::mutex qmlRenderMutex; + std::unique_lock qmlRenderLock{ qmlRenderMutex }; + _shared->_renderControl->render(); + } } _shared->_lastRenderTime = usecTimestampNow(); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); From 1570c59a4545583b16609d1240f963a2bd5da82b Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Tue, 13 Aug 2019 16:06:44 -0700 Subject: [PATCH 11/21] Allow collapsing of all multi spheres --- libraries/physics/src/MultiSphereShape.cpp | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/libraries/physics/src/MultiSphereShape.cpp b/libraries/physics/src/MultiSphereShape.cpp index 5a5a9d8dab..0b09a70a4d 100644 --- a/libraries/physics/src/MultiSphereShape.cpp +++ b/libraries/physics/src/MultiSphereShape.cpp @@ -306,6 +306,7 @@ void MultiSphereShape::spheresFromAxes(const std::vector& points, con float distance = glm::length(axis); float correntionRatio = radiusRatio * (spheres[j]._radius / maxAverageRadius); float radius = (correntionRatio < 0.8f * radiusRatio ? 0.8f * radiusRatio : correntionRatio) * spheres[j]._radius; + maxRadius = radius > maxRadius ? radius : maxRadius; if (sphereCount > 3) { distance = contractionRatio * distance; } @@ -317,15 +318,28 @@ void MultiSphereShape::spheresFromAxes(const std::vector& points, con } } // Collapse spheres if too close - if (sphereCount == 2) { - int maxRadiusIndex = spheres[0]._radius > spheres[1]._radius ? 0 : 1; - if (glm::length(spheres[0]._position - spheres[1]._position) < 0.2f * spheres[maxRadiusIndex]._radius) { - SphereShapeData newSphere; - newSphere._position = 0.5f * (spheres[0]._position + spheres[1]._position); - newSphere._radius = spheres[maxRadiusIndex]._radius; - spheres.clear(); - spheres.push_back(newSphere); + if (sphereCount > 1) { + bool collapsed = false; + for (size_t i = 0; i < spheres.size() - 1; i++) { + for (size_t j = i + 1; j < spheres.size(); j++) { + if (i != j) { + int maxRadiusIndex = spheres[i]._radius > spheres[j]._radius ? i : j; + if (glm::length(spheres[i]._position - spheres[j]._position) < 0.2f * spheres[maxRadiusIndex]._radius) { + SphereShapeData newSphere; + newSphere._position = _midPoint; + newSphere._radius = maxRadius; + spheres.clear(); + spheres.push_back(newSphere); + collapsed = true; + break; + } + } + } + if (collapsed) { + break; + } } + } } From 4a93b23d83d1dd80bb518067d8920489f72ecbfa Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 13 Aug 2019 18:47:57 -0700 Subject: [PATCH 12/21] Address the procedural to populate all reflection versions with user uniforms bindings and make EnigneInspector works correctly --- .../src/RenderablePolyLineEntityItem.cpp | 3 --- libraries/gpu/src/gpu/Shader.cpp | 16 +++---------- .../procedural/src/procedural/Procedural.cpp | 24 ++++++++++++++----- .../render-utils/src/RenderForwardTask.h | 4 ++-- libraries/shaders/src/shaders/Shaders.cpp | 6 ++--- libraries/shaders/src/shaders/Shaders.h | 2 ++ .../utilities/lib/jet/qml/TaskPropView.qml | 2 +- .../utilities/lib/prop/PropGroup.qml | 2 +- 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index ca0a924d91..1c3e755c7b 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -55,7 +55,6 @@ void PolyLineEntityRenderer::buildPipelines() { state->setCullMode(gpu::State::CullMode::CULL_NONE); state->setDepthTest(true, !key.second, gpu::LESS_EQUAL); - // PrepareStencil::testMaskDrawShape(*state); PrepareStencil::testMask(*state); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, @@ -67,12 +66,10 @@ void PolyLineEntityRenderer::buildPipelines() { ItemKey PolyLineEntityRenderer::getKey() { return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); - // return ItemKey::Builder::opaqueShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); } ShapeKey PolyLineEntityRenderer::getShapeKey() { auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); - //auto builder = ShapeKey::Builder().withOwnPipeline().withoutCullFace(); if (_primitiveMode == PrimitiveMode::LINES) { builder.withWireframe(); } diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index dcdbff56d2..6a1ea53cda 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -66,21 +66,11 @@ Shader::Reflection Shader::getReflection(shader::Dialect dialect, shader::Varian Shader::Reflection Shader::getReflection() const { - - // FOr sake of convenience i would like to be able to use a "default" dialect that represents the reflection + // For sake of convenience i would like to be able to use a "default" dialect that represents the reflection // of the source of the shader - // What i really want, is a reflection that is designed for the gpu lib interface but we don;t have that yet (glsl45 is the closest to that) + // What i really want, is a reflection that is designed for the gpu lib interface but we don't have that yet (glsl45 is the closest to that) // Until we have an implementation for this, we will return such default reflection from the one available and platform specific - -#if defined(USE_GLES) - auto defaultDialect = shader::Dialect::glsl310es; -#elif defined(Q_OS_MAC) - // Mac only supports 4.1 - auto defaultDialect = shader::Dialect::glsl410; -#else - auto defaultDialect = shader::Dialect::glsl450; -#endif - return getReflection(defaultDialect, shader::Variant::Mono); + return getReflection(shader::DEFAULT_DIALECT, shader::Variant::Mono); } Shader::~Shader() diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 7d0b7c05ea..ce4fbb2a38 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -264,12 +264,24 @@ void Procedural::prepare(gpu::Batch& batch, fragmentSource.replacements[PROCEDURAL_VERSION] = "#define PROCEDURAL_V" + std::to_string(_data.version); fragmentSource.replacements[PROCEDURAL_BLOCK] = _shaderSource.toStdString(); - // Set any userdata specified uniforms - int customSlot = procedural::slot::uniform::Custom; - for (const auto& key : _data.uniforms.keys()) { - std::string uniformName = key.toLocal8Bit().data(); - // fragmentSource.reflection.uniforms[uniformName] = customSlot; - ++customSlot; + // Set any userdata specified uniforms (if any) + if (!_data.uniforms.empty()) { + // First grab all the possible dialect/variant/Reflections + std::vector allReflections; + for (auto dialectIt = fragmentSource.dialectSources.begin(); dialectIt != fragmentSource.dialectSources.end(); ++dialectIt) { + for (auto variantIt = (*dialectIt).second.variantSources.begin(); variantIt != (*dialectIt).second.variantSources.end(); ++variantIt) { + allReflections.push_back(&(*variantIt).second.reflection); + } + } + // Then fill in every reflections the new custom bindings + int customSlot = procedural::slot::uniform::Custom; + for (const auto& key : _data.uniforms.keys()) { + std::string uniformName = key.toLocal8Bit().data(); + for (auto reflection : allReflections) { + reflection->uniforms[uniformName] = customSlot; + } + ++customSlot; + } } // Leave this here for debugging diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index d225ffb648..647994d3c0 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -42,8 +42,8 @@ public: class PreparePrimaryFramebufferMSAAConfig : public render::Job::Config { Q_OBJECT - Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale) - Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples) + Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale NOTIFY dirty()) + Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty()) public: float getResolutionScale() const { return resolutionScale; } void setResolutionScale(float scale); diff --git a/libraries/shaders/src/shaders/Shaders.cpp b/libraries/shaders/src/shaders/Shaders.cpp index 02a3c9587e..ef67842f84 100644 --- a/libraries/shaders/src/shaders/Shaders.cpp +++ b/libraries/shaders/src/shaders/Shaders.cpp @@ -32,7 +32,7 @@ namespace shader { #if defined(USE_GLES) -static const Dialect DEFAULT_DIALECT = Dialect::glsl310es; +const Dialect DEFAULT_DIALECT = Dialect::glsl310es; const std::vector& allDialects() { static const std::vector ALL_DIALECTS{ { Dialect::glsl310es } }; @@ -41,7 +41,7 @@ const std::vector& allDialects() { #elif defined(Q_OS_MAC) -static const Dialect DEFAULT_DIALECT = Dialect::glsl410; +const Dialect DEFAULT_DIALECT = Dialect::glsl410; const std::vector& allDialects() { static const std::vector ALL_DIALECTS{ Dialect::glsl410 }; @@ -50,7 +50,7 @@ const std::vector& allDialects() { #else -static const Dialect DEFAULT_DIALECT = Dialect::glsl450; +const Dialect DEFAULT_DIALECT = Dialect::glsl450; const std::vector & allDialects() { static const std::vector ALL_DIALECTS{ { Dialect::glsl450, Dialect::glsl410 } }; diff --git a/libraries/shaders/src/shaders/Shaders.h b/libraries/shaders/src/shaders/Shaders.h index 7eb4241de4..701695c3a8 100644 --- a/libraries/shaders/src/shaders/Shaders.h +++ b/libraries/shaders/src/shaders/Shaders.h @@ -42,6 +42,8 @@ enum class Dialect #endif }; +extern const Dialect DEFAULT_DIALECT; + const std::vector& allDialects(); const std::string& dialectPath(Dialect dialect); diff --git a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml index 04a18f8e2a..69902392a5 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml @@ -91,7 +91,7 @@ Prop.PropGroup { // console.log(JSON.stringify(props)); if (showProps) { for (var p in props) { - propsModel.push({"object": rootConfig.getConfig(jobPath), "property":props[p] }) + propsModel.push({"object": rootConfig.getConfig(jobPath), "property":props[p]}) } root.updatePropItems(root.propItemsPanel, propsModel); } diff --git a/scripts/developer/utilities/lib/prop/PropGroup.qml b/scripts/developer/utilities/lib/prop/PropGroup.qml index c6b2c694f6..bfae2798eb 100644 --- a/scripts/developer/utilities/lib/prop/PropGroup.qml +++ b/scripts/developer/utilities/lib/prop/PropGroup.qml @@ -68,7 +68,7 @@ PropFolderPanel { "min": (proItem["min"] !== undefined ? proItem.min : 0.0), "max": (proItem["max"] !== undefined ? proItem.max : 1.0), "integer": (proItem["integral"] !== undefined ? proItem.integral : false), - "readOnly": (proItem["readOnly"] !== undefined ? proItem["readOnly"] : false), + "readOnly": (proItem["readOnly"] !== undefined ? proItem["readOnly"] : true), }) } break; case 'PropEnum': { From 5c085bd08d5139c566908f470cf06b7e5517e7ac Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 13 Aug 2019 18:58:35 -0700 Subject: [PATCH 13/21] CLean the code of the task::COnfig changes --- libraries/task/src/task/Config.h | 126 ++++-------------- libraries/task/src/task/Task.h | 12 +- .../utilities/lib/jet/qml/TaskList.qml | 2 +- 3 files changed, 28 insertions(+), 112 deletions(-) diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index ba17c7418c..193674d152 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -161,10 +161,24 @@ public: template typename T::Config* getConfig(std::string jobPath = "") const { return dynamic_cast(getJobConfig(jobPath)); } - + + // Describe the node graph data connections of the associated Job/Task + /**jsdoc + * @function JobConfig.isTask + * @returns {boolean} + */ Q_INVOKABLE bool isTask() const { return _isTask; } + + /**jsdoc + * @function JobConfig.isSwitch + * @returns {boolean} + */ Q_INVOKABLE bool isSwitch() const { return _isSwitch; } + /**jsdoc + * @function JobConfig.getSubConfigs + * @returns {object[]} + */ Q_INVOKABLE QObjectList getSubConfigs() const { auto list = findChildren(QRegExp(".*"), Qt::FindDirectChildrenOnly); QObjectList returned; @@ -173,38 +187,23 @@ public: } return returned; } + + /**jsdoc + * @function JobConfig.getNumSubs + * @returns {number} + */ Q_INVOKABLE int getNumSubs() const { return getSubConfigs().size(); } + + /**jsdoc + * @function JobConfig.getSubConfig + * @param {number} index + * @returns {object} + */ Q_INVOKABLE QObject* getSubConfig(int i) const { auto subs = getSubConfigs(); return ((i < 0 || i >= subs.size()) ? nullptr : subs[i]); } - // Describe the node graph data connections of the associated Job/Task - /**jsdoc - * @function Workload.isTask - * @returns {boolean} - */ - //Q_INVOKABLE virtual bool isTask() const { return false; } - - /**jsdoc - * @function Workload.getSubConfigs - * @returns {object[]} - */ - // Q_INVOKABLE virtual QObjectList getSubConfigs() const { return QObjectList(); } - - /**jsdoc - * @function Workload.getNumSubs - * @returns {number} - */ - // Q_INVOKABLE virtual int getNumSubs() const { return 0; } - - /**jsdoc - * @function Workload.getSubConfig - * @param {number} index - * @returns {object} - */ - //Q_INVOKABLE virtual QObject* getSubConfig(int i) const { return nullptr; } - void connectChildConfig(std::shared_ptr childConfig, const std::string& name); void transferChildrenConfigs(std::shared_ptr source); @@ -249,79 +248,6 @@ signals: using QConfigPointer = std::shared_ptr; - - -#ifdef SPECIALIZE_CONFIG -/**jsdoc - * @namespace Workload - * - * @hifi-interface - * @hifi-client-entity - * @hifi-avatar - * - * @property {number} cpuRunTime - Read-only. - * @property {boolean} enabled - */ -class TaskConfig : public JobConfig { - Q_OBJECT - -public: - using Persistent = PersistentConfig; - - TaskConfig() = default; - TaskConfig(bool enabled) : JobConfig(enabled) {} - - /**jsdoc - * @function Workload.getConfig - * @param {string} name - * @returns {object} - */ - // Get a sub job config through task.getConfig(path) - // where path can be: - // - search for the first job named job_name traversing the the sub graph of task and jobs (from this task as root) - // - .[.] - // Allowing 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 were found) - // - // getter for qml integration, prefer the templated getter - Q_INVOKABLE QObject* getConfig(const QString& name) { return getConfig(name.toStdString()); } - - // getter for cpp (strictly typed), prefer this getter - TaskConfig* getRootConfig(const std::string& jobPath, std::string& jobName) const; - JobConfig* getJobConfig(const std::string& jobPath) const; - - template typename T::Config* getConfig(std::string jobPath = "") const { - return dynamic_cast(getJobConfig(jobPath)); - } - - Q_INVOKABLE bool isTask() const override { return true; } - Q_INVOKABLE QObjectList getSubConfigs() const override { - auto list = findChildren(QRegExp(".*"), Qt::FindDirectChildrenOnly); - QObjectList returned; - for (int i = 0; i < list.size(); i++) { - returned.push_back(list[i]); - } - return returned; - } - Q_INVOKABLE int getNumSubs() const override { return getSubConfigs().size(); } - Q_INVOKABLE QObject* getSubConfig(int i) const override { - auto subs = getSubConfigs(); - return ((i < 0 || i >= subs.size()) ? nullptr : subs[i]); - } -}; - -class SwitchConfig : public JobConfig { - Q_OBJECT - Q_PROPERTY(int branch READ getBranch WRITE setBranch NOTIFY dirtyEnabled) - -public: - uint8_t getBranch() const { return _branch; } - void setBranch(uint8_t index); - -protected: - uint8_t _branch { 0 }; -}; -#endif } #endif // hifi_task_Config_h diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 0871cb5982..4d346480b6 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -80,8 +80,7 @@ public: virtual QConfigPointer& getConfiguration() { return _config; } virtual void applyConfiguration() = 0; - void setCPURunTime(const std::chrono::nanoseconds& runtime) { - /*std::static_pointer_cast*/(_config)->setCPURunTime(runtime); } + void setCPURunTime(const std::chrono::nanoseconds& runtime) { (_config)->setCPURunTime(runtime); } QConfigPointer _config; protected: @@ -95,9 +94,6 @@ template void jobConfigure(T& data, const C& configuration) { template void jobConfigure(T&, const JobConfig&) { // nop, as the default JobConfig was used, so the data does not need a configure method } -/*template void jobConfigure(T&, const TaskConfig&) { - // nop, as the default TaskConfig was used, so the data does not need a configure method -}*/ template void jobRun(T& data, const JC& jobContext, const JobNoIO& input, JobNoIO& output) { data.run(jobContext); @@ -296,9 +292,6 @@ public: TimeProfiler probe("build::" + model->getName()); model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } - // Recreate the Config to use the templated type - // model->createConfiguration(); - // model->applyConfiguration(); return model; } @@ -439,9 +432,6 @@ public: TimeProfiler probe("build::" + model->getName()); model->_data.build(*(model), model->_input, model->_output, std::forward(args)...); } - // Recreate the Config to use the templated type - // model->createConfiguration(); - // model->applyConfiguration(); return model; } diff --git a/scripts/developer/utilities/lib/jet/qml/TaskList.qml b/scripts/developer/utilities/lib/jet/qml/TaskList.qml index 0cfd9c049a..e4b0267d3f 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskList.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskList.qml @@ -31,7 +31,7 @@ Rectangle { } Component.onCompleted: { - var message = "sam" + var message = "" var functor = Jet.job_print_functor(function (line) { message += line + "\n"; }, false, true); Jet.task_traverseTree(rootConfig, functor); textArea.append(message); From 02e730a4d95ee3174422b59192a0a9af5a39a947 Mon Sep 17 00:00:00 2001 From: luiscuenca Date: Wed, 14 Aug 2019 08:08:32 -0700 Subject: [PATCH 14/21] fix size_t warning --- libraries/physics/src/MultiSphereShape.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/MultiSphereShape.cpp b/libraries/physics/src/MultiSphereShape.cpp index 0b09a70a4d..e8181e19c3 100644 --- a/libraries/physics/src/MultiSphereShape.cpp +++ b/libraries/physics/src/MultiSphereShape.cpp @@ -323,7 +323,7 @@ void MultiSphereShape::spheresFromAxes(const std::vector& points, con for (size_t i = 0; i < spheres.size() - 1; i++) { for (size_t j = i + 1; j < spheres.size(); j++) { if (i != j) { - int maxRadiusIndex = spheres[i]._radius > spheres[j]._radius ? i : j; + size_t maxRadiusIndex = spheres[i]._radius > spheres[j]._radius ? i : j; if (glm::length(spheres[i]._position - spheres[j]._position) < 0.2f * spheres[maxRadiusIndex]._radius) { SphereShapeData newSphere; newSphere._position = _midPoint; From 859016bf37fadd49e94d5a10f46f6d15fc143f96 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 14 Aug 2019 10:28:42 -0700 Subject: [PATCH 15/21] Addressing review comments --- libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp | 3 --- libraries/render-utils/src/RenderForwardTask.cpp | 1 - libraries/render-utils/src/RenderForwardTask.h | 4 ++-- libraries/task/src/task/Config.h | 2 -- libraries/task/src/task/Task.h | 1 - scripts/developer/utilities/render/luci2.js | 4 ++-- 6 files changed, 4 insertions(+), 11 deletions(-) diff --git a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp index 1b21be2e73..227bad787b 100644 --- a/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp +++ b/libraries/gpu-gl/src/gpu/gl41/GL41BackendShader.cpp @@ -56,9 +56,6 @@ void GL41Backend::postLinkProgram(ShaderObject& programObject, const Shader& pro continue; } const auto& targetBinding = expectedResourceBuffers.at(resourceBuffer.name); - if (resourceBuffer.name == std::string("polylineVerticesBuffer")) { - qDebug() << "Setting texture unit for " << resourceBuffer.name.c_str() << " to " << targetBinding; - } glProgramUniform1i(glprogram, resourceBuffer.binding, targetBinding); } } diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index 9b547b82bb..e34db755b7 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -52,7 +52,6 @@ void PreparePrimaryFramebufferMSAAConfig::setResolutionScale(float scale) { const float SCALE_RANGE_MIN = 0.1f; const float SCALE_RANGE_MAX = 2.0f; resolutionScale = std::max(SCALE_RANGE_MIN, std::min(SCALE_RANGE_MAX, scale)); - // emit dirty(); } void PreparePrimaryFramebufferMSAAConfig::setNumSamples(int num) { diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index 647994d3c0..6833e42449 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -42,8 +42,8 @@ public: class PreparePrimaryFramebufferMSAAConfig : public render::Job::Config { Q_OBJECT - Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale NOTIFY dirty()) - Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty()) + Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale NOTIFY dirty) + Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty) public: float getResolutionScale() const { return resolutionScale; } void setResolutionScale(float scale); diff --git a/libraries/task/src/task/Config.h b/libraries/task/src/task/Config.h index 193674d152..8accba9e1f 100644 --- a/libraries/task/src/task/Config.h +++ b/libraries/task/src/task/Config.h @@ -133,8 +133,6 @@ public: */ Q_INVOKABLE void load(const QVariantMap& map) { qObjectFromJsonValue(QJsonObject::fromVariantMap(map), *this); emit loaded(); } - //Q_INVOKABLE QObject* getConfig(const QString& name) { return nullptr; } - // Running Time measurement // The new stats signal is emitted once per run time of a job when stats (cpu runtime) are updated void setCPURunTime(const std::chrono::nanoseconds& runtime) { _msCPURunTime = std::chrono::duration(runtime).count(); emit newStats(); } diff --git a/libraries/task/src/task/Task.h b/libraries/task/src/task/Task.h index 4d346480b6..0ee458f3ea 100644 --- a/libraries/task/src/task/Task.h +++ b/libraries/task/src/task/Task.h @@ -261,7 +261,6 @@ public: _jobs.emplace_back((NT::JobModel::create(name, input, std::forward(args)...))); // Conect the child config to this task's config - // std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); std::static_pointer_cast(Concept::getConfiguration())->connectChildConfig(_jobs.back().getConfiguration(), name); return _jobs.back().getOutput(); diff --git a/scripts/developer/utilities/render/luci2.js b/scripts/developer/utilities/render/luci2.js index ba0215569a..a34cf88415 100644 --- a/scripts/developer/utilities/render/luci2.js +++ b/scripts/developer/utilities/render/luci2.js @@ -69,8 +69,8 @@ function openView() { } pages.addPage('Luci', 'Luci', '../luci.qml', 300, 420, openLuciWindow, closeLuciWindow); - // pages.addPage('openEngineLODView', 'Render LOD', '../lod.qml', 300, 400); - // pages.addPage('openMaterialInspectorView', 'Material Inspector', '../materialInspector.qml', 300, 400, MaterialInspector.setWindow, MaterialInspector.setWindow); + pages.addPage('openEngineLODView', 'Render LOD', '../lod.qml', 300, 400); + pages.addPage('openMaterialInspectorView', 'Material Inspector', '../materialInspector.qml', 300, 400, MaterialInspector.setWindow, MaterialInspector.setWindow); pages.open('Luci'); From 5e57e53db2674e4a2287a45bf5ee017da846b61e Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 14 Aug 2019 11:15:52 -0700 Subject: [PATCH 16/21] Address errors sent from running the ENgine Inspector.js --- .../utilities/lib/jet/qml/TaskPropView.qml | 4 +- .../utilities/lib/prop/PropGroup.qml | 48 ++++++++++--------- .../utilities/lib/prop/style/Global.qml | 6 +-- scripts/developer/utilities/render/luci.qml | 10 ++++ scripts/developer/utilities/render/luci2.js | 1 + 5 files changed, 41 insertions(+), 28 deletions(-) diff --git a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml index 69902392a5..699390c8bf 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml @@ -29,7 +29,7 @@ Prop.PropGroup { property var showProps: true property var showSubs: true - property var jobEnabled: rootConfig.getConfig(jobPath).enabled + property bool jobEnabled: rootConfig.getConfig(jobPath).enabled property var jobCpuTime: pullCpuTime() function pullCpuTime() { @@ -72,7 +72,7 @@ Prop.PropGroup { anchors.right:parent.right anchors.verticalCenter: parent.verticalCenter filled: root.jobEnabled - fillColor: (root.jobEnabled ? root.global.colorGreenHighlight : global.colorOrangeAccent) + fillColor: (root.jobEnabled ? global.colorGreenHighlight : global.colorOrangeAccent) icon: 5 MouseArea{ diff --git a/scripts/developer/utilities/lib/prop/PropGroup.qml b/scripts/developer/utilities/lib/prop/PropGroup.qml index bfae2798eb..a4133ab96c 100644 --- a/scripts/developer/utilities/lib/prop/PropGroup.qml +++ b/scripts/developer/utilities/lib/prop/PropGroup.qml @@ -136,30 +136,32 @@ PropFolderPanel { function populateFromObjectProps(object) { var propsModel = [] - var props = Object.keys(object); - for (var p in props) { - var o = {}; - o["object"] = object - o["property"] = props[p]; - // o["readOnly"] = true; - - var thePropThing = object[props[p]]; - if ((thePropThing !== undefined) && (thePropThing !== null)) { - var theType = typeof(thePropThing) - switch(theType) { - case 'object': { - o["type"] = "object"; - propsModel.push(o) - } break; - default: { - o["type"] = "string"; - propsModel.push(o) - } break; - } + if (object !== undefined) { + var props = Object.keys(object); + for (var p in props) { + var o = {}; + o["object"] = object + o["property"] = props[p]; + // o["readOnly"] = true; - } else { - o["type"] = "string"; - propsModel.push(o) + var thePropThing = object[props[p]]; + if ((thePropThing !== undefined) && (thePropThing !== null)) { + var theType = typeof(thePropThing) + switch(theType) { + case 'object': { + o["type"] = "object"; + propsModel.push(o) + } break; + default: { + o["type"] = "string"; + propsModel.push(o) + } break; + } + + } else { + o["type"] = "string"; + propsModel.push(o) + } } } diff --git a/scripts/developer/utilities/lib/prop/style/Global.qml b/scripts/developer/utilities/lib/prop/style/Global.qml index b8ea41371e..cec56e6126 100644 --- a/scripts/developer/utilities/lib/prop/style/Global.qml +++ b/scripts/developer/utilities/lib/prop/style/Global.qml @@ -31,9 +31,9 @@ Item { readonly property color colorBorderHighight: hifi.colors.blueHighlight readonly property color colorBorderLighter: hifi.colors.faintGray - readonly property color colorOrangeAccent: "#FF6309" - readonly property color colorRedAccent: "#C62147" - readonly property color colorGreenHighlight: "#1ac567" + readonly property color colorOrangeAccent: hifi.colors.orangeAccent + readonly property color colorRedAccent: hifi.colors.redAccent + readonly property color colorGreenHighlight: hifi.colors.greenHighlight readonly property real fontSize: 12 readonly property var fontFamily: "Raleway" diff --git a/scripts/developer/utilities/render/luci.qml b/scripts/developer/utilities/render/luci.qml index 3a61a0394d..d768acb160 100644 --- a/scripts/developer/utilities/render/luci.qml +++ b/scripts/developer/utilities/render/luci.qml @@ -32,6 +32,7 @@ Rectangle { clip: true Column { + id: column width: parent.width Prop.PropFolderPanel { label: "Render Settings" @@ -81,17 +82,26 @@ Rectangle { label: "Tools" panelFrameData: Component { Row { + HifiControls.Button { + text: "Engine" + onClicked: { + sendToScript({method: "openEngineInspectorView"}); + } + width:column.width / 3 + } HifiControls.Button { text: "LOD" onClicked: { sendToScript({method: "openEngineLODView"}); } + width:column.width / 3 } HifiControls.Button { text: "Material" onClicked: { sendToScript({method: "openMaterialInspectorView"}); } + width:column.width / 3 } } } diff --git a/scripts/developer/utilities/render/luci2.js b/scripts/developer/utilities/render/luci2.js index a34cf88415..e2e5523ccd 100644 --- a/scripts/developer/utilities/render/luci2.js +++ b/scripts/developer/utilities/render/luci2.js @@ -69,6 +69,7 @@ function openView() { } pages.addPage('Luci', 'Luci', '../luci.qml', 300, 420, openLuciWindow, closeLuciWindow); + pages.addPage('openEngineInspectorView', 'Render Engine Inspector', '../engineInspector.qml', 300, 400); pages.addPage('openEngineLODView', 'Render LOD', '../lod.qml', 300, 400); pages.addPage('openMaterialInspectorView', 'Material Inspector', '../materialInspector.qml', 300, 400, MaterialInspector.setWindow, MaterialInspector.setWindow); From f4c33d8392f2a1a56b6294b3808266a429aaf052 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 14 Aug 2019 11:33:30 -0700 Subject: [PATCH 17/21] Refining the look of the enable button of the TaskPropView --- scripts/developer/utilities/lib/jet/qml/TaskPropView.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml index 699390c8bf..6a658a33e3 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml @@ -71,8 +71,8 @@ Prop.PropGroup { id: enabledIcon anchors.right:parent.right anchors.verticalCenter: parent.verticalCenter - filled: root.jobEnabled - fillColor: (root.jobEnabled ? global.colorGreenHighlight : global.colorOrangeAccent) + filled: true + fillColor: (root.jobEnabled ? global.colorGreenHighlight : global.colorRedAccent) icon: 5 MouseArea{ From a5e2cacb98c73022fa7289330f47b5cd5a009859 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 14 Aug 2019 11:45:27 -0700 Subject: [PATCH 18/21] Apply the new tiering rule for macos: if intel gpu go low, else stick to mid --- libraries/platform/src/platform/Profiler.cpp | 53 ++++++++------------ 1 file changed, 20 insertions(+), 33 deletions(-) diff --git a/libraries/platform/src/platform/Profiler.cpp b/libraries/platform/src/platform/Profiler.cpp index 622a18a6b2..0062041658 100644 --- a/libraries/platform/src/platform/Profiler.cpp +++ b/libraries/platform/src/platform/Profiler.cpp @@ -58,21 +58,32 @@ bool filterOnComputer(const platform::json& computer, Profiler::Tier& tier) { // tier filter on computer MACOS bool filterOnComputerMACOS(const platform::json& computer, Profiler::Tier& tier) { - // it s a macos computer, probably can tell from the model name: - if (computer.count(keys::computer::model)) { - const auto model = computer[keys::computer::model].get(); - if (model.find("MacBookAir") != std::string::npos) { + // it s a macos computer, probably can tell from the model name but... + // The simple rule for mac is + // if it s an intel gpu then LOW + // else go mid + auto gpu = platform::getGPU(platform::getMasterGPU()); + if (gpu.count(keys::gpu::vendor)) { + std::string gpuVendor = gpu[keys::gpu::vendor].get(); + std::string gpuModel = gpu[keys::gpu::model].get(); + + // intel integrated graphics + if (gpuVendor.find(keys::gpu::vendor_Intel) != std::string::npos) { + // go LOW because Intel GPU tier = Profiler::Tier::LOW; return true; - } else if (model.find("MacBookPro") != std::string::npos) { + } else { + // else go mid tier = Profiler::Tier::MID; return true; - } else if (model.find("MacBook") != std::string::npos) { - tier = Profiler::Tier::LOW; - return true; } + } else { + // no gpuinfo ? + // Go low in doubt + // go LOW because Intel GPU + tier = Profiler::Tier::LOW; + return true; } - return false; } bool filterOnProcessors(const platform::json& computer, const platform::json& cpu, const platform::json& gpu, Profiler::Tier& tier) { @@ -133,30 +144,6 @@ bool filterOnProcessors(const platform::json& computer, const platform::json& cp // YES on macos EXCEPT for macbookair with gpu intel iris or intel HD 6000 bool Profiler::isRenderMethodDeferredCapable() { #if defined(Q_OS_MAC) - // Deferred works correctly on every supported macos platform at the moment, let s enable it -/* - auto computer = platform::getComputer(); - const auto computerModel = (computer.count(keys::computer::model) ? computer[keys::computer::model].get() : ""); - - auto gpuInfo = platform::getGPU(getMasterGPU()); - const auto gpuModel = (gpuInfo.count(keys::gpu::model) ? gpuInfo[keys::gpu::model].get() : ""); - - - // Macbook air 2018 are a problem - if ((computerModel.find("MacBookAir7,2") != std::string::npos) && (gpuModel.find("Intel HD Graphics 6000") != std::string::npos)) { - return false; - } - - // We know for fact that the Mac BOok Pro 13 from Mid 2014 INtel Iris is problematic, - if ((computerModel.find("MacBookPro11,1") != std::string::npos) && (gpuModel.find("Intel Iris") != std::string::npos)) { - return false; - } - - // TO avoid issues for the next few days, we are excluding all of intel chipset... - if ((gpuModel.find("Intel ") != std::string::npos)) { - return false; - } -*/ return true; #elif defined(Q_OS_ANDROID) return false; From eb24667218c9310b591f199854947711ecc9820e Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Wed, 14 Aug 2019 11:54:39 -0700 Subject: [PATCH 19/21] Remove useless variable --- libraries/platform/src/platform/Profiler.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/platform/src/platform/Profiler.cpp b/libraries/platform/src/platform/Profiler.cpp index 0062041658..d805fd8ebc 100644 --- a/libraries/platform/src/platform/Profiler.cpp +++ b/libraries/platform/src/platform/Profiler.cpp @@ -65,7 +65,6 @@ bool filterOnComputerMACOS(const platform::json& computer, Profiler::Tier& tier) auto gpu = platform::getGPU(platform::getMasterGPU()); if (gpu.count(keys::gpu::vendor)) { std::string gpuVendor = gpu[keys::gpu::vendor].get(); - std::string gpuModel = gpu[keys::gpu::model].get(); // intel integrated graphics if (gpuVendor.find(keys::gpu::vendor_Intel) != std::string::npos) { From 9aacd136b88fd41f0bf872a882a6db440a088ca2 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Wed, 14 Aug 2019 13:51:40 -0700 Subject: [PATCH 20/21] Add blocking to script unload for client entity-scripts --- interface/src/Application.cpp | 1 - libraries/entities-renderer/src/EntityTreeRenderer.cpp | 2 +- libraries/script-engine/src/ScriptEngine.cpp | 5 +++-- libraries/script-engine/src/ScriptEngine.h | 3 ++- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 481975caac..0df377a4f2 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2761,7 +2761,6 @@ void Application::cleanupBeforeQuit() { } getEntities()->shutdown(); // tell the entities system we're shutting down, so it will stop running scripts - getEntities()->clear(); // Clear any queued processing (I/O, FBX/OBJ/Texture parsing) QThreadPool::globalInstance()->clear(); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 305384361d..fd82567a94 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -253,7 +253,7 @@ void EntityTreeRenderer::clear() { // unload and stop the engine if (_entitiesScriptEngine) { // do this here (instead of in deleter) to avoid marshalling unload signals back to this thread - _entitiesScriptEngine->unloadAllEntityScripts(); + _entitiesScriptEngine->unloadAllEntityScripts(true); _entitiesScriptEngine->stop(); } diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 5e20f06a7f..6808da2e1a 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -2470,13 +2470,14 @@ QList ScriptEngine::getListOfEntityScriptIDs() { return _entityScripts.keys(); } -void ScriptEngine::unloadAllEntityScripts() { +void ScriptEngine::unloadAllEntityScripts(bool blockingCall) { if (QThread::currentThread() != thread()) { #ifdef THREAD_DEBUGGING qCDebug(scriptengine) << "*** WARNING *** ScriptEngine::unloadAllEntityScripts() called on wrong thread [" << QThread::currentThread() << "], invoking on correct thread [" << thread() << "]"; #endif - QMetaObject::invokeMethod(this, "unloadAllEntityScripts"); + QMetaObject::invokeMethod(this, "unloadAllEntityScripts", + blockingCall ? Qt::BlockingQueuedConnection : Qt::QueuedConnection); return; } #ifdef THREAD_DEBUGGING diff --git a/libraries/script-engine/src/ScriptEngine.h b/libraries/script-engine/src/ScriptEngine.h index 52ece63dc2..d738b13ecc 100644 --- a/libraries/script-engine/src/ScriptEngine.h +++ b/libraries/script-engine/src/ScriptEngine.h @@ -578,9 +578,10 @@ public: /**jsdoc * @function Script.unloadAllEntityScripts + * @param {boolean} [blockingCall=false] - Wait for completion if call moved to another thread. * @deprecated This function is deprecated and will be removed. */ - Q_INVOKABLE void unloadAllEntityScripts(); + Q_INVOKABLE void unloadAllEntityScripts(bool blockingCall = false); /**jsdoc * Calls a method in an entity script. From 5be1cfcb364938b028d9829a0ee88d4f37953e5b Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 15 Aug 2019 13:07:43 -0700 Subject: [PATCH 21/21] Fix linux specific script engine crash --- scripts/modules/request.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/modules/request.js b/scripts/modules/request.js index 48c9913bd6..7e942a47f7 100644 --- a/scripts/modules/request.js +++ b/scripts/modules/request.js @@ -40,10 +40,10 @@ module.exports = { response = { statusCode: httpRequest.status }; } + callback(error, response, optionalCallbackParameter); + // Break circular reference to httpRequest so the engine can garbage collect it. httpRequest.onreadystatechange = null; - - callback(error, response, optionalCallbackParameter); } }; if (typeof options === 'string') {