From d8380923f0c54cd07b89dc266dfc50431536234c Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 14 Jun 2017 18:06:42 -0700 Subject: [PATCH 01/39] Introducing the SCeneUpdtate job to the engine to take care of performing transactions and introducing the stages --- interface/src/Application.cpp | 3 -- libraries/render/src/render/Engine.cpp | 3 ++ libraries/render/src/render/Scene.h | 6 +++- libraries/render/src/render/SceneTask.cpp | 21 ++++++++++++ libraries/render/src/render/SceneTask.h | 41 +++++++++++++++++++++++ libraries/render/src/render/Stage.cpp | 26 ++++++++++++++ libraries/render/src/render/Stage.h | 38 +++++++++++++++++++++ 7 files changed, 134 insertions(+), 4 deletions(-) create mode 100644 libraries/render/src/render/SceneTask.cpp create mode 100644 libraries/render/src/render/SceneTask.h create mode 100644 libraries/render/src/render/Stage.cpp create mode 100644 libraries/render/src/render/Stage.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 9ce6cc9b25..cd3875521a 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5140,10 +5140,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se } { - PerformanceTimer perfTimer("SceneProcessTransaction"); _main3DScene->enqueueTransaction(transaction); - - _main3DScene->processTransactionQueue(); } // For now every frame pass the renderContext diff --git a/libraries/render/src/render/Engine.cpp b/libraries/render/src/render/Engine.cpp index b3372a9305..19fececa4b 100644 --- a/libraries/render/src/render/Engine.cpp +++ b/libraries/render/src/render/Engine.cpp @@ -18,6 +18,8 @@ #include #include "EngineStats.h" +#include "SceneTask.h" + #include "Logging.h" using namespace render; @@ -31,6 +33,7 @@ public: void build(JobModel& task, const Varying& in, Varying& out) { task.addJob("Stats"); + task.addJob("PerformSceneTransaction"); } }; diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index fc0a8c1fca..48d09a9d52 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -128,7 +128,6 @@ protected: void removeItems(const ItemIDs& ids); void updateItems(const ItemIDs& ids, UpdateFunctors& functors); - // The Selection map mutable std::mutex _selectionsMutex; // mutable so it can be used in the thread safe getSelection const method SelectionMap _selections; @@ -139,6 +138,11 @@ protected: // void appendToSelection(const Selection& selection); // void mergeWithSelection(const Selection& selection); + // The Stages + StageMap _stages; + + + friend class Engine; }; diff --git a/libraries/render/src/render/SceneTask.cpp b/libraries/render/src/render/SceneTask.cpp new file mode 100644 index 0000000000..56010f246e --- /dev/null +++ b/libraries/render/src/render/SceneTask.cpp @@ -0,0 +1,21 @@ +// +// SceneTask.cpp +// render/src/render +// +// Created by Sam Gateau on 6/14/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "SceneTask.h" + + +using namespace render; + +void PerformSceneTransaction::configure(const Config& config) { +} + +void PerformSceneTransaction::run(const RenderContextPointer& renderContext) { + renderContext->_scene->processTransactionQueue(); +} diff --git a/libraries/render/src/render/SceneTask.h b/libraries/render/src/render/SceneTask.h new file mode 100644 index 0000000000..0cf2dda395 --- /dev/null +++ b/libraries/render/src/render/SceneTask.h @@ -0,0 +1,41 @@ +// +// SceneTask.h +// render/src/render +// +// Created by Sam Gateau on 6/14/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_render_SceneTask_h +#define hifi_render_SceneTask_h + +#include "Engine.h" + +namespace render { + + class PerformSceneTransactionConfig : public Job::Config { + Q_OBJECT + public: + signals: + void dirty(); + + protected: + }; + + class PerformSceneTransaction { + public: + using Config = PerformSceneTransactionConfig; + using JobModel = Job::Model; + + void configure(const Config& config); + void run(const RenderContextPointer& renderContext); + protected: + }; + + +} + +#endif // hifi_render_SceneTask_h diff --git a/libraries/render/src/render/Stage.cpp b/libraries/render/src/render/Stage.cpp new file mode 100644 index 0000000000..1ee9b1d6ff --- /dev/null +++ b/libraries/render/src/render/Stage.cpp @@ -0,0 +1,26 @@ +// +// Stage.cpp +// render/src/render +// +// Created by Sam Gateau on 6/14/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "Stage.h" + + +using namespace render; + + + +Stage::~Stage() { + +} + +Stage::Stage() : + _name() +{ +} + diff --git a/libraries/render/src/render/Stage.h b/libraries/render/src/render/Stage.h new file mode 100644 index 0000000000..5145810671 --- /dev/null +++ b/libraries/render/src/render/Stage.h @@ -0,0 +1,38 @@ +// +// Stage.h +// render/src/render +// +// Created by Sam Gateau on 6/14/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_render_Stage_h +#define hifi_render_Stage_h + +#include +#include +#include + +namespace render { + + class Stage { + public: + using Name = std::string; + + Stage(); + virtual ~Stage(); + + protected: + Name _name; + }; + + using StagePointer = std::shared_ptr; + + using StageMap = std::map; + +} + +#endif // hifi_render_Stage_h From df340a5b55fad72e7c504967a8b41b2e81dbde8b Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Wed, 14 Jun 2017 22:39:47 -0700 Subject: [PATCH 02/39] COmpiling --- libraries/render/src/render/Scene.h | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 48d09a9d52..6c536be34a 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -14,6 +14,7 @@ #include "Item.h" #include "SpatialTree.h" +#include "Stage.h" #include "Selection.h" namespace render { From 9ae2861ee6c020e86b56237cb86c44586fbdad44 Mon Sep 17 00:00:00 2001 From: samcake Date: Wed, 21 Jun 2017 18:29:38 -0700 Subject: [PATCH 03/39] Moving the stage objects under the scene umbrella and creating a cear task to update the scene elements --- interface/src/Application.cpp | 6 ++-- .../render-utils/src/BackgroundStage.cpp | 13 +++++++- libraries/render-utils/src/BackgroundStage.h | 12 +++++++- libraries/render-utils/src/LightStage.cpp | 10 +++++++ libraries/render-utils/src/LightStage.h | 23 ++++++++++---- .../render-utils/src/UpdateSceneTask.cpp | 24 +++++++++++++++ libraries/render-utils/src/UpdateSceneTask.h | 30 +++++++++++++++++++ libraries/render/src/render/Engine.cpp | 1 - libraries/render/src/render/Scene.cpp | 23 ++++++++++++++ libraries/render/src/render/Scene.h | 12 ++++++-- 10 files changed, 140 insertions(+), 14 deletions(-) create mode 100644 libraries/render-utils/src/UpdateSceneTask.cpp create mode 100644 libraries/render-utils/src/UpdateSceneTask.h diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c5ba7be12b..d44ca58a89 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -111,10 +111,7 @@ #include #include #include -#include -#include -#include -#include +#include #include #include #include @@ -1902,6 +1899,7 @@ void Application::initializeGL() { render::CullFunctor cullFunctor = LODManager::shouldRender; static const QString RENDER_FORWARD = "HIFI_RENDER_FORWARD"; bool isDeferred = !QProcessEnvironment::systemEnvironment().contains(RENDER_FORWARD); + _renderEngine->addJob("UpdateScene"); _renderEngine->addJob("SecondaryCameraFrame", cullFunctor); _renderEngine->addJob("RenderMainView", cullFunctor, isDeferred); _renderEngine->load(); diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 5c2f55954a..1d1aa877e4 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -137,4 +137,15 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, } */ -} \ No newline at end of file +} + +BackgroundStageSetup::BackgroundStageSetup() { +} + +void BackgroundStageSetup::run(const render::RenderContextPointer& renderContext) { + auto stage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + if (!stage) { + renderContext->_scene->resetStage("BACKGROUND_STAGE", std::make_shared()); + } +} + diff --git a/libraries/render-utils/src/BackgroundStage.h b/libraries/render-utils/src/BackgroundStage.h index 1dd1651c98..2f0231b071 100644 --- a/libraries/render-utils/src/BackgroundStage.h +++ b/libraries/render-utils/src/BackgroundStage.h @@ -15,12 +15,13 @@ #include #include #include +#include #include "LightingModel.h" // Background stage to set up background-related rendering tasks -class BackgroundStage { +class BackgroundStage : public render::Stage { public: using Index = render::indexed_container::Index; static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX }; @@ -66,6 +67,15 @@ public: }; using BackgroundStagePointer = std::shared_ptr; +class BackgroundStageSetup { +public: + using JobModel = render::Job::Model; + + BackgroundStageSetup(); + void run(const render::RenderContextPointer& renderContext); + +protected: +}; class DrawBackgroundStage { public: diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index dd6a046dea..14abc746d4 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -165,3 +165,13 @@ void LightStage::updateLightArrayBuffer(Index lightId) { } } +LightStageSetup::LightStageSetup() { +} + +void LightStageSetup::run(const render::RenderContextPointer& renderContext) { + auto stage = renderContext->_scene->getStage("LIGHT_STAGE"); + if (!stage) { + renderContext->_scene->resetStage("LIGHT_STAGE", std::make_shared()); + } +} + diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index edbdff28fd..90501056e4 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -14,16 +14,19 @@ #include #include + +#include + +#include + #include - -#include "gpu/Framebuffer.h" - -#include "model/Light.h" +#include +#include class ViewFrustum; // Light stage to set up light-related rendering tasks -class LightStage { +class LightStage : public render::Stage { public: using Index = render::indexed_container::Index; static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX }; @@ -149,5 +152,15 @@ using LightStagePointer = std::shared_ptr; +class LightStageSetup { +public: + using JobModel = render::Job::Model; + + LightStageSetup(); + void run(const render::RenderContextPointer& renderContext); + +protected: +}; + #endif diff --git a/libraries/render-utils/src/UpdateSceneTask.cpp b/libraries/render-utils/src/UpdateSceneTask.cpp new file mode 100644 index 0000000000..4fd46b215f --- /dev/null +++ b/libraries/render-utils/src/UpdateSceneTask.cpp @@ -0,0 +1,24 @@ +// +// UpdateSceneTask.cpp +// render-utils/src/ +// +// Created by Sam Gateau on 6/21/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#include "UpdateSceneTask.h" + +#include +#include "LightStage.h" +#include "BackgroundStage.h" + +void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { + + task.addJob("PerformSceneTransaction"); + + task.addJob("LightStageSetup"); + +} + diff --git a/libraries/render-utils/src/UpdateSceneTask.h b/libraries/render-utils/src/UpdateSceneTask.h new file mode 100644 index 0000000000..227ede8ea3 --- /dev/null +++ b/libraries/render-utils/src/UpdateSceneTask.h @@ -0,0 +1,30 @@ +// +// UpdateSceneTask.h +// render-utils/src/ +// +// Created by Sam Gateau on 6/21/2017. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +#pragma once +#ifndef hifi_UpdateSceneTask_h +#define hifi_UpdateSceneTask_h + +#include +#include + + +class UpdateSceneTask { +public: + using JobModel = render::Task::Model; + + UpdateSceneTask() {} + + void build(JobModel& task, const render::Varying& inputs, render::Varying& outputs); + +}; + + +#endif // hifi_UpdateSceneTask_h diff --git a/libraries/render/src/render/Engine.cpp b/libraries/render/src/render/Engine.cpp index 19fececa4b..5f67d40d17 100644 --- a/libraries/render/src/render/Engine.cpp +++ b/libraries/render/src/render/Engine.cpp @@ -33,7 +33,6 @@ public: void build(JobModel& task, const Varying& in, Varying& out) { task.addJob("Stats"); - task.addJob("PerformSceneTransaction"); } }; diff --git a/libraries/render/src/render/Scene.cpp b/libraries/render/src/render/Scene.cpp index 0e77b389a0..b8f93c52c3 100644 --- a/libraries/render/src/render/Scene.cpp +++ b/libraries/render/src/render/Scene.cpp @@ -237,3 +237,26 @@ void Scene::resetSelections(const Selections& selections) { } } } + +// Access a particular Stage (empty if doesn't exist) +// Thread safe +StagePointer Scene::getStage(const Stage::Name& name) const { + std::unique_lock lock(_stagesMutex); + auto found = _stages.find(name); + if (found == _stages.end()) { + return StagePointer(); + } else { + return (*found).second; + } + +} + +void Scene::resetStage(const Stage::Name& name, const StagePointer& stage) { + std::unique_lock lock(_stagesMutex); + auto found = _stages.find(name); + if (found == _stages.end()) { + _stages.insert(StageMap::value_type(name, stage)); + } else { + (*found).second = stage; + } +} \ No newline at end of file diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 6c536be34a..09f6140618 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -111,6 +111,14 @@ public: // Access non-spatialized items (overlays, backgrounds) const ItemIDSet& getNonspatialSet() const { return _masterNonspatialSet; } + + + // Access a particular Stage (empty if doesn't exist) + // Thread safe + StagePointer getStage(const Stage::Name& name) const; + void resetStage(const Stage::Name& name, const StagePointer& stage); + + protected: // Thread safe elements that can be accessed from anywhere std::atomic _IDAllocator{ 1 }; // first valid itemID will be One @@ -139,11 +147,11 @@ protected: // void appendToSelection(const Selection& selection); // void mergeWithSelection(const Selection& selection); - // The Stages + // The Stage map + mutable std::mutex _stagesMutex; // mutable so it can be used in the thread safe getStage const method StageMap _stages; - friend class Engine; }; From 07e18eb3a8a29efee23015e3ba83a5ca6622e19c Mon Sep 17 00:00:00 2001 From: Sam Cake Date: Thu, 22 Jun 2017 01:12:32 -0700 Subject: [PATCH 04/39] Keep cleaning up the DeferredLightingEffect , removing stage s from there... --- .../src/RenderableZoneEntityItem.cpp | 6 +- .../render-utils/src/BackgroundStage.cpp | 5 +- .../render-utils/src/DebugDeferredBuffer.cpp | 9 ++- .../src/DeferredLightingEffect.cpp | 71 ++++++++++++++++--- .../render-utils/src/DeferredLightingEffect.h | 41 +++++++---- libraries/render-utils/src/LightClusters.cpp | 5 +- libraries/render-utils/src/LightPayload.cpp | 6 +- libraries/render-utils/src/LightStage.cpp | 6 +- libraries/render-utils/src/LightStage.h | 2 + .../render-utils/src/RenderShadowTask.cpp | 6 +- .../render-utils/src/SubsurfaceScattering.cpp | 7 +- .../render-utils/src/UpdateSceneTask.cpp | 2 + libraries/render-utils/src/ZoneRenderer.cpp | 17 +++-- libraries/render/src/render/Scene.h | 5 ++ 14 files changed, 142 insertions(+), 46 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index 2d4dd50e88..da0aef75aa 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -554,11 +554,13 @@ void RenderableZoneEntityItemMeta::setProceduralUserData(QString userData) { void RenderableZoneEntityItemMeta::render(RenderArgs* args) { if (!_stage) { - _stage = DependencyManager::get()->getLightStage(); + // _stage = DependencyManager::get()->getLightStage(); + _stage = args->_scene->getStage("LIGHT_STAGE"); } if (!_backgroundStage) { - _backgroundStage = DependencyManager::get()->getBackgroundStage(); + //_backgroundStage = DependencyManager::get()->getBackgroundStage(); + _backgroundStage = args->_scene->getStage("BACKGROUND_STAGE"); } { // Sun diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 1d1aa877e4..b980887471 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -60,7 +60,8 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, // Background rendering decision - auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); model::SunSkyStagePointer background; model::SkyboxPointer skybox; if (backgroundStage->_currentFrame._backgrounds.size()) { @@ -70,7 +71,7 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, skybox = background->getSkybox(); } } else { - skybox = DependencyManager::get()->getDefaultSkybox(); + // skybox = DependencyManager::get()->getDefaultSkybox(); } /* auto backgroundMode = skyStage->getBackgroundMode(); diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 3359b3a12d..e83789252c 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -432,9 +432,12 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I batch.setResourceTexture(Lighting, deferredFramebuffer->getLightingTexture()); } - auto deferredLightingEffect = DependencyManager::get(); - assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); - auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); + // auto deferredLightingEffect = DependencyManager::get(); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + // assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); + assert(lightStage->getNumLights() > 0); + // auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); + auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; if (globalShadow) { batch.setResourceTexture(Shadow, globalShadow->map); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 0b4eee125b..374487a79d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -101,7 +101,7 @@ void DeferredLightingEffect::init() { loadLightProgram(deferred_light_vert, local_lights_drawOutline_frag, true, _localLightOutline, _localLightOutlineLocations); // Light Stage and clusters - _lightStage = std::make_shared(); + /* _lightStage = std::make_shared(); // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light _allocatedLights.push_back(std::make_shared()); @@ -140,7 +140,7 @@ void DeferredLightingEffect::init() { auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); if (irradianceSH) { lp->setAmbientSphere((*irradianceSH)); - } + }*/ } void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { @@ -275,11 +275,11 @@ void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) { globalLight->setAmbientSphere(light->getAmbientSphere()); globalLight->setAmbientMap(light->getAmbientMap());*/ } - +/* const model::LightPointer& DeferredLightingEffect::getGlobalLight() const { return _allocatedLights.front(); } - +*/ #include @@ -483,8 +483,10 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input // Prepare a fresh Light Frame - auto deferredLightingEffect = DependencyManager::get(); - deferredLightingEffect->getLightStage()->_currentFrame.clear(); + //auto deferredLightingEffect = DependencyManager::get(); + //deferredLightingEffect->getLightStage()->_currentFrame.clear(); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + lightStage->_currentFrame.clear(); } @@ -547,8 +549,11 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Global directional light and ambient pass - assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); - auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + // assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); + assert(lightStage->getNumLights() > 0); + // auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); + auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; // Bind the shadow buffer @@ -749,3 +754,53 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs auto config = std::static_pointer_cast(renderContext->jobConfig); config->setGPUBatchRunTime(_gpuTimer->getGPUAverage(), _gpuTimer->getBatchAverage()); } + + + +void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { + + if (!_defaultLight) { + if (!_defaultSkyboxTexture) { + auto textureCache = DependencyManager::get(); + { + PROFILE_RANGE(render, "Process Default Skybox"); + auto textureCache = DependencyManager::get(); + + auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx"; + + _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl); + _defaultSkyboxAmbientTexture = _defaultSkyboxTexture; + + _defaultSkybox->setCubemap(_defaultSkyboxTexture); + } + } + + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + if (lightStage) { + + // Allocate a default global light directional and ambient + model::LightPointer lp = std::make_shared(); + lp->setType(model::Light::SUN); + lp->setDirection(glm::vec3(-1.0f)); + lp->setColor(glm::vec3(1.0f)); + lp->setIntensity(1.0f); + lp->setType(model::Light::SUN); + lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); + + lp->setAmbientIntensity(0.5f); + lp->setAmbientMap(_defaultSkyboxAmbientTexture); + auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); + if (irradianceSH) { + lp->setAmbientSphere((*irradianceSH)); + } + + // capture default light + _defaultLight = lp; + + // Add the global light to the light stage (for later shadow rendering) + auto defaultLightID = lightStage->addLight(lp); + lightStage->addShadow(defaultLightID); + } + } +} + diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index d69c72e97d..0e1b365149 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -51,25 +51,25 @@ public: void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); // update global lighting - void setGlobalLight(const model::LightPointer& light); - const model::LightPointer& getGlobalLight() const; + // void setGlobalLight(const model::LightPointer& light); + // const model::LightPointer& getGlobalLight() const; - const LightStagePointer& getLightStage() { return _lightStage; } - const BackgroundStagePointer& getBackgroundStage() { return _backgroundStage; } + // const LightStagePointer& getLightStage() { return _lightStage; } + // const BackgroundStagePointer& getBackgroundStage() { return _backgroundStage; } void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; } bool isAmbientOcclusionEnabled() const { return _ambientOcclusionEnabled; } - model::SkyboxPointer getDefaultSkybox() const { return _defaultSkybox; } - gpu::TexturePointer getDefaultSkyboxTexture() const { return _defaultSkyboxTexture; } - gpu::TexturePointer getDefaultSkyboxAmbientTexture() const { return _defaultSkyboxAmbientTexture; } + // model::SkyboxPointer getDefaultSkybox() const { return _defaultSkybox; } + // gpu::TexturePointer getDefaultSkyboxTexture() const { return _defaultSkyboxTexture; } + // gpu::TexturePointer getDefaultSkyboxAmbientTexture() const { return _defaultSkyboxAmbientTexture; } private: DeferredLightingEffect() = default; - LightStagePointer _lightStage; - BackgroundStagePointer _backgroundStage; + // LightStagePointer _lightStage; + // BackgroundStagePointer _backgroundStage; bool _shadowMapEnabled{ false }; bool _ambientOcclusionEnabled{ false }; @@ -97,14 +97,14 @@ private: LightLocationsPtr _localLightLocations; LightLocationsPtr _localLightOutlineLocations; - using Lights = std::vector; + // using Lights = std::vector; - Lights _allocatedLights; - std::vector _globalLights; + // Lights _allocatedLights; + // std::vector _globalLights; - model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; - gpu::TexturePointer _defaultSkyboxTexture; - gpu::TexturePointer _defaultSkyboxAmbientTexture; + // model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; + // gpu::TexturePointer _defaultSkyboxTexture; + // gpu::TexturePointer _defaultSkyboxAmbientTexture; friend class LightClusteringPass; friend class RenderDeferredSetup; @@ -195,6 +195,17 @@ protected: gpu::RangeTimerPointer _gpuTimer; }; +class DefaultLightingSetup { +public: + using JobModel = render::Job::Model; + void run(const render::RenderContextPointer& renderContext); + +protected: + model::LightPointer _defaultLight; + model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; + gpu::TexturePointer _defaultSkyboxTexture; + gpu::TexturePointer _defaultSkyboxAmbientTexture; +}; #endif // hifi_DeferredLightingEffect_h diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index e35120eb5b..79b755f310 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -574,8 +574,9 @@ void LightClusteringPass::run(const render::RenderContextPointer& renderContext, } // From the LightStage and the current frame, update the light cluster Grid - auto deferredLightingEffect = DependencyManager::get(); - auto lightStage = deferredLightingEffect->getLightStage(); + // auto deferredLightingEffect = DependencyManager::get(); + // auto lightStage = deferredLightingEffect->getLightStage(); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); _lightClusters->updateLightStage(lightStage); _lightClusters->updateLightFrame(lightStage->_currentFrame, lightingModel->isPointLightEnabled(), lightingModel->isSpotLightEnabled()); diff --git a/libraries/render-utils/src/LightPayload.cpp b/libraries/render-utils/src/LightPayload.cpp index dbdf7129ef..d0cc8dfd18 100644 --- a/libraries/render-utils/src/LightPayload.cpp +++ b/libraries/render-utils/src/LightPayload.cpp @@ -55,7 +55,8 @@ LightPayload::~LightPayload() { void LightPayload::render(RenderArgs* args) { if (!_stage) { - _stage = DependencyManager::get()->getLightStage(); + // _stage = DependencyManager::get()->getLightStage(); + _stage = args->_scene->getStage("LIGHT_STAGE"); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { @@ -123,7 +124,8 @@ KeyLightPayload::~KeyLightPayload() { void KeyLightPayload::render(RenderArgs* args) { if (!_stage) { - _stage = DependencyManager::get()->getLightStage(); + // _stage = DependencyManager::get()->getLightStage(); + _stage = args->_scene->getStage("LIGHT_STAGE"); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 14abc746d4..10c99bf008 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -13,6 +13,9 @@ #include "LightStage.h" +LightStage::LightStage() { +} + LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum{ std::make_shared() } { framebuffer = gpu::FramebufferPointer(gpu::Framebuffer::createShadowmap(MAP_SIZE)); map = framebuffer->getDepthStencilBuffer(); @@ -171,7 +174,8 @@ LightStageSetup::LightStageSetup() { void LightStageSetup::run(const render::RenderContextPointer& renderContext) { auto stage = renderContext->_scene->getStage("LIGHT_STAGE"); if (!stage) { - renderContext->_scene->resetStage("LIGHT_STAGE", std::make_shared()); + stage = std::make_shared(); + renderContext->_scene->resetStage("LIGHT_STAGE", stage); } } diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 90501056e4..8273118f0c 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -96,6 +96,7 @@ public: LightPointer getLight(Index lightId) const { return _lights.get(lightId); } + Index getShadowId(Index lightId) const { if (checkLightId(lightId)) { return _descs[lightId].shadowId; @@ -112,6 +113,7 @@ public: return LightAndShadow(getLight(lightId), getShadow(lightId)); } + LightStage(); Lights _lights; LightMap _lightMap; Descs _descs; diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index ddb64bc69e..2d8f6c0cab 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -35,7 +35,8 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); - auto lightStage = DependencyManager::get()->getLightStage(); + // auto lightStage = DependencyManager::get()->getLightStage(); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); LightStage::Index globalLightIndex { 0 }; @@ -140,7 +141,8 @@ void RenderShadowTask::configure(const Config& configuration) { } void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, Output& output) { - auto lightStage = DependencyManager::get()->getLightStage(); + // auto lightStage = DependencyManager::get()->getLightStage(); + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); const auto globalShadow = lightStage->getShadow(0); // Cache old render args diff --git a/libraries/render-utils/src/SubsurfaceScattering.cpp b/libraries/render-utils/src/SubsurfaceScattering.cpp index 40b3c85675..d67369774c 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.cpp +++ b/libraries/render-utils/src/SubsurfaceScattering.cpp @@ -532,9 +532,10 @@ void DebugSubsurfaceScattering::run(const render::RenderContextPointer& renderCo - - const auto light = DependencyManager::get()->getLightStage()->getLight(0); - + auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + // const auto light = DependencyManager::get()->getLightStage()->getLight(0); + const auto light = lightStage->getLight(0); + gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { batch.enableStereo(false); diff --git a/libraries/render-utils/src/UpdateSceneTask.cpp b/libraries/render-utils/src/UpdateSceneTask.cpp index 4fd46b215f..1a9beb4bed 100644 --- a/libraries/render-utils/src/UpdateSceneTask.cpp +++ b/libraries/render-utils/src/UpdateSceneTask.cpp @@ -13,6 +13,7 @@ #include #include "LightStage.h" #include "BackgroundStage.h" +#include "DeferredLightingEffect.h" void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { @@ -20,5 +21,6 @@ void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render task.addJob("LightStageSetup"); + task.addJob("DefaultLightingSetup"); } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 8f04265226..e20e7d9ed8 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -53,7 +53,8 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& oupu void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) { - auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); backgroundStage->_currentFrame.clear(); // call render in the correct order first... @@ -130,14 +131,16 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I auto deferredTransform = inputs; - auto lightStage = DependencyManager::get()->getLightStage(); + // auto lightStage = DependencyManager::get()->getLightStage(); + auto lightStage = context->_scene->getStage("LIGHT_STAGE"); std::vector keyLightStack; if (lightStage && lightStage->_currentFrame._sunLights.size()) { for (auto index : lightStage->_currentFrame._sunLights) { keyLightStack.push_back(lightStage->getLight(index)); } } - keyLightStack.push_back(DependencyManager::get()->getGlobalLight()); + // keyLightStack.push_back(DependencyManager::get()->getGlobalLight()); + keyLightStack.push_back(lightStage->getLight(0)); std::vector ambientLightStack; if (lightStage && lightStage->_currentFrame._ambientLights.size()) { @@ -145,10 +148,12 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I ambientLightStack.push_back(lightStage->getLight(index)); } } - ambientLightStack.push_back(DependencyManager::get()->getGlobalLight()); + // ambientLightStack.push_back(DependencyManager::get()->getGlobalLight()); + ambientLightStack.push_back(lightStage->getLight(0)); - auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); + auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); std::vector skyboxStack; if (backgroundStage && backgroundStage->_currentFrame._backgrounds.size()) { for (auto index : backgroundStage->_currentFrame._backgrounds) { @@ -158,7 +163,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I } } } - skyboxStack.push_back(DependencyManager::get()->getDefaultSkybox()); + // skyboxStack.push_back(DependencyManager::get()->getDefaultSkybox()); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 09f6140618..f0c5e7a3f0 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -116,6 +116,11 @@ public: // Access a particular Stage (empty if doesn't exist) // Thread safe StagePointer getStage(const Stage::Name& name) const; + template + std::shared_ptr getStage(const Stage::Name& name) const { + auto stage = getStage(name); + return (stage ? std::static_pointer_cast(stage) : std::shared_ptr()); + } void resetStage(const Stage::Name& name, const StagePointer& stage); From 20d8c11e28f84c2d2df66d81bd7ac6abe4b94e6d Mon Sep 17 00:00:00 2001 From: samcake Date: Thu, 22 Jun 2017 17:54:16 -0700 Subject: [PATCH 05/39] ALmost there, getting eback everything to work with the light and background stages in the scene, not in deferredLighting Effect anymore --- interface/src/Application.cpp | 2 +- interface/src/Util.cpp | 14 +-- interface/src/Util.h | 3 +- interface/src/ui/overlays/Cube3DOverlay.cpp | 4 +- interface/src/ui/overlays/Shape3DOverlay.cpp | 4 +- interface/src/ui/overlays/Sphere3DOverlay.cpp | 4 +- interface/src/ui/overlays/Text3DOverlay.cpp | 2 +- .../src/avatars-renderer/Avatar.cpp | 2 +- .../src/avatars-renderer/SkeletonModel.cpp | 6 +- .../src/avatars-renderer/SkeletonModel.h | 2 +- .../src/RenderableModelEntityItem.cpp | 2 +- .../src/RenderableShapeEntityItem.cpp | 4 +- .../src/RenderableZoneEntityItem.cpp | 4 +- .../render-utils/src/BackgroundStage.cpp | 5 +- .../src/DeferredLightingEffect.cpp | 98 +++++-------------- .../render-utils/src/DeferredLightingEffect.h | 3 +- libraries/render-utils/src/GeometryCache.cpp | 36 +++---- libraries/render-utils/src/GeometryCache.h | 36 +++---- .../render-utils/src/RenderPipelines.cpp | 12 +-- .../render-utils/src/UpdateSceneTask.cpp | 6 +- libraries/render-utils/src/ZoneRenderer.cpp | 20 ++-- libraries/render/src/render/ShapePipeline.cpp | 6 +- libraries/render/src/render/ShapePipeline.h | 4 +- tests/gpu-test/src/TestWindow.cpp | 2 +- tests/render-perf/src/main.cpp | 4 +- 25 files changed, 120 insertions(+), 165 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 690a833c3b..27361d0bd0 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -5110,7 +5110,7 @@ namespace render { auto& batch = *args->_batch; DependencyManager::get()->bindSimpleProgram(batch); - renderWorldBox(batch); + renderWorldBox(args, batch); } } } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 78a503bc71..7822b78244 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -34,7 +34,7 @@ using namespace std; -void renderWorldBox(gpu::Batch& batch) { +void renderWorldBox(RenderArgs* args, gpu::Batch& batch) { auto geometryCache = DependencyManager::get(); // Show center of world @@ -115,7 +115,7 @@ void renderWorldBox(gpu::Batch& batch) { geometryIds[17]); - geometryCache->renderWireCubeInstance(batch, GREY4); + geometryCache->renderWireCubeInstance(args, batch, GREY4); // Draw meter markers along the 3 axis to help with measuring things const float MARKER_DISTANCE = 1.0f; @@ -123,23 +123,23 @@ void renderWorldBox(gpu::Batch& batch) { transform = Transform().setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, RED); + geometryCache->renderSolidSphereInstance(args, batch, RED); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, 0.0f)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, RED); + geometryCache->renderSolidSphereInstance(args, batch, RED); transform = Transform().setTranslation(glm::vec3(0.0f, MARKER_DISTANCE, 0.0f)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, GREEN); + geometryCache->renderSolidSphereInstance(args, batch, GREEN); transform = Transform().setTranslation(glm::vec3(0.0f, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, BLUE); + geometryCache->renderSolidSphereInstance(args, batch, BLUE); transform = Transform().setTranslation(glm::vec3(MARKER_DISTANCE, 0.0f, MARKER_DISTANCE)).setScale(MARKER_RADIUS); batch.setModelTransform(transform); - geometryCache->renderSolidSphereInstance(batch, GREY); + geometryCache->renderSolidSphereInstance(args, batch, GREY); } // Do some basic timing tests and report the results diff --git a/interface/src/Util.h b/interface/src/Util.h index b1b4c78bcb..48acb53936 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -16,8 +16,9 @@ #include #include +#include -void renderWorldBox(gpu::Batch& batch); +void renderWorldBox(RenderArgs* args, gpu::Batch& batch); void runTimingTests(); void runUnitTests(); diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 8af4c1d908..707aabc241 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -73,7 +73,7 @@ void Cube3DOverlay::render(RenderArgs* args) { if (_isSolid) { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderSolidCubeInstance(*batch, cubeColor, pipeline); + geometryCache->renderSolidCubeInstance(args, *batch, cubeColor, pipeline); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { @@ -109,7 +109,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderWireCubeInstance(*batch, cubeColor, pipeline); + geometryCache->renderWireCubeInstance(args, *batch, cubeColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Shape3DOverlay.cpp b/interface/src/ui/overlays/Shape3DOverlay.cpp index 2556bc84aa..72c57565d4 100644 --- a/interface/src/ui/overlays/Shape3DOverlay.cpp +++ b/interface/src/ui/overlays/Shape3DOverlay.cpp @@ -53,9 +53,9 @@ void Shape3DOverlay::render(RenderArgs* args) { transform.setScale(dimensions); batch->setModelTransform(transform); if (_isSolid) { - geometryCache->renderSolidShapeInstance(*batch, _shape, cubeColor, pipeline); + geometryCache->renderSolidShapeInstance(args, *batch, _shape, cubeColor, pipeline); } else { - geometryCache->renderWireShapeInstance(*batch, _shape, cubeColor, pipeline); + geometryCache->renderWireShapeInstance(args, *batch, _shape, cubeColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 07c2861f16..67e11cf1d8 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -50,9 +50,9 @@ void Sphere3DOverlay::render(RenderArgs* args) { } if (_isSolid) { - geometryCache->renderSolidSphereInstance(*batch, sphereColor, pipeline); + geometryCache->renderSolidSphereInstance(args, *batch, sphereColor, pipeline); } else { - geometryCache->renderWireSphereInstance(*batch, sphereColor, pipeline); + geometryCache->renderWireSphereInstance(args, *batch, sphereColor, pipeline); } } } diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index ebc28ca86a..ed29bc4e1b 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -138,7 +138,7 @@ void Text3DOverlay::render(RenderArgs* args) { _textRenderer->draw(batch, 0, 0, getText(), textColor, glm::vec2(-1.0f), getDrawInFront()); // so before we continue, we must reset the pipeline batch.setPipeline(args->_pipeline->pipeline); - args->_pipeline->prepare(batch); + args->_pipeline->prepare(batch, args); } const render::ShapeKey Text3DOverlay::getShapeKey() { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index a0a348388e..6cdffff844 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -609,7 +609,7 @@ void Avatar::render(RenderArgs* renderArgs) { if (showCollisionShapes && shouldRenderHead(renderArgs) && _skeletonModel->isRenderable()) { PROFILE_RANGE_BATCH(batch, __FUNCTION__":skeletonBoundingCollisionShapes"); const float BOUNDING_SHAPE_ALPHA = 0.7f; - _skeletonModel->renderBoundingCollisionShapes(*renderArgs->_batch, getUniformScale(), BOUNDING_SHAPE_ALPHA); + _skeletonModel->renderBoundingCollisionShapes(renderArgs, *renderArgs->_batch, getUniformScale(), BOUNDING_SHAPE_ALPHA); } if (showReceiveStats || showNamesAboveHeads) { diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp index 2a2817e68b..9651951b46 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.cpp @@ -322,20 +322,20 @@ void SkeletonModel::computeBoundingShape() { _boundingCapsuleLocalOffset = invScale * offset; } -void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha) { +void SkeletonModel::renderBoundingCollisionShapes(RenderArgs* args, gpu::Batch& batch, float scale, float alpha) { auto geometryCache = DependencyManager::get(); // draw a blue sphere at the capsule top point glm::vec3 topPoint = _translation + getRotation() * (scale * (_boundingCapsuleLocalOffset + (0.5f * _boundingCapsuleHeight) * Vectors::UNIT_Y)); batch.setModelTransform(Transform().setTranslation(topPoint).postScale(scale * _boundingCapsuleRadius)); - geometryCache->renderSolidSphereInstance(batch, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); + geometryCache->renderSolidSphereInstance(args, batch, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); // draw a yellow sphere at the capsule bottom point glm::vec3 bottomPoint = topPoint - glm::vec3(0.0f, scale * _boundingCapsuleHeight, 0.0f); glm::vec3 axis = topPoint - bottomPoint; batch.setModelTransform(Transform().setTranslation(bottomPoint).postScale(scale * _boundingCapsuleRadius)); - geometryCache->renderSolidSphereInstance(batch, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); + geometryCache->renderSolidSphereInstance(args, batch, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); diff --git a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h index db87a37477..e48884c581 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h +++ b/libraries/avatars-renderer/src/avatars-renderer/SkeletonModel.h @@ -96,7 +96,7 @@ public: /// \return whether or not the head was found. glm::vec3 getDefaultEyeModelPosition() const; - void renderBoundingCollisionShapes(gpu::Batch& batch, float scale, float alpha); + void renderBoundingCollisionShapes(RenderArgs* args, gpu::Batch& batch, float scale, float alpha); float getBoundingCapsuleRadius() const { return _boundingCapsuleRadius; } float getBoundingCapsuleHeight() const { return _boundingCapsuleHeight; } const glm::vec3 getBoundingCapsuleOffset() const { return _boundingCapsuleLocalOffset; } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index f343fdb155..e94a965156 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -380,7 +380,7 @@ void RenderableModelEntityItem::render(RenderArgs* args) { auto shapeTransform = getTransformToCenter(success); if (success) { batch.setModelTransform(shapeTransform); // we want to include the scale as well - DependencyManager::get()->renderWireCubeInstance(batch, greenColor); + DependencyManager::get()->renderWireCubeInstance(args, batch, greenColor); } return; } diff --git a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp index 27dd678d91..62ab3377a8 100644 --- a/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableShapeEntityItem.cpp @@ -128,9 +128,9 @@ void RenderableShapeEntityItem::render(RenderArgs* args) { auto pipeline = color.a < 1.0f ? geometryCache->getTransparentShapePipeline() : geometryCache->getOpaqueShapePipeline(); if (render::ShapeKey(args->_globalShapeKey).isWireframe()) { - geometryCache->renderWireShapeInstance(batch, MAPPING[_shape], color, pipeline); + geometryCache->renderWireShapeInstance(args, batch, MAPPING[_shape], color, pipeline); } else { - geometryCache->renderSolidShapeInstance(batch, MAPPING[_shape], color, pipeline); + geometryCache->renderSolidShapeInstance(args, batch, MAPPING[_shape], color, pipeline); } } diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index da0aef75aa..bb07454992 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -221,10 +221,10 @@ void RenderableZoneEntityItem::render(RenderArgs* args) { if (getShapeType() == SHAPE_TYPE_SPHERE) { shapeTransform.postScale(SPHERE_ENTITY_SCALE); batch.setModelTransform(shapeTransform); - geometryCache->renderWireSphereInstance(batch, DEFAULT_COLOR); + geometryCache->renderWireSphereInstance(args, batch, DEFAULT_COLOR); } else { batch.setModelTransform(shapeTransform); - geometryCache->renderWireCubeInstance(batch, DEFAULT_COLOR); + geometryCache->renderWireCubeInstance(args, batch, DEFAULT_COLOR); } break; } diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index b980887471..c164b584a9 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -60,7 +60,6 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, // Background rendering decision - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); model::SunSkyStagePointer background; model::SkyboxPointer skybox; @@ -69,9 +68,9 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, auto background = backgroundStage->getBackground(backgroundId); if (background) { skybox = background->getSkybox(); - } + } } else { - // skybox = DependencyManager::get()->getDefaultSkybox(); + skybox = backgroundStage->getBackground(0)->getSkybox(); } /* auto backgroundMode = skyStage->getBackgroundMode(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 374487a79d..84c972bab3 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -99,64 +99,23 @@ void DeferredLightingEffect::init() { loadLightProgram(deferred_light_vert, local_lights_shading_frag, true, _localLight, _localLightLocations); loadLightProgram(deferred_light_vert, local_lights_drawOutline_frag, true, _localLightOutline, _localLightOutlineLocations); - - // Light Stage and clusters - /* _lightStage = std::make_shared(); - - // Allocate a global light representing the Global Directional light casting shadow (the sun) and the ambient light - _allocatedLights.push_back(std::make_shared()); - model::LightPointer lp = _allocatedLights[0]; - lp->setType(model::Light::SUN); - lp->setDirection(glm::vec3(-1.0f)); - lp->setColor(glm::vec3(1.0f)); - lp->setIntensity(1.0f); - lp->setType(model::Light::SUN); - lp->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset::OLD_TOWN_SQUARE); - - // Add the global light to the light stage (for later shadow rendering) - _globalLights.push_back(_lightStage->addLight(lp)); - _lightStage->addShadow(_globalLights[0]); - - - _backgroundStage = std::make_shared(); - - auto textureCache = DependencyManager::get(); - - { - PROFILE_RANGE(render, "Process Default Skybox"); - auto textureCache = DependencyManager::get(); - - auto skyboxUrl = PathUtils::resourcesPath().toStdString() + "images/Default-Sky-9-cubemap.ktx"; - - _defaultSkyboxTexture = gpu::Texture::unserialize(skyboxUrl); - _defaultSkyboxAmbientTexture = _defaultSkyboxTexture; - - _defaultSkybox->setCubemap(_defaultSkyboxTexture); - } - - - lp->setAmbientIntensity(0.5f); - lp->setAmbientMap(_defaultSkyboxAmbientTexture); - auto irradianceSH = _defaultSkyboxAmbientTexture->getIrradiance(); - if (irradianceSH) { - lp->setAmbientSphere((*irradianceSH)); - }*/ } -void DeferredLightingEffect::setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { +void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { PerformanceTimer perfTimer("DLE->setupBatch()"); model::LightPointer keySunLight; - if (_lightStage && _lightStage->_currentFrame._sunLights.size()) { - keySunLight = _lightStage->getLight(_lightStage->_currentFrame._sunLights.front()); + auto lightStage = args->_scene->getStage("LIGHT_STAGE"); + if (lightStage && lightStage->_currentFrame._sunLights.size()) { + keySunLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front()); } else { - keySunLight = _allocatedLights[_globalLights.front()]; + keySunLight = lightStage->getLight(0); } model::LightPointer keyAmbiLight; - if (_lightStage && _lightStage->_currentFrame._ambientLights.size()) { - keyAmbiLight = _lightStage->getLight(_lightStage->_currentFrame._ambientLights.front()); + if (lightStage && lightStage->_currentFrame._ambientLights.size()) { + keyAmbiLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front()); } else { - keyAmbiLight = _allocatedLights[_globalLights.front()]; + keyAmbiLight = lightStage->getLight(0); } if (lightBufferUnit >= 0) { @@ -266,21 +225,6 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo } -void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) { - /* auto globalLight = _allocatedLights.front(); - globalLight->setDirection(light->getDirection()); - globalLight->setColor(light->getColor()); - globalLight->setIntensity(light->getIntensity()); - globalLight->setAmbientIntensity(light->getAmbientIntensity()); - globalLight->setAmbientSphere(light->getAmbientSphere()); - globalLight->setAmbientMap(light->getAmbientMap());*/ -} -/* -const model::LightPointer& DeferredLightingEffect::getGlobalLight() const { - return _allocatedLights.front(); -} -*/ - #include model::MeshPointer DeferredLightingEffect::getPointLightMesh() { @@ -483,8 +427,6 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input // Prepare a fresh Light Frame - //auto deferredLightingEffect = DependencyManager::get(); - //deferredLightingEffect->getLightStage()->_currentFrame.clear(); auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); lightStage->_currentFrame.clear(); } @@ -550,9 +492,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Global directional light and ambient pass auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); - // assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); assert(lightStage->getNumLights() > 0); - // auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; @@ -563,7 +503,8 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, auto& program = deferredLightingEffect->_directionalSkyboxLight; LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; - const auto& keyLight = deferredLightingEffect->_allocatedLights[deferredLightingEffect->_globalLights.front()]; + + auto keyLight = lightStage->getLight(0); // Setup the global directional pass pipeline { @@ -602,7 +543,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, batch._glUniform4fv(locations->texcoordFrameTransform, 1, reinterpret_cast< const float* >(&textureFrameTransform)); // Setup the global lighting - deferredLightingEffect->setupKeyLightBatch(batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); + deferredLightingEffect->setupKeyLightBatch(args, batch, locations->lightBufferUnit, locations->ambientBufferUnit, SKYBOX_MAP_UNIT); batch.draw(gpu::TRIANGLE_STRIP, 4); @@ -759,7 +700,7 @@ void RenderDeferred::run(const RenderContextPointer& renderContext, const Inputs void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { - if (!_defaultLight) { + if (!_defaultLight || !_defaultBackground) { if (!_defaultSkyboxTexture) { auto textureCache = DependencyManager::get(); { @@ -779,7 +720,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { if (lightStage) { // Allocate a default global light directional and ambient - model::LightPointer lp = std::make_shared(); + auto lp = std::make_shared(); lp->setType(model::Light::SUN); lp->setDirection(glm::vec3(-1.0f)); lp->setColor(glm::vec3(1.0f)); @@ -801,6 +742,19 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { auto defaultLightID = lightStage->addLight(lp); lightStage->addShadow(defaultLightID); } + + auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + if (backgroundStage) { + + auto background = std::make_shared(); + background->setSkybox(_defaultSkybox); + + // capture deault background + _defaultBackground = background; + + // Add the global light to the light stage (for later shadow rendering) + auto defaultBackgroundID = backgroundStage->addBackground(_defaultBackground); + } } } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 0e1b365149..fcbb8acf25 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -47,7 +47,7 @@ class DeferredLightingEffect : public Dependency { public: void init(); - void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); + void setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); // update global lighting @@ -203,6 +203,7 @@ public: protected: model::LightPointer _defaultLight; + model::SunSkyStagePointer _defaultBackground; model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; gpu::TexturePointer _defaultSkyboxTexture; gpu::TexturePointer _defaultSkyboxAmbientTexture; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index dcf90012c1..49b844efb0 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -455,7 +455,7 @@ _nextID(0) { buildShapes(); GeometryCache::_simpleOpaquePipeline = std::make_shared(getSimplePipeline(false, false, true, false), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) { + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -463,7 +463,7 @@ _nextID(0) { ); GeometryCache::_simpleTransparentPipeline = std::make_shared(getSimplePipeline(false, true, true, false), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) { + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -471,7 +471,7 @@ _nextID(0) { ); GeometryCache::_simpleWirePipeline = std::make_shared(getSimplePipeline(false, false, true, true), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) {}); + [](const render::ShapePipeline&, gpu::Batch& batch, RenderArgs* args) {}); } GeometryCache::~GeometryCache() { @@ -1938,7 +1938,7 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; -void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, +void renderInstances(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, bool isWire, const render::ShapePipelinePointer& pipeline, GeometryCache::Shape shape) { // Add pipeline to name std::string instanceName = (isWire ? "wire_shapes_" : "solid_shapes_") + std::to_string(shape) + "_" + std::to_string(std::hash()(pipeline)); @@ -1951,9 +1951,9 @@ void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, } // Add call to named buffer - batch.setupNamedCalls(instanceName, [isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { + batch.setupNamedCalls(instanceName, [args, isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { batch.setPipeline(pipeline->pipeline); - pipeline->prepare(batch); + pipeline->prepare(batch, args); if (isWire) { DependencyManager::get()->renderWireShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]); @@ -1963,28 +1963,28 @@ void renderInstances(gpu::Batch& batch, const glm::vec4& color, bool isWire, }); } -void GeometryCache::renderSolidShapeInstance(gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, false, pipeline, shape); +void GeometryCache::renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, false, pipeline, shape); } -void GeometryCache::renderWireShapeInstance(gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, true, pipeline, shape); +void GeometryCache::renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, GeometryCache::Shape shape, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, true, pipeline, shape); } -void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, false, pipeline, GeometryCache::Sphere); +void GeometryCache::renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, false, pipeline, GeometryCache::Sphere); } -void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { - renderInstances(batch, color, true, pipeline, GeometryCache::Sphere); +void GeometryCache::renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { + renderInstances(args, batch, color, true, pipeline, GeometryCache::Sphere); } // Enable this in a debug build to cause 'box' entities to iterate through all the // available shape types, both solid and wireframes //#define DEBUG_SHAPES -void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { +void GeometryCache::renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { #ifdef DEBUG_SHAPES static auto startTime = usecTimestampNow(); renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { @@ -2018,11 +2018,11 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& } }); #else - renderInstances(batch, color, false, pipeline, GeometryCache::Cube); + renderInstances(args, batch, color, false, pipeline, GeometryCache::Cube); #endif } -void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { +void GeometryCache::renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { static const std::string INSTANCE_NAME = __FUNCTION__; - renderInstances(batch, color, true, pipeline, GeometryCache::Cube); + renderInstances(args, batch, color, true, pipeline, GeometryCache::Cube); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 9853269280..fa558a1151 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -172,46 +172,46 @@ public: void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer); - void renderSolidShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), + void renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec3& color, + void renderSolidShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidShapeInstance(batch, shape, glm::vec4(color, 1.0f), pipeline); + renderSolidShapeInstance(args, batch, shape, glm::vec4(color, 1.0f), pipeline); } - void renderWireShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), + void renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec4& color = glm::vec4(1), const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderWireShapeInstance(gpu::Batch& batch, Shape shape, const glm::vec3& color, + void renderWireShapeInstance(RenderArgs* args, gpu::Batch& batch, Shape shape, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderWireShapeInstance(batch, shape, glm::vec4(color, 1.0f), pipeline); + renderWireShapeInstance(args, batch, shape, glm::vec4(color, 1.0f), pipeline); } - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, + void renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, + void renderSolidSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderSolidSphereInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, + void renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline); - void renderWireSphereInstance(gpu::Batch& batch, const glm::vec3& color, + void renderWireSphereInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline) { - renderWireSphereInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderWireSphereInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color, + void renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline); - void renderSolidCubeInstance(gpu::Batch& batch, const glm::vec3& color, + void renderSolidCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleOpaquePipeline) { - renderSolidCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderSolidCubeInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, + void renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline); - void renderWireCubeInstance(gpu::Batch& batch, const glm::vec3& color, + void renderWireCubeInstance(RenderArgs* args, gpu::Batch& batch, const glm::vec3& color, const render::ShapePipelinePointer& pipeline = _simpleWirePipeline) { - renderWireCubeInstance(batch, glm::vec4(color, 1.0f), pipeline); + renderWireCubeInstance(args, batch, glm::vec4(color, 1.0f), pipeline); } // Dynamic geometry diff --git a/libraries/render-utils/src/RenderPipelines.cpp b/libraries/render-utils/src/RenderPipelines.cpp index 42ed0bdad9..6c3a58b7e5 100644 --- a/libraries/render-utils/src/RenderPipelines.cpp +++ b/libraries/render-utils/src/RenderPipelines.cpp @@ -76,8 +76,8 @@ void initForwardPipelines(ShapePlumber& plumber); void addPlumberPipeline(ShapePlumber& plumber, const ShapeKey& key, const gpu::ShaderPointer& vertex, const gpu::ShaderPointer& pixel); -void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch); -void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch); +void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args); +void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args); void initOverlay3DPipelines(ShapePlumber& plumber) { auto vertex = gpu::Shader::createVertex(std::string(overlay3D_vert)); @@ -359,7 +359,7 @@ void addPlumberPipeline(ShapePlumber& plumber, } } -void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { +void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args) { // Set a default albedo map batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); @@ -382,13 +382,13 @@ void batchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { } } -void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch) { +void lightBatchSetter(const ShapePipeline& pipeline, gpu::Batch& batch, RenderArgs* args) { // Set the batch - batchSetter(pipeline, batch); + batchSetter(pipeline, batch, args); // Set the light if (pipeline.locations->lightBufferUnit >= 0) { - DependencyManager::get()->setupKeyLightBatch(batch, + DependencyManager::get()->setupKeyLightBatch(args, batch, pipeline.locations->lightBufferUnit, pipeline.locations->lightAmbientBufferUnit, pipeline.locations->lightAmbientMapUnit); diff --git a/libraries/render-utils/src/UpdateSceneTask.cpp b/libraries/render-utils/src/UpdateSceneTask.cpp index 1a9beb4bed..2daee5fb5a 100644 --- a/libraries/render-utils/src/UpdateSceneTask.cpp +++ b/libraries/render-utils/src/UpdateSceneTask.cpp @@ -16,11 +16,11 @@ #include "DeferredLightingEffect.h" void UpdateSceneTask::build(JobModel& task, const render::Varying& input, render::Varying& output) { - - task.addJob("PerformSceneTransaction"); - task.addJob("LightStageSetup"); + task.addJob("BackgroundStageSetup"); task.addJob("DefaultLightingSetup"); + + task.addJob("PerformSceneTransaction"); } diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index e20e7d9ed8..80be123f0f 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -52,14 +52,19 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& oupu } void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) { - - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); backgroundStage->_currentFrame.clear(); // call render in the correct order first... render::renderItems(context, inputs); + // Finally add the default lights and background: + auto lightStage = context->_scene->getStage("LIGHT_STAGE"); + lightStage->_currentFrame.pushSunLight(0); + lightStage->_currentFrame.pushAmbientLight(0); + + backgroundStage->_currentFrame.pushBackground(0); + } const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() { @@ -131,7 +136,6 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I auto deferredTransform = inputs; - // auto lightStage = DependencyManager::get()->getLightStage(); auto lightStage = context->_scene->getStage("LIGHT_STAGE"); std::vector keyLightStack; if (lightStage && lightStage->_currentFrame._sunLights.size()) { @@ -139,8 +143,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I keyLightStack.push_back(lightStage->getLight(index)); } } - // keyLightStack.push_back(DependencyManager::get()->getGlobalLight()); - keyLightStack.push_back(lightStage->getLight(0)); + // keyLightStack.push_back(lightStage->getLight(0)); std::vector ambientLightStack; if (lightStage && lightStage->_currentFrame._ambientLights.size()) { @@ -148,11 +151,8 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I ambientLightStack.push_back(lightStage->getLight(index)); } } - // ambientLightStack.push_back(DependencyManager::get()->getGlobalLight()); - ambientLightStack.push_back(lightStage->getLight(0)); + // ambientLightStack.push_back(lightStage->getLight(0)); - - // auto backgroundStage = DependencyManager::get()->getBackgroundStage(); auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); std::vector skyboxStack; if (backgroundStage && backgroundStage->_currentFrame._backgrounds.size()) { @@ -163,7 +163,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I } } } - // skyboxStack.push_back(DependencyManager::get()->getDefaultSkybox()); + // skyboxStack.push_back(backgroundStage->getBackground(0)->getSkybox()); gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index d51d7f8cb6..79ac5c0990 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -17,9 +17,9 @@ using namespace render; -void ShapePipeline::prepare(gpu::Batch& batch) { +void ShapePipeline::prepare(gpu::Batch& batch, RenderArgs* args) { if (batchSetter) { - batchSetter(*this, batch); + batchSetter(*this, batch, args); } } @@ -119,7 +119,7 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke // Run the pipeline's BatchSetter on the passed in batch if (shapePipeline->batchSetter) { - shapePipeline->batchSetter(*shapePipeline, *batch); + shapePipeline->batchSetter(*shapePipeline, *batch, args); } return shapePipeline; diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 434c909198..1b97baae7c 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -240,14 +240,14 @@ public: }; using LocationsPointer = std::shared_ptr; - using BatchSetter = std::function; + using BatchSetter = std::function; ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) : pipeline(pipeline), locations(locations), batchSetter(batchSetter) {} // Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually, // after calling setPipeline this method should be called to prepare the pipeline with default buffers. - void prepare(gpu::Batch& batch); + void prepare(gpu::Batch& batch, RenderArgs* args); gpu::PipelinePointer pipeline; std::shared_ptr locations; diff --git a/tests/gpu-test/src/TestWindow.cpp b/tests/gpu-test/src/TestWindow.cpp index 6436ff1ef4..5b5102701a 100644 --- a/tests/gpu-test/src/TestWindow.cpp +++ b/tests/gpu-test/src/TestWindow.cpp @@ -77,7 +77,7 @@ void TestWindow::initGl() { #ifdef DEFERRED_LIGHTING auto deferredLightingEffect = DependencyManager::get(); deferredLightingEffect->init(); - deferredLightingEffect->setGlobalLight(_light); + // deferredLightingEffect->setGlobalLight(_light); initDeferredPipelines(*_shapePlumber); #endif } diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 52592cd202..f725e1f09d 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -891,7 +891,7 @@ private: // Setup the current Zone Entity lighting { auto stage = DependencyManager::get()->getSkyStage(); - DependencyManager::get()->setGlobalLight(stage->getSunLight()); + // DependencyManager::get()->setGlobalLight(stage->getSunLight()); } { @@ -914,7 +914,7 @@ private: // The pending changes collecting the changes here render::Transaction transaction; // Setup the current Zone Entity lighting - DependencyManager::get()->setGlobalLight(_sunSkyStage.getSunLight()); + // DependencyManager::get()->setGlobalLight(_sunSkyStage.getSunLight()); { PerformanceTimer perfTimer("SceneProcessTransaction"); _main3DScene->enqueueTransaction(transaction); From 77644e7e9dbf890e760d54a8a5a20b30d3e877b7 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 14:34:09 +0200 Subject: [PATCH 06/39] Removing commented objects from deferredlighting effect --- .../render-utils/src/DeferredLightingEffect.h | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index fcbb8acf25..7fc9600d18 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -50,27 +50,13 @@ public: void setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); void unsetKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit); - // update global lighting - // void setGlobalLight(const model::LightPointer& light); - // const model::LightPointer& getGlobalLight() const; - - // const LightStagePointer& getLightStage() { return _lightStage; } - // const BackgroundStagePointer& getBackgroundStage() { return _backgroundStage; } - void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; void setAmbientOcclusionEnabled(bool enable) { _ambientOcclusionEnabled = enable; } bool isAmbientOcclusionEnabled() const { return _ambientOcclusionEnabled; } - // model::SkyboxPointer getDefaultSkybox() const { return _defaultSkybox; } - // gpu::TexturePointer getDefaultSkyboxTexture() const { return _defaultSkyboxTexture; } - // gpu::TexturePointer getDefaultSkyboxAmbientTexture() const { return _defaultSkyboxAmbientTexture; } - private: DeferredLightingEffect() = default; - // LightStagePointer _lightStage; - // BackgroundStagePointer _backgroundStage; - bool _shadowMapEnabled{ false }; bool _ambientOcclusionEnabled{ false }; @@ -97,15 +83,6 @@ private: LightLocationsPtr _localLightLocations; LightLocationsPtr _localLightOutlineLocations; - // using Lights = std::vector; - - // Lights _allocatedLights; - // std::vector _globalLights; - - // model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; - // gpu::TexturePointer _defaultSkyboxTexture; - // gpu::TexturePointer _defaultSkyboxAmbientTexture; - friend class LightClusteringPass; friend class RenderDeferredSetup; friend class RenderDeferredLocals; From 904f22985c4840c3412308cb6a52393ac75fd8be Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 16:43:04 +0200 Subject: [PATCH 07/39] CLeaning up comments --- .../entities-renderer/src/RenderableZoneEntityItem.cpp | 6 ++---- libraries/render-utils/src/BackgroundStage.cpp | 6 ++++-- libraries/render-utils/src/BackgroundStage.h | 3 +++ libraries/render-utils/src/DeferredLightingEffect.cpp | 10 +++++----- libraries/render-utils/src/LightStage.cpp | 6 ++++-- libraries/render-utils/src/LightStage.h | 3 +++ libraries/render/src/render/Scene.h | 2 +- 7 files changed, 22 insertions(+), 14 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index bb07454992..a57a6e5d52 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -554,13 +554,11 @@ void RenderableZoneEntityItemMeta::setProceduralUserData(QString userData) { void RenderableZoneEntityItemMeta::render(RenderArgs* args) { if (!_stage) { - // _stage = DependencyManager::get()->getLightStage(); - _stage = args->_scene->getStage("LIGHT_STAGE"); + _stage = args->_scene->getStage(); } if (!_backgroundStage) { - //_backgroundStage = DependencyManager::get()->getBackgroundStage(); - _backgroundStage = args->_scene->getStage("BACKGROUND_STAGE"); + _backgroundStage = args->_scene->getStage(); } { // Sun diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index c164b584a9..8599ec64e0 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -13,6 +13,8 @@ #include +std::string BackgroundStage::_stageName { "BACKGROUND_STAGE"}; + BackgroundStage::Index BackgroundStage::findBackground(const BackgroundPointer& background) const { auto found = _backgroundMap.find(background); if (found != _backgroundMap.end()) { @@ -143,9 +145,9 @@ BackgroundStageSetup::BackgroundStageSetup() { } void BackgroundStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + auto stage = renderContext->_scene->getStage(BackgroundStage::getName()); if (!stage) { - renderContext->_scene->resetStage("BACKGROUND_STAGE", std::make_shared()); + renderContext->_scene->resetStage(BackgroundStage::getName(), std::make_shared()); } } diff --git a/libraries/render-utils/src/BackgroundStage.h b/libraries/render-utils/src/BackgroundStage.h index 2f0231b071..eab7c94f0d 100644 --- a/libraries/render-utils/src/BackgroundStage.h +++ b/libraries/render-utils/src/BackgroundStage.h @@ -23,6 +23,9 @@ // Background stage to set up background-related rendering tasks class BackgroundStage : public render::Stage { public: + static std::string _stageName; + static const std::string& getName() { return _stageName; } + using Index = render::indexed_container::Index; static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX }; static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; } diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 84c972bab3..399225ac3b 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -104,7 +104,7 @@ void DeferredLightingEffect::init() { void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Batch& batch, int lightBufferUnit, int ambientBufferUnit, int skyboxCubemapUnit) { PerformanceTimer perfTimer("DLE->setupBatch()"); model::LightPointer keySunLight; - auto lightStage = args->_scene->getStage("LIGHT_STAGE"); + auto lightStage = args->_scene->getStage(); if (lightStage && lightStage->_currentFrame._sunLights.size()) { keySunLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front()); } else { @@ -427,7 +427,7 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input // Prepare a fresh Light Frame - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); lightStage->_currentFrame.clear(); } @@ -491,7 +491,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Global directional light and ambient pass - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); assert(lightStage->getNumLights() > 0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; @@ -716,7 +716,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { } } - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); if (lightStage) { // Allocate a default global light directional and ambient @@ -743,7 +743,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { lightStage->addShadow(defaultLightID); } - auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + auto backgroundStage = renderContext->_scene->getStage(); if (backgroundStage) { auto background = std::make_shared(); diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 10c99bf008..d0e9f2467e 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -13,6 +13,8 @@ #include "LightStage.h" +std::string LightStage::_stageName { "LIGHT_STAGE"}; + LightStage::LightStage() { } @@ -172,10 +174,10 @@ LightStageSetup::LightStageSetup() { } void LightStageSetup::run(const render::RenderContextPointer& renderContext) { - auto stage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto stage = renderContext->_scene->getStage(LightStage::getName()); if (!stage) { stage = std::make_shared(); - renderContext->_scene->resetStage("LIGHT_STAGE", stage); + renderContext->_scene->resetStage(LightStage::getName(), stage); } } diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index 8273118f0c..f946cf699e 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -28,6 +28,9 @@ class ViewFrustum; // Light stage to set up light-related rendering tasks class LightStage : public render::Stage { public: + static std::string _stageName; + static const std::string& getName() { return _stageName; } + using Index = render::indexed_container::Index; static const Index INVALID_INDEX { render::indexed_container::INVALID_INDEX }; static bool isIndexInvalid(Index index) { return index == INVALID_INDEX; } diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index f0c5e7a3f0..199d9ce224 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -117,7 +117,7 @@ public: // Thread safe StagePointer getStage(const Stage::Name& name) const; template - std::shared_ptr getStage(const Stage::Name& name) const { + std::shared_ptr getStage(const Stage::Name& name = T::getName()) const { auto stage = getStage(name); return (stage ? std::static_pointer_cast(stage) : std::shared_ptr()); } From a2fc44703d4be82b9b10982e2834c6aeece07b5a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 16:45:54 +0200 Subject: [PATCH 08/39] One less constant --- libraries/render-utils/src/BackgroundStage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 8599ec64e0..5275331696 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -62,7 +62,7 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, // Background rendering decision - auto backgroundStage = renderContext->_scene->getStage("BACKGROUND_STAGE"); + auto backgroundStage = renderContext->_scene->getStage(); model::SunSkyStagePointer background; model::SkyboxPointer skybox; if (backgroundStage->_currentFrame._backgrounds.size()) { From 7cbeabfc2991949ec18eed4c8ec16c4c1f59a7a5 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 16:49:20 +0200 Subject: [PATCH 09/39] less comments & constant --- libraries/render-utils/src/LightClusters.cpp | 2 +- libraries/render-utils/src/LightPayload.cpp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 79b755f310..1f99f190af 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -576,7 +576,7 @@ void LightClusteringPass::run(const render::RenderContextPointer& renderContext, // From the LightStage and the current frame, update the light cluster Grid // auto deferredLightingEffect = DependencyManager::get(); // auto lightStage = deferredLightingEffect->getLightStage(); - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); _lightClusters->updateLightStage(lightStage); _lightClusters->updateLightFrame(lightStage->_currentFrame, lightingModel->isPointLightEnabled(), lightingModel->isSpotLightEnabled()); diff --git a/libraries/render-utils/src/LightPayload.cpp b/libraries/render-utils/src/LightPayload.cpp index d0cc8dfd18..5f7f7236f2 100644 --- a/libraries/render-utils/src/LightPayload.cpp +++ b/libraries/render-utils/src/LightPayload.cpp @@ -55,8 +55,7 @@ LightPayload::~LightPayload() { void LightPayload::render(RenderArgs* args) { if (!_stage) { - // _stage = DependencyManager::get()->getLightStage(); - _stage = args->_scene->getStage("LIGHT_STAGE"); + _stage = args->_scene->getStage(); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { @@ -124,8 +123,7 @@ KeyLightPayload::~KeyLightPayload() { void KeyLightPayload::render(RenderArgs* args) { if (!_stage) { - // _stage = DependencyManager::get()->getLightStage(); - _stage = args->_scene->getStage("LIGHT_STAGE"); + _stage = args->_scene->getStage(); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { From 6ab2dccd3830dbe013337cbbf51b7693c19f7cb4 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 16:52:04 +0200 Subject: [PATCH 10/39] less comments & constant --- libraries/render-utils/src/LightClusters.cpp | 2 -- libraries/render-utils/src/RenderShadowTask.cpp | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 1f99f190af..74209ce951 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -574,8 +574,6 @@ void LightClusteringPass::run(const render::RenderContextPointer& renderContext, } // From the LightStage and the current frame, update the light cluster Grid - // auto deferredLightingEffect = DependencyManager::get(); - // auto lightStage = deferredLightingEffect->getLightStage(); auto lightStage = renderContext->_scene->getStage(); _lightClusters->updateLightStage(lightStage); _lightClusters->updateLightFrame(lightStage->_currentFrame, lightingModel->isPointLightEnabled(), lightingModel->isSpotLightEnabled()); diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 2d8f6c0cab..a817a6abff 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -35,8 +35,7 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, assert(renderContext->args); assert(renderContext->args->hasViewFrustum()); - // auto lightStage = DependencyManager::get()->getLightStage(); - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); LightStage::Index globalLightIndex { 0 }; @@ -141,8 +140,7 @@ void RenderShadowTask::configure(const Config& configuration) { } void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, Output& output) { - // auto lightStage = DependencyManager::get()->getLightStage(); - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); const auto globalShadow = lightStage->getShadow(0); // Cache old render args From 5e05c41980c9248f67b33ccd3fb6e20cded4dc2a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 16:56:04 +0200 Subject: [PATCH 11/39] less comments & constant --- libraries/render-utils/src/DebugDeferredBuffer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index e83789252c..8887de81ef 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -432,11 +432,8 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I batch.setResourceTexture(Lighting, deferredFramebuffer->getLightingTexture()); } - // auto deferredLightingEffect = DependencyManager::get(); - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); - // assert(deferredLightingEffect->getLightStage()->getNumLights() > 0); + auto lightStage = renderContext->_scene->getStage(); assert(lightStage->getNumLights() > 0); - // auto lightAndShadow = deferredLightingEffect->getLightStage()->getLightAndShadow(0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; if (globalShadow) { From 7687bdc0600880b40fc5b7d13fe6b877afa4e080 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 26 Jun 2017 17:02:45 +0200 Subject: [PATCH 12/39] less comments & constant --- .../src/DeferredLightingEffect.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 399225ac3b..5f18916a92 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -107,26 +107,27 @@ void DeferredLightingEffect::setupKeyLightBatch(const RenderArgs* args, gpu::Bat auto lightStage = args->_scene->getStage(); if (lightStage && lightStage->_currentFrame._sunLights.size()) { keySunLight = lightStage->getLight(lightStage->_currentFrame._sunLights.front()); - } else { - keySunLight = lightStage->getLight(0); } model::LightPointer keyAmbiLight; if (lightStage && lightStage->_currentFrame._ambientLights.size()) { keyAmbiLight = lightStage->getLight(lightStage->_currentFrame._ambientLights.front()); - } else { - keyAmbiLight = lightStage->getLight(0); } - if (lightBufferUnit >= 0) { - batch.setUniformBuffer(lightBufferUnit, keySunLight->getLightSchemaBuffer()); - } - if (ambientBufferUnit >= 0) { - batch.setUniformBuffer(ambientBufferUnit, keyAmbiLight->getAmbientSchemaBuffer()); + if (keySunLight) { + if (lightBufferUnit >= 0) { + batch.setUniformBuffer(lightBufferUnit, keySunLight->getLightSchemaBuffer()); + } } - if (keyAmbiLight->getAmbientMap() && (skyboxCubemapUnit >= 0)) { - batch.setResourceTexture(skyboxCubemapUnit, keyAmbiLight->getAmbientMap()); + if (keyAmbiLight) { + if (ambientBufferUnit >= 0) { + batch.setUniformBuffer(ambientBufferUnit, keyAmbiLight->getAmbientSchemaBuffer()); + } + + if (keyAmbiLight->getAmbientMap() && (skyboxCubemapUnit >= 0)) { + batch.setResourceTexture(skyboxCubemapUnit, keyAmbiLight->getAmbientMap()); + } } } From 76dae279cf4f9381796016fd6b4ef3546208e915 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 27 Jun 2017 14:24:34 +0200 Subject: [PATCH 13/39] Removing the default case from the renderer --- libraries/render-utils/src/BackgroundStage.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 5275331696..5d04f188f1 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -54,13 +54,11 @@ BackgroundStage::BackgroundPointer BackgroundStage::removeBackground(Index index void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, const Inputs& inputs) { - const auto& lightingModel = inputs; if (!lightingModel->isBackgroundEnabled()) { return; } - // Background rendering decision auto backgroundStage = renderContext->_scene->getStage(); model::SunSkyStagePointer background; @@ -71,10 +69,7 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, if (background) { skybox = background->getSkybox(); } - } else { - skybox = backgroundStage->getBackground(0)->getSkybox(); } - /* auto backgroundMode = skyStage->getBackgroundMode(); switch (backgroundMode) { From 9e822de196ed831ee3c35e31eec19f7f74728820 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Tue, 27 Jun 2017 17:40:23 -0700 Subject: [PATCH 14/39] remove local collection of radius ignored nodes --- .../src/avatars/AvatarMixerClientData.cpp | 3 --- interface/src/avatar/AvatarManager.cpp | 4 ---- .../src/avatars-renderer/Avatar.cpp | 3 +-- libraries/avatars/src/AvatarHashMap.cpp | 7 ------ libraries/avatars/src/AvatarHashMap.h | 1 - libraries/networking/src/NodeList.cpp | 22 +------------------ libraries/networking/src/NodeList.h | 4 ---- libraries/networking/src/udt/PacketHeaders.h | 1 - 8 files changed, 2 insertions(+), 43 deletions(-) diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index 4d80bc7d17..a4bf8fa253 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -108,9 +108,6 @@ void AvatarMixerClientData::ignoreOther(SharedNodePointer self, SharedNodePointe void AvatarMixerClientData::removeFromRadiusIgnoringSet(SharedNodePointer self, const QUuid& other) { if (isRadiusIgnoring(other)) { _radiusIgnoredOthers.erase(other); - auto exitingSpaceBubblePacket = NLPacket::create(PacketType::ExitingSpaceBubble, NUM_BYTES_RFC4122_UUID); - exitingSpaceBubblePacket->write(other.toRfc4122()); - DependencyManager::get()->sendUnreliablePacket(*exitingSpaceBubblePacket, *self); } } diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 20b3949bc6..74775245a7 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -62,7 +62,6 @@ AvatarManager::AvatarManager(QObject* parent) : packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket"); packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar"); packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket"); - packetReceiver.registerListener(PacketType::ExitingSpaceBubble, this, "processExitingSpaceBubble"); // when we hear that the user has ignored an avatar by session UUID // immediately remove that avatar instead of waiting for the absence of packets from avatar mixer @@ -319,9 +318,6 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) { emit DependencyManager::get()->enteredIgnoreRadius(); - } - if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble || removalReason == YourAvatarEnteredTheirBubble) { - DependencyManager::get()->radiusIgnoreNodeBySessionID(avatar->getSessionUUID(), true); } else if (removalReason == KillAvatarReason::AvatarDisconnected) { // remove from node sets, if present DependencyManager::get()->removeFromIgnoreMuteSets(avatar->getSessionUUID()); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index a0a348388e..9355b15ed8 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1439,8 +1439,7 @@ void Avatar::addToScene(AvatarSharedPointer myHandle, const render::ScenePointer if (scene) { auto nodelist = DependencyManager::get(); if (showAvatars - && !nodelist->isIgnoringNode(getSessionUUID()) - && !nodelist->isRadiusIgnoringNode(getSessionUUID())) { + && !nodelist->isIgnoringNode(getSessionUUID())) { render::Transaction transaction; addToScene(myHandle, scene, transaction); scene->enqueueTransaction(transaction); diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index e8c37bdaa8..3712080cdb 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -170,13 +170,6 @@ void AvatarHashMap::processKillAvatar(QSharedPointer message, S removeAvatar(sessionUUID, reason); } -void AvatarHashMap::processExitingSpaceBubble(QSharedPointer message, SharedNodePointer sendingNode) { - // read the node id - QUuid sessionUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); - auto nodeList = DependencyManager::get(); - nodeList->radiusIgnoreNodeBySessionID(sessionUUID, false); -} - void AvatarHashMap::removeAvatar(const QUuid& sessionUUID, KillAvatarReason removalReason) { QWriteLocker locker(&_hashLock); diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 21ea8081c7..68fc232685 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -60,7 +60,6 @@ protected slots: void processAvatarDataPacket(QSharedPointer message, SharedNodePointer sendingNode); void processAvatarIdentityPacket(QSharedPointer message, SharedNodePointer sendingNode); void processKillAvatar(QSharedPointer message, SharedNodePointer sendingNode); - void processExitingSpaceBubble(QSharedPointer message, SharedNodePointer sendingNode); protected: AvatarHashMap(); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index e8506e5263..ef9b131928 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -239,11 +239,7 @@ void NodeList::reset() { LimitedNodeList::reset(); _numNoReplyDomainCheckIns = 0; - - // lock and clear our set of radius ignored IDs - _radiusIgnoredSetLock.lockForWrite(); - _radiusIgnoredNodeIDs.clear(); - _radiusIgnoredSetLock.unlock(); +; // lock and clear our set of ignored IDs _ignoredSetLock.lockForWrite(); _ignoredNodeIDs.clear(); @@ -809,22 +805,6 @@ void NodeList::sendIgnoreRadiusStateToNode(const SharedNodePointer& destinationN sendPacket(std::move(ignorePacket), *destinationNode); } -void NodeList::radiusIgnoreNodeBySessionID(const QUuid& nodeID, bool radiusIgnoreEnabled) { - if (radiusIgnoreEnabled) { - QReadLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // read lock for insert - // add this nodeID to our set of ignored IDs - _radiusIgnoredNodeIDs.insert(nodeID); - } else { - QWriteLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // write lock for unsafe_erase - _radiusIgnoredNodeIDs.unsafe_erase(nodeID); - } -} - -bool NodeList::isRadiusIgnoringNode(const QUuid& nodeID) const { - QReadLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // read lock for reading - return _radiusIgnoredNodeIDs.find(nodeID) != _radiusIgnoredNodeIDs.cend(); -} - void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) { // enumerate the nodes to send a reliable ignore packet to each that can leverage it if (!nodeID.isNull() && _sessionUUID != nodeID) { diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index 6db760b3ca..b3a12153e5 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -77,8 +77,6 @@ public: void toggleIgnoreRadius() { ignoreNodesInRadius(!getIgnoreRadiusEnabled()); } void enableIgnoreRadius() { ignoreNodesInRadius(true); } void disableIgnoreRadius() { ignoreNodesInRadius(false); } - void radiusIgnoreNodeBySessionID(const QUuid& nodeID, bool radiusIgnoreEnabled); - bool isRadiusIgnoringNode(const QUuid& other) const; void ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled); bool isIgnoringNode(const QUuid& nodeID) const; void personalMuteNodeBySessionID(const QUuid& nodeID, bool muteEnabled); @@ -166,8 +164,6 @@ private: QTimer _keepAlivePingTimer; bool _requestsDomainListData; - mutable QReadWriteLock _radiusIgnoredSetLock; - tbb::concurrent_unordered_set _radiusIgnoredNodeIDs; mutable QReadWriteLock _ignoredSetLock; tbb::concurrent_unordered_set _ignoredNodeIDs; mutable QReadWriteLock _personalMutedSetLock; diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 6c42193e11..848bfd97cf 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -105,7 +105,6 @@ public: UsernameFromIDReply, ViewFrustum, RequestsDomainListData, - ExitingSpaceBubble, PerAvatarGainSet, EntityScriptGetStatus, EntityScriptGetStatusReply, From be37998b47ad185fe53753e679264d7cc0d6d5c0 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 28 Jun 2017 10:11:55 -0700 Subject: [PATCH 15/39] remove stray semicolon in NodeList --- libraries/networking/src/NodeList.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index ef9b131928..09622ff19d 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -239,7 +239,7 @@ void NodeList::reset() { LimitedNodeList::reset(); _numNoReplyDomainCheckIns = 0; -; + // lock and clear our set of ignored IDs _ignoredSetLock.lockForWrite(); _ignoredNodeIDs.clear(); From f7a3b3a4116498bd0f8b011be8ed4c80ccadc3c6 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 29 Jun 2017 15:55:47 +0200 Subject: [PATCH 16/39] Experimenting faster getters on Avatar for scripts --- libraries/animation/src/Rig.cpp | 19 ++++++++++++++----- .../src/avatars-renderer/Avatar.cpp | 16 ++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 3d04b0b26f..3ea03bc5f9 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -404,8 +404,10 @@ void Rig::setJointRotation(int index, bool valid, const glm::quat& rotation, flo } bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const { - if (isIndexValid(jointIndex)) { - position = (rotation * _internalPoseSet._absolutePoses[jointIndex].trans()) + translation; + // if (isIndexValid(jointIndex)) { + QReadLocker readLock(&_externalPoseSetLock); + if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { + position = (rotation * _externalPoseSet._absolutePoses[jointIndex].trans()) + translation; return true; } else { return false; @@ -413,17 +415,24 @@ bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm: } bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const { +/* if (isIndexValid(jointIndex)) { position = _internalPoseSet._absolutePoses[jointIndex].trans(); return true; } else { return false; - } + }*/ + return getAbsoluteJointTranslationInRigFrame(jointIndex, position); } bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const { - if (isIndexValid(jointIndex)) { - result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); + // if (isIndexValid(jointIndex)) { + // result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); + // return true; + + QReadLocker readLock(&_externalPoseSetLock); + if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { + result = rotation * _externalPoseSet._absolutePoses[jointIndex].rot(); return true; } else { return false; diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index a0a348388e..fbf2254248 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1008,12 +1008,12 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } int Avatar::getJointIndex(const QString& name) const { - if (QThread::currentThread() != thread()) { + /* if (QThread::currentThread() != thread()) { int result; QMetaObject::invokeMethod(const_cast(this), "getJointIndex", Qt::BlockingQueuedConnection, Q_RETURN_ARG(int, result), Q_ARG(const QString&, name)); return result; - } + } */ int result = getFauxJointIndex(name); if (result != -1) { return result; @@ -1022,34 +1022,34 @@ int Avatar::getJointIndex(const QString& name) const { } QStringList Avatar::getJointNames() const { - if (QThread::currentThread() != thread()) { +/* if (QThread::currentThread() != thread()) { QStringList result; QMetaObject::invokeMethod(const_cast(this), "getJointNames", Qt::BlockingQueuedConnection, Q_RETURN_ARG(QStringList, result)); return result; - } + }*/ return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointNames() : QStringList(); } glm::vec3 Avatar::getJointPosition(int index) const { - if (QThread::currentThread() != thread()) { +/* if (QThread::currentThread() != thread()) { glm::vec3 position; QMetaObject::invokeMethod(const_cast(this), "getJointPosition", Qt::BlockingQueuedConnection, Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index)); return position; - } + }*/ glm::vec3 position; _skeletonModel->getJointPositionInWorldFrame(index, position); return position; } glm::vec3 Avatar::getJointPosition(const QString& name) const { - if (QThread::currentThread() != thread()) { +/* if (QThread::currentThread() != thread()) { glm::vec3 position; QMetaObject::invokeMethod(const_cast(this), "getJointPosition", Qt::BlockingQueuedConnection, Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name)); return position; - } + }*/ glm::vec3 position; _skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position); return position; From 24c8267030734bc6b96b1e853cca43bc0588ad4d Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 13:22:14 -0700 Subject: [PATCH 17/39] in Rig joint accessors, if on the Rig's thread use internalPoseSet, else use external --- libraries/animation/src/Rig.cpp | 42 +++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index 3ea03bc5f9..cd5d8c6231 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -404,31 +404,41 @@ void Rig::setJointRotation(int index, bool valid, const glm::quat& rotation, flo } bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm::vec3 translation, glm::quat rotation) const { - // if (isIndexValid(jointIndex)) { + if (QThread::currentThread() == thread()) { + if (isIndexValid(jointIndex)) { + position = (rotation * _internalPoseSet._absolutePoses[jointIndex].trans()) + translation; + return true; + } + return false; + } + QReadLocker readLock(&_externalPoseSetLock); if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { position = (rotation * _externalPoseSet._absolutePoses[jointIndex].trans()) + translation; return true; - } else { - return false; } + return false; } bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const { -/* - if (isIndexValid(jointIndex)) { - position = _internalPoseSet._absolutePoses[jointIndex].trans(); - return true; - } else { + if (QThread::currentThread() == thread()) { + if (isIndexValid(jointIndex)) { + position = _internalPoseSet._absolutePoses[jointIndex].trans(); + return true; + } return false; - }*/ + } return getAbsoluteJointTranslationInRigFrame(jointIndex, position); } bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const { - // if (isIndexValid(jointIndex)) { - // result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); - // return true; + if (QThread::currentThread() == thread()) { + if (isIndexValid(jointIndex)) { + result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); + return true; + } + return false; + } QReadLocker readLock(&_externalPoseSetLock); if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { @@ -440,6 +450,14 @@ bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const } bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const { + if (QThread::currentThread() == thread()) { + if (isIndexValid(jointIndex)) { + rotation = _internalPoseSet._relativePoses[jointIndex].rot(); + return true; + } + return false; + } + QReadLocker readLock(&_externalPoseSetLock); if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._relativePoses.size()) { rotation = _externalPoseSet._relativePoses[jointIndex].rot(); From 0ac8f6efa3dcea0a62fad55f948b46c5b277ebaa Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 14:02:59 -0700 Subject: [PATCH 18/39] cache the jointnames and indexes from FBXGeometry for out-of-thread access --- .../src/avatars-renderer/Avatar.cpp | 43 ++++++------------- .../src/avatars-renderer/Avatar.h | 4 ++ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 5d4d7af493..3674c003a1 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1009,48 +1009,25 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } int Avatar::getJointIndex(const QString& name) const { - /* if (QThread::currentThread() != thread()) { - int result; - BLOCKING_INVOKE_METHOD(const_cast(this), "getJointIndex", - Q_RETURN_ARG(int, result), Q_ARG(const QString&, name)); - return result; - } */ - int result = getFauxJointIndex(name); - if (result != -1) { - return result; + QReadLocker readLock(&_jointIndicesCacheLock); + if (_jointIndicesCache.contains(name)) { + return _jointIndicesCache[name]; } - return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointIndex(name) : -1; + return -1; } QStringList Avatar::getJointNames() const { -/* if (QThread::currentThread() != thread()) { - QStringList result; - BLOCKING_INVOKE_METHOD(const_cast(this), "getJointNames", - Q_RETURN_ARG(QStringList, result)); - return result; - }*/ - return _skeletonModel->isActive() ? _skeletonModel->getFBXGeometry().getJointNames() : QStringList(); + QReadLocker readLock(&_jointIndicesCacheLock); + return _jointIndicesCache.keys(); } glm::vec3 Avatar::getJointPosition(int index) const { -/* if (QThread::currentThread() != thread()) { - glm::vec3 position; - BLOCKING_INVOKE_METHOD(const_cast(this), "getJointPosition", - Q_RETURN_ARG(glm::vec3, position), Q_ARG(const int, index)); - return position; - }*/ glm::vec3 position; _skeletonModel->getJointPositionInWorldFrame(index, position); return position; } glm::vec3 Avatar::getJointPosition(const QString& name) const { -/* if (QThread::currentThread() != thread()) { - glm::vec3 position; - BLOCKING_INVOKE_METHOD(const_cast(this), "getJointPosition", - Q_RETURN_ARG(glm::vec3, position), Q_ARG(const QString&, name)); - return position; - }*/ glm::vec3 position; _skeletonModel->getJointPositionInWorldFrame(getJointIndex(name), position); return position; @@ -1071,6 +1048,14 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { } void Avatar::setModelURLFinished(bool success) { + { + QWriteLocker writeLock(&_jointIndicesCacheLock); + _jointIndicesCache.clear(); + if (_skeletonModel && _skeletonModel->isActive()) { + _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; + } + } + if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) { const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 || diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 1724d42510..d2c7756257 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -267,6 +267,10 @@ protected: virtual void maybeUpdateSessionDisplayNameFromTransport(const QString& sessionDisplayName) override { _sessionDisplayName = sessionDisplayName; } // don't use no-op setter! SkeletonModelPointer _skeletonModel; + + QHash _jointIndicesCache; + mutable QReadWriteLock _jointIndicesCacheLock; + glm::vec3 _skeletonOffset; std::vector> _attachmentModels; std::vector> _attachmentsToRemove; From e03b902a157be8ef74d7cdc680374cf359716ec6 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 15:42:24 -0700 Subject: [PATCH 19/39] change when joint cache is copied --- .../src/avatars-renderer/Avatar.cpp | 49 ++++++++++++++----- .../src/avatars-renderer/Avatar.h | 4 +- 2 files changed, 41 insertions(+), 12 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 3674c003a1..445396870f 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1008,17 +1008,48 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } } -int Avatar::getJointIndex(const QString& name) const { - QReadLocker readLock(&_jointIndicesCacheLock); - if (_jointIndicesCache.contains(name)) { - return _jointIndicesCache[name]; +void Avatar::cacheJoints() const { + // _jointIndicesCacheLock should be locked for write before calling this. + _jointIndicesCache.clear(); + if (_skeletonModel && _skeletonModel->isActive()) { + _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; + _jointsCached = true; } - return -1; +} + +int Avatar::getJointIndex(const QString& name) const { + auto getJointIndexWorker = [&]() { + if (_jointIndicesCache.contains(name)) { + return _jointIndicesCache[name]; + } + return -1; + }; + QReadLocker readLock(&_jointIndicesCacheLock); + if (!_jointsCached) { + readLock.unlock(); + { + QWriteLocker writeLock(&_jointIndicesCacheLock); + Avatar::cacheJoints(); + return getJointIndexWorker(); + } + } + return getJointIndexWorker(); } QStringList Avatar::getJointNames() const { + auto getJointNamesWorker = [&]() { + return _jointIndicesCache.keys(); + }; QReadLocker readLock(&_jointIndicesCacheLock); - return _jointIndicesCache.keys(); + if (!_jointsCached) { + readLock.unlock(); + { + QWriteLocker writeLock(&_jointIndicesCacheLock); + Avatar::cacheJoints(); + return getJointNamesWorker(); + } + } + return getJointNamesWorker(); } glm::vec3 Avatar::getJointPosition(int index) const { @@ -1050,12 +1081,8 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { void Avatar::setModelURLFinished(bool success) { { QWriteLocker writeLock(&_jointIndicesCacheLock); - _jointIndicesCache.clear(); - if (_skeletonModel && _skeletonModel->isActive()) { - _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; - } + _jointsCached = false; } - if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) { const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 || diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index d2c7756257..f19feab9c6 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -268,8 +268,10 @@ protected: SkeletonModelPointer _skeletonModel; - QHash _jointIndicesCache; + void cacheJoints() const; + mutable QHash _jointIndicesCache; mutable QReadWriteLock _jointIndicesCacheLock; + mutable bool _jointsCached { false }; glm::vec3 _skeletonOffset; std::vector> _attachmentModels; From 1ac415aa14d3be3b9782aa813690b7dfe5ff148c Mon Sep 17 00:00:00 2001 From: Dante Ruiz Date: Thu, 6 Jul 2017 23:50:32 +0100 Subject: [PATCH 20/39] dynamic listview height --- interface/resources/qml/hifi/audio/Audio.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/resources/qml/hifi/audio/Audio.qml b/interface/resources/qml/hifi/audio/Audio.qml index c13bd3281a..519499e35c 100644 --- a/interface/resources/qml/hifi/audio/Audio.qml +++ b/interface/resources/qml/hifi/audio/Audio.qml @@ -166,7 +166,7 @@ Rectangle { ListView { anchors { left: parent.left; right: parent.right; leftMargin: 70 } - height: 125; + height: Math.min(250, contentHeight); spacing: 0; snapMode: ListView.SnapToItem; clip: true; From 2e88eca2b983f34dbe2e61fb1d747c987057b8af Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 16:33:37 -0700 Subject: [PATCH 21/39] oopsy crazy --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 445396870f..16c0d7516b 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1019,6 +1019,10 @@ void Avatar::cacheJoints() const { int Avatar::getJointIndex(const QString& name) const { auto getJointIndexWorker = [&]() { + int result = getFauxJointIndex(name); + if (result != -1) { + return result; + } if (_jointIndicesCache.contains(name)) { return _jointIndicesCache[name]; } From 15d379cc5ab86be34b6190d91dd7528188ab6194 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 17:36:28 -0700 Subject: [PATCH 22/39] coding style --- libraries/animation/src/Rig.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libraries/animation/src/Rig.cpp b/libraries/animation/src/Rig.cpp index cd5d8c6231..6ebb68773f 100644 --- a/libraries/animation/src/Rig.cpp +++ b/libraries/animation/src/Rig.cpp @@ -408,16 +408,18 @@ bool Rig::getJointPositionInWorldFrame(int jointIndex, glm::vec3& position, glm: if (isIndexValid(jointIndex)) { position = (rotation * _internalPoseSet._absolutePoses[jointIndex].trans()) + translation; return true; + } else { + return false; } - return false; } QReadLocker readLock(&_externalPoseSetLock); if (jointIndex >= 0 && jointIndex < (int)_externalPoseSet._absolutePoses.size()) { position = (rotation * _externalPoseSet._absolutePoses[jointIndex].trans()) + translation; return true; + } else { + return false; } - return false; } bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const { @@ -425,10 +427,12 @@ bool Rig::getJointPosition(int jointIndex, glm::vec3& position) const { if (isIndexValid(jointIndex)) { position = _internalPoseSet._absolutePoses[jointIndex].trans(); return true; + } else { + return false; } - return false; + } else { + return getAbsoluteJointTranslationInRigFrame(jointIndex, position); } - return getAbsoluteJointTranslationInRigFrame(jointIndex, position); } bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const glm::quat& rotation) const { @@ -436,8 +440,9 @@ bool Rig::getJointRotationInWorldFrame(int jointIndex, glm::quat& result, const if (isIndexValid(jointIndex)) { result = rotation * _internalPoseSet._absolutePoses[jointIndex].rot(); return true; + } else { + return false; } - return false; } QReadLocker readLock(&_externalPoseSetLock); @@ -454,8 +459,9 @@ bool Rig::getJointRotation(int jointIndex, glm::quat& rotation) const { if (isIndexValid(jointIndex)) { rotation = _internalPoseSet._relativePoses[jointIndex].rot(); return true; + } else { + return false; } - return false; } QReadLocker readLock(&_externalPoseSetLock); From fc61fcf49488c41bb116c53655b59efda773f60a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 17:40:41 -0700 Subject: [PATCH 23/39] coding style --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 16c0d7516b..3fc7bba3d2 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1022,11 +1022,11 @@ int Avatar::getJointIndex(const QString& name) const { int result = getFauxJointIndex(name); if (result != -1) { return result; - } - if (_jointIndicesCache.contains(name)) { + } else if (_jointIndicesCache.contains(name)) { return _jointIndicesCache[name]; + } else { + return -1; } - return -1; }; QReadLocker readLock(&_jointIndicesCacheLock); if (!_jointsCached) { From a543b957efeaf198a60fe45fe69d3034f1372882 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 17:45:57 -0700 Subject: [PATCH 24/39] fix a race --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 3fc7bba3d2..e3586fd9a8 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1010,6 +1010,9 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { void Avatar::cacheJoints() const { // _jointIndicesCacheLock should be locked for write before calling this. + if (_jointsCached) { + return; + } _jointIndicesCache.clear(); if (_skeletonModel && _skeletonModel->isActive()) { _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; From ab8d9f4885dd3bf441fb3a14624cf506d82aedd4 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 18:00:11 -0700 Subject: [PATCH 25/39] check for faux joints before heading into code that needs to lock --- .../avatars-renderer/src/avatars-renderer/Avatar.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index e3586fd9a8..439beb94d6 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1021,11 +1021,13 @@ void Avatar::cacheJoints() const { } int Avatar::getJointIndex(const QString& name) const { + int result = getFauxJointIndex(name); + if (result != -1) { + return result; + } + auto getJointIndexWorker = [&]() { - int result = getFauxJointIndex(name); - if (result != -1) { - return result; - } else if (_jointIndicesCache.contains(name)) { + if (_jointIndicesCache.contains(name)) { return _jointIndicesCache[name]; } else { return -1; From ef4a04b9cf31a201fd5e0dafd3e925913f8af44a Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 18:01:58 -0700 Subject: [PATCH 26/39] code style --- .../avatars-renderer/src/avatars-renderer/Avatar.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 439beb94d6..fc604809dc 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1034,7 +1034,9 @@ int Avatar::getJointIndex(const QString& name) const { } }; QReadLocker readLock(&_jointIndicesCacheLock); - if (!_jointsCached) { + if (_jointsCached) { + return getJointIndexWorker(); + } else { readLock.unlock(); { QWriteLocker writeLock(&_jointIndicesCacheLock); @@ -1042,7 +1044,6 @@ int Avatar::getJointIndex(const QString& name) const { return getJointIndexWorker(); } } - return getJointIndexWorker(); } QStringList Avatar::getJointNames() const { @@ -1050,7 +1051,9 @@ QStringList Avatar::getJointNames() const { return _jointIndicesCache.keys(); }; QReadLocker readLock(&_jointIndicesCacheLock); - if (!_jointsCached) { + if (_jointsCached) { + return getJointNamesWorker(); + } else { readLock.unlock(); { QWriteLocker writeLock(&_jointIndicesCacheLock); @@ -1058,7 +1061,6 @@ QStringList Avatar::getJointNames() const { return getJointNamesWorker(); } } - return getJointNamesWorker(); } glm::vec3 Avatar::getJointPosition(int index) const { From 57ba2c5cd6c9c807e46692f3715bf8611c751c39 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 18:16:41 -0700 Subject: [PATCH 27/39] add invalidateJointIndicesCache method --- .../avatars-renderer/src/avatars-renderer/Avatar.cpp | 11 +++++++---- .../avatars-renderer/src/avatars-renderer/Avatar.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index fc604809dc..2206d67c2c 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1020,6 +1020,11 @@ void Avatar::cacheJoints() const { } } +void Avatar::invalidateJointIndicesCache() const { + QWriteLocker writeLock(&_jointIndicesCacheLock); + _jointsCached = false; +} + int Avatar::getJointIndex(const QString& name) const { int result = getFauxJointIndex(name); if (result != -1) { @@ -1090,10 +1095,8 @@ void Avatar::setSkeletonModelURL(const QUrl& skeletonModelURL) { } void Avatar::setModelURLFinished(bool success) { - { - QWriteLocker writeLock(&_jointIndicesCacheLock); - _jointsCached = false; - } + invalidateJointIndicesCache(); + if (!success && _skeletonModelURL != AvatarData::defaultFullAvatarModelUrl()) { const int MAX_SKELETON_DOWNLOAD_ATTEMPTS = 4; // NOTE: we don't want to be as generous as ResourceCache is, we only want 4 attempts if (_skeletonModel->getResourceDownloadAttemptsRemaining() <= 0 || diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index f19feab9c6..2069e36998 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -269,6 +269,7 @@ protected: SkeletonModelPointer _skeletonModel; void cacheJoints() const; + void invalidateJointIndicesCache() const; mutable QHash _jointIndicesCache; mutable QReadWriteLock _jointIndicesCacheLock; mutable bool _jointsCached { false }; From 801c45898ffd4a23e5a738d5540d0c59ce2bc33e Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 18:41:11 -0700 Subject: [PATCH 28/39] dry up some code --- .../src/avatars-renderer/Avatar.cpp | 71 ++++++++----------- .../src/avatars-renderer/Avatar.h | 2 +- 2 files changed, 30 insertions(+), 43 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 2206d67c2c..4ffacf9fa6 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1008,64 +1008,51 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } } -void Avatar::cacheJoints() const { - // _jointIndicesCacheLock should be locked for write before calling this. - if (_jointsCached) { - return; - } - _jointIndicesCache.clear(); - if (_skeletonModel && _skeletonModel->isActive()) { - _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; - _jointsCached = true; - } -} - void Avatar::invalidateJointIndicesCache() const { QWriteLocker writeLock(&_jointIndicesCacheLock); _jointsCached = false; } +void Avatar::withValidCache(std::function const& worker) const { + QReadLocker readLock(&_jointIndicesCacheLock); + if (_jointsCached) { + worker(); + } else { + readLock.unlock(); + { + QWriteLocker writeLock(&_jointIndicesCacheLock); + if (!_jointsCached) { + _jointIndicesCache.clear(); + if (_skeletonModel && _skeletonModel->isActive()) { + _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; + _jointsCached = true; + } + } + worker(); + } + } +} + int Avatar::getJointIndex(const QString& name) const { int result = getFauxJointIndex(name); if (result != -1) { return result; } - auto getJointIndexWorker = [&]() { + withValidCache([&]() { if (_jointIndicesCache.contains(name)) { - return _jointIndicesCache[name]; - } else { - return -1; + result = _jointIndicesCache[name]; } - }; - QReadLocker readLock(&_jointIndicesCacheLock); - if (_jointsCached) { - return getJointIndexWorker(); - } else { - readLock.unlock(); - { - QWriteLocker writeLock(&_jointIndicesCacheLock); - Avatar::cacheJoints(); - return getJointIndexWorker(); - } - } + }); + return result; } QStringList Avatar::getJointNames() const { - auto getJointNamesWorker = [&]() { - return _jointIndicesCache.keys(); - }; - QReadLocker readLock(&_jointIndicesCacheLock); - if (_jointsCached) { - return getJointNamesWorker(); - } else { - readLock.unlock(); - { - QWriteLocker writeLock(&_jointIndicesCacheLock); - Avatar::cacheJoints(); - return getJointNamesWorker(); - } - } + QStringList result; + withValidCache([&]() { + result = _jointIndicesCache.keys(); + }); + return result; } glm::vec3 Avatar::getJointPosition(int index) const { diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 2069e36998..6566e79d79 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -268,8 +268,8 @@ protected: SkeletonModelPointer _skeletonModel; - void cacheJoints() const; void invalidateJointIndicesCache() const; + void withValidCache(std::function const& worker) const; mutable QHash _jointIndicesCache; mutable QReadWriteLock _jointIndicesCacheLock; mutable bool _jointsCached { false }; From ddabe940d699b8054f7e4aba67e7581ccdeaecce Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 6 Jul 2017 18:42:00 -0700 Subject: [PATCH 29/39] dry up some code --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 6 +++--- libraries/avatars-renderer/src/avatars-renderer/Avatar.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 4ffacf9fa6..664b9f5959 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1013,7 +1013,7 @@ void Avatar::invalidateJointIndicesCache() const { _jointsCached = false; } -void Avatar::withValidCache(std::function const& worker) const { +void Avatar::withValidJointIndicesCache(std::function const& worker) const { QReadLocker readLock(&_jointIndicesCacheLock); if (_jointsCached) { worker(); @@ -1039,7 +1039,7 @@ int Avatar::getJointIndex(const QString& name) const { return result; } - withValidCache([&]() { + withValidJointIndicesCache([&]() { if (_jointIndicesCache.contains(name)) { result = _jointIndicesCache[name]; } @@ -1049,7 +1049,7 @@ int Avatar::getJointIndex(const QString& name) const { QStringList Avatar::getJointNames() const { QStringList result; - withValidCache([&]() { + withValidJointIndicesCache([&]() { result = _jointIndicesCache.keys(); }); return result; diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index 6566e79d79..ce7e53656e 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -269,7 +269,7 @@ protected: SkeletonModelPointer _skeletonModel; void invalidateJointIndicesCache() const; - void withValidCache(std::function const& worker) const; + void withValidJointIndicesCache(std::function const& worker) const; mutable QHash _jointIndicesCache; mutable QReadWriteLock _jointIndicesCacheLock; mutable bool _jointsCached { false }; From 4c1bf6af4716f8dfe6b6ea5cecf6865dcd9d1d3d Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 7 Jul 2017 11:38:25 +0200 Subject: [PATCH 30/39] REmoving comments --- libraries/render-utils/src/ZoneRenderer.cpp | 9 +++------ tests/gpu-test/src/TestWindow.cpp | 1 - tests/render-perf/src/main.cpp | 7 ------- 3 files changed, 3 insertions(+), 14 deletions(-) diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 80be123f0f..8fa243c13b 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -136,14 +136,13 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I auto deferredTransform = inputs; - auto lightStage = context->_scene->getStage("LIGHT_STAGE"); + auto lightStage = context->_scene->getStage(LightStage::getName()); std::vector keyLightStack; if (lightStage && lightStage->_currentFrame._sunLights.size()) { for (auto index : lightStage->_currentFrame._sunLights) { keyLightStack.push_back(lightStage->getLight(index)); } } - // keyLightStack.push_back(lightStage->getLight(0)); std::vector ambientLightStack; if (lightStage && lightStage->_currentFrame._ambientLights.size()) { @@ -151,9 +150,8 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I ambientLightStack.push_back(lightStage->getLight(index)); } } - // ambientLightStack.push_back(lightStage->getLight(0)); - auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); + auto backgroundStage = context->_scene->getStage(BackgroundStage::getName()); std::vector skyboxStack; if (backgroundStage && backgroundStage->_currentFrame._backgrounds.size()) { for (auto index : backgroundStage->_currentFrame._backgrounds) { @@ -162,8 +160,7 @@ void DebugZoneLighting::run(const render::RenderContextPointer& context, const I skyboxStack.push_back(background->getSkybox()); } } - } - // skyboxStack.push_back(backgroundStage->getBackground(0)->getSkybox()); + } gpu::doInBatch(args->_context, [=](gpu::Batch& batch) { diff --git a/tests/gpu-test/src/TestWindow.cpp b/tests/gpu-test/src/TestWindow.cpp index 5b5102701a..39043805b8 100644 --- a/tests/gpu-test/src/TestWindow.cpp +++ b/tests/gpu-test/src/TestWindow.cpp @@ -77,7 +77,6 @@ void TestWindow::initGl() { #ifdef DEFERRED_LIGHTING auto deferredLightingEffect = DependencyManager::get(); deferredLightingEffect->init(); - // deferredLightingEffect->setGlobalLight(_light); initDeferredPipelines(*_shapePlumber); #endif } diff --git a/tests/render-perf/src/main.cpp b/tests/render-perf/src/main.cpp index 2b91a36b48..ce47a896aa 100644 --- a/tests/render-perf/src/main.cpp +++ b/tests/render-perf/src/main.cpp @@ -889,11 +889,6 @@ private: BackgroundRenderData::_item = _main3DScene->allocateID(); transaction.resetItem(BackgroundRenderData::_item, backgroundRenderPayload); } - // Setup the current Zone Entity lighting - { - auto stage = DependencyManager::get()->getSkyStage(); - // DependencyManager::get()->setGlobalLight(stage->getSunLight()); - } { PerformanceTimer perfTimer("SceneProcessTransaction"); @@ -914,8 +909,6 @@ private: PerformanceTimer perfTimer("draw"); // The pending changes collecting the changes here render::Transaction transaction; - // Setup the current Zone Entity lighting - // DependencyManager::get()->setGlobalLight(_sunSkyStage.getSunLight()); { PerformanceTimer perfTimer("SceneProcessTransaction"); _main3DScene->enqueueTransaction(transaction); From a8086764dae94e8195d939d69ed76a03e8d99d2f Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Fri, 7 Jul 2017 12:19:22 +0200 Subject: [PATCH 31/39] REmoving warnings for unused var --- libraries/render-utils/src/DeferredLightingEffect.cpp | 6 +++--- libraries/render-utils/src/DeferredLightingEffect.h | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 5f18916a92..7b1ea1768d 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -740,8 +740,8 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { _defaultLight = lp; // Add the global light to the light stage (for later shadow rendering) - auto defaultLightID = lightStage->addLight(lp); - lightStage->addShadow(defaultLightID); + _defaultLightID = lightStage->addLight(lp); + lightStage->addShadow(_defaultLightID); } auto backgroundStage = renderContext->_scene->getStage(); @@ -754,7 +754,7 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) { _defaultBackground = background; // Add the global light to the light stage (for later shadow rendering) - auto defaultBackgroundID = backgroundStage->addBackground(_defaultBackground); + _defaultBackgroundID = backgroundStage->addBackground(_defaultBackground); } } } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 7fc9600d18..a4d62ea407 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -180,7 +180,9 @@ public: protected: model::LightPointer _defaultLight; + LightStage::Index _defaultLightID{ LightStage::INVALID_INDEX }; model::SunSkyStagePointer _defaultBackground; + BackgroundStage::Index _defaultBackgroundID{ BackgroundStage::INVALID_INDEX }; model::SkyboxPointer _defaultSkybox { new ProceduralSkybox() }; gpu::TexturePointer _defaultSkyboxTexture; gpu::TexturePointer _defaultSkyboxAmbientTexture; From 88c39f3237ecaa00fc713114f86295b00fdafd6b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 7 Jul 2017 09:15:42 -0700 Subject: [PATCH 32/39] off-by-one --- libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 664b9f5959..20a85331d9 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1041,7 +1041,7 @@ int Avatar::getJointIndex(const QString& name) const { withValidJointIndicesCache([&]() { if (_jointIndicesCache.contains(name)) { - result = _jointIndicesCache[name]; + result = _jointIndicesCache[name] - 1; } }); return result; From 6782a891d04c0ae887c68c09386b8d7a0b0d1282 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Fri, 7 Jul 2017 10:35:45 -0700 Subject: [PATCH 33/39] rename the joint-name caches in AvatarData and Avatar so it's more clear that they are different --- .../src/avatars-renderer/Avatar.cpp | 24 +++++++++---------- .../src/avatars-renderer/Avatar.h | 6 ++--- libraries/avatars/src/AvatarData.cpp | 18 +++++++------- libraries/avatars/src/AvatarData.h | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 20a85331d9..7e1e51572f 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1009,23 +1009,23 @@ glm::vec3 Avatar::getAbsoluteJointTranslationInObjectFrame(int index) const { } void Avatar::invalidateJointIndicesCache() const { - QWriteLocker writeLock(&_jointIndicesCacheLock); - _jointsCached = false; + QWriteLocker writeLock(&_modelJointIndicesCacheLock); + _modelJointsCached = false; } void Avatar::withValidJointIndicesCache(std::function const& worker) const { - QReadLocker readLock(&_jointIndicesCacheLock); - if (_jointsCached) { + QReadLocker readLock(&_modelJointIndicesCacheLock); + if (_modelJointsCached) { worker(); } else { readLock.unlock(); { - QWriteLocker writeLock(&_jointIndicesCacheLock); - if (!_jointsCached) { - _jointIndicesCache.clear(); + QWriteLocker writeLock(&_modelJointIndicesCacheLock); + if (!_modelJointsCached) { + _modelJointIndicesCache.clear(); if (_skeletonModel && _skeletonModel->isActive()) { - _jointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; - _jointsCached = true; + _modelJointIndicesCache = _skeletonModel->getFBXGeometry().jointIndices; + _modelJointsCached = true; } } worker(); @@ -1040,8 +1040,8 @@ int Avatar::getJointIndex(const QString& name) const { } withValidJointIndicesCache([&]() { - if (_jointIndicesCache.contains(name)) { - result = _jointIndicesCache[name] - 1; + if (_modelJointIndicesCache.contains(name)) { + result = _modelJointIndicesCache[name] - 1; } }); return result; @@ -1050,7 +1050,7 @@ int Avatar::getJointIndex(const QString& name) const { QStringList Avatar::getJointNames() const { QStringList result; withValidJointIndicesCache([&]() { - result = _jointIndicesCache.keys(); + result = _modelJointIndicesCache.keys(); }); return result; } diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h index ce7e53656e..89db519abc 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.h +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.h @@ -270,9 +270,9 @@ protected: void invalidateJointIndicesCache() const; void withValidJointIndicesCache(std::function const& worker) const; - mutable QHash _jointIndicesCache; - mutable QReadWriteLock _jointIndicesCacheLock; - mutable bool _jointsCached { false }; + mutable QHash _modelJointIndicesCache; + mutable QReadWriteLock _modelJointIndicesCacheLock; + mutable bool _modelJointsCached { false }; glm::vec3 _skeletonOffset; std::vector> _attachmentModels; diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 6eed23fb5b..cc64d21f0f 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -1462,12 +1462,12 @@ int AvatarData::getJointIndex(const QString& name) const { return result; } QReadLocker readLock(&_jointDataLock); - return _jointIndices.value(name) - 1; + return _fstJointIndices.value(name) - 1; } QStringList AvatarData::getJointNames() const { QReadLocker readLock(&_jointDataLock); - return _jointNames; + return _fstJointNames; } glm::quat AvatarData::getOrientationOutbound() const { @@ -1720,14 +1720,14 @@ void AvatarData::setJointMappingsFromNetworkReply() { bool ok; int jointIndex = line.mid(secondSeparatorIndex + 1).trimmed().toInt(&ok); if (ok) { - while (_jointNames.size() < jointIndex + 1) { - _jointNames.append(QString()); + while (_fstJointNames.size() < jointIndex + 1) { + _fstJointNames.append(QString()); } - _jointNames[jointIndex] = jointName; + _fstJointNames[jointIndex] = jointName; } } - for (int i = 0; i < _jointNames.size(); i++) { - _jointIndices.insert(_jointNames.at(i), i + 1); + for (int i = 0; i < _fstJointNames.size(); i++) { + _fstJointIndices.insert(_fstJointNames.at(i), i + 1); } } @@ -1781,8 +1781,8 @@ void AvatarData::sendIdentityPacket() { void AvatarData::updateJointMappings() { { QWriteLocker writeLock(&_jointDataLock); - _jointIndices.clear(); - _jointNames.clear(); + _fstJointIndices.clear(); + _fstJointNames.clear(); _jointData.clear(); } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index d6241c2c50..1f672328ba 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -704,8 +704,8 @@ protected: QString _displayName; QString _sessionDisplayName { }; - QHash _jointIndices; ///< 1-based, since zero is returned for missing keys - QStringList _jointNames; ///< in order of depth-first traversal + QHash _fstJointIndices; ///< 1-based, since zero is returned for missing keys + QStringList _fstJointNames; ///< in order of depth-first traversal quint64 _errorLogExpiry; ///< time in future when to log an error From 420e9233b6e4d15d4969400ebc09db263b534935 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 7 Jul 2017 16:50:28 -0700 Subject: [PATCH 34/39] Revert "fix for invisible avatars after radius ignore" --- .../src/avatars/AvatarMixerClientData.cpp | 3 +++ interface/src/avatar/AvatarManager.cpp | 4 ++++ .../src/avatars-renderer/Avatar.cpp | 3 ++- libraries/avatars/src/AvatarHashMap.cpp | 7 +++++++ libraries/avatars/src/AvatarHashMap.h | 1 + libraries/networking/src/NodeList.cpp | 20 +++++++++++++++++++ libraries/networking/src/NodeList.h | 4 ++++ libraries/networking/src/udt/PacketHeaders.h | 1 + 8 files changed, 42 insertions(+), 1 deletion(-) diff --git a/assignment-client/src/avatars/AvatarMixerClientData.cpp b/assignment-client/src/avatars/AvatarMixerClientData.cpp index a4bf8fa253..4d80bc7d17 100644 --- a/assignment-client/src/avatars/AvatarMixerClientData.cpp +++ b/assignment-client/src/avatars/AvatarMixerClientData.cpp @@ -108,6 +108,9 @@ void AvatarMixerClientData::ignoreOther(SharedNodePointer self, SharedNodePointe void AvatarMixerClientData::removeFromRadiusIgnoringSet(SharedNodePointer self, const QUuid& other) { if (isRadiusIgnoring(other)) { _radiusIgnoredOthers.erase(other); + auto exitingSpaceBubblePacket = NLPacket::create(PacketType::ExitingSpaceBubble, NUM_BYTES_RFC4122_UUID); + exitingSpaceBubblePacket->write(other.toRfc4122()); + DependencyManager::get()->sendUnreliablePacket(*exitingSpaceBubblePacket, *self); } } diff --git a/interface/src/avatar/AvatarManager.cpp b/interface/src/avatar/AvatarManager.cpp index 3272bc3255..c46d61cf68 100644 --- a/interface/src/avatar/AvatarManager.cpp +++ b/interface/src/avatar/AvatarManager.cpp @@ -63,6 +63,7 @@ AvatarManager::AvatarManager(QObject* parent) : packetReceiver.registerListener(PacketType::BulkAvatarData, this, "processAvatarDataPacket"); packetReceiver.registerListener(PacketType::KillAvatar, this, "processKillAvatar"); packetReceiver.registerListener(PacketType::AvatarIdentity, this, "processAvatarIdentityPacket"); + packetReceiver.registerListener(PacketType::ExitingSpaceBubble, this, "processExitingSpaceBubble"); // when we hear that the user has ignored an avatar by session UUID // immediately remove that avatar instead of waiting for the absence of packets from avatar mixer @@ -319,6 +320,9 @@ void AvatarManager::handleRemovedAvatar(const AvatarSharedPointer& removedAvatar if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble) { emit DependencyManager::get()->enteredIgnoreRadius(); + } + if (removalReason == KillAvatarReason::TheirAvatarEnteredYourBubble || removalReason == YourAvatarEnteredTheirBubble) { + DependencyManager::get()->radiusIgnoreNodeBySessionID(avatar->getSessionUUID(), true); } else if (removalReason == KillAvatarReason::AvatarDisconnected) { // remove from node sets, if present DependencyManager::get()->removeFromIgnoreMuteSets(avatar->getSessionUUID()); diff --git a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp index 63009d7a28..d303b2e66d 100644 --- a/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp +++ b/libraries/avatars-renderer/src/avatars-renderer/Avatar.cpp @@ -1440,7 +1440,8 @@ void Avatar::addToScene(AvatarSharedPointer myHandle, const render::ScenePointer if (scene) { auto nodelist = DependencyManager::get(); if (showAvatars - && !nodelist->isIgnoringNode(getSessionUUID())) { + && !nodelist->isIgnoringNode(getSessionUUID()) + && !nodelist->isRadiusIgnoringNode(getSessionUUID())) { render::Transaction transaction; addToScene(myHandle, scene, transaction); scene->enqueueTransaction(transaction); diff --git a/libraries/avatars/src/AvatarHashMap.cpp b/libraries/avatars/src/AvatarHashMap.cpp index 3712080cdb..e8c37bdaa8 100644 --- a/libraries/avatars/src/AvatarHashMap.cpp +++ b/libraries/avatars/src/AvatarHashMap.cpp @@ -170,6 +170,13 @@ void AvatarHashMap::processKillAvatar(QSharedPointer message, S removeAvatar(sessionUUID, reason); } +void AvatarHashMap::processExitingSpaceBubble(QSharedPointer message, SharedNodePointer sendingNode) { + // read the node id + QUuid sessionUUID = QUuid::fromRfc4122(message->readWithoutCopy(NUM_BYTES_RFC4122_UUID)); + auto nodeList = DependencyManager::get(); + nodeList->radiusIgnoreNodeBySessionID(sessionUUID, false); +} + void AvatarHashMap::removeAvatar(const QUuid& sessionUUID, KillAvatarReason removalReason) { QWriteLocker locker(&_hashLock); diff --git a/libraries/avatars/src/AvatarHashMap.h b/libraries/avatars/src/AvatarHashMap.h index 68fc232685..21ea8081c7 100644 --- a/libraries/avatars/src/AvatarHashMap.h +++ b/libraries/avatars/src/AvatarHashMap.h @@ -60,6 +60,7 @@ protected slots: void processAvatarDataPacket(QSharedPointer message, SharedNodePointer sendingNode); void processAvatarIdentityPacket(QSharedPointer message, SharedNodePointer sendingNode); void processKillAvatar(QSharedPointer message, SharedNodePointer sendingNode); + void processExitingSpaceBubble(QSharedPointer message, SharedNodePointer sendingNode); protected: AvatarHashMap(); diff --git a/libraries/networking/src/NodeList.cpp b/libraries/networking/src/NodeList.cpp index 7c479e1bff..262f0318b6 100644 --- a/libraries/networking/src/NodeList.cpp +++ b/libraries/networking/src/NodeList.cpp @@ -241,6 +241,10 @@ void NodeList::reset() { _numNoReplyDomainCheckIns = 0; + // lock and clear our set of radius ignored IDs + _radiusIgnoredSetLock.lockForWrite(); + _radiusIgnoredNodeIDs.clear(); + _radiusIgnoredSetLock.unlock(); // lock and clear our set of ignored IDs _ignoredSetLock.lockForWrite(); _ignoredNodeIDs.clear(); @@ -806,6 +810,22 @@ void NodeList::sendIgnoreRadiusStateToNode(const SharedNodePointer& destinationN sendPacket(std::move(ignorePacket), *destinationNode); } +void NodeList::radiusIgnoreNodeBySessionID(const QUuid& nodeID, bool radiusIgnoreEnabled) { + if (radiusIgnoreEnabled) { + QReadLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // read lock for insert + // add this nodeID to our set of ignored IDs + _radiusIgnoredNodeIDs.insert(nodeID); + } else { + QWriteLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // write lock for unsafe_erase + _radiusIgnoredNodeIDs.unsafe_erase(nodeID); + } +} + +bool NodeList::isRadiusIgnoringNode(const QUuid& nodeID) const { + QReadLocker radiusIgnoredSetLocker{ &_radiusIgnoredSetLock }; // read lock for reading + return _radiusIgnoredNodeIDs.find(nodeID) != _radiusIgnoredNodeIDs.cend(); +} + void NodeList::ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled) { // enumerate the nodes to send a reliable ignore packet to each that can leverage it if (!nodeID.isNull() && _sessionUUID != nodeID) { diff --git a/libraries/networking/src/NodeList.h b/libraries/networking/src/NodeList.h index b3a12153e5..6db760b3ca 100644 --- a/libraries/networking/src/NodeList.h +++ b/libraries/networking/src/NodeList.h @@ -77,6 +77,8 @@ public: void toggleIgnoreRadius() { ignoreNodesInRadius(!getIgnoreRadiusEnabled()); } void enableIgnoreRadius() { ignoreNodesInRadius(true); } void disableIgnoreRadius() { ignoreNodesInRadius(false); } + void radiusIgnoreNodeBySessionID(const QUuid& nodeID, bool radiusIgnoreEnabled); + bool isRadiusIgnoringNode(const QUuid& other) const; void ignoreNodeBySessionID(const QUuid& nodeID, bool ignoreEnabled); bool isIgnoringNode(const QUuid& nodeID) const; void personalMuteNodeBySessionID(const QUuid& nodeID, bool muteEnabled); @@ -164,6 +166,8 @@ private: QTimer _keepAlivePingTimer; bool _requestsDomainListData; + mutable QReadWriteLock _radiusIgnoredSetLock; + tbb::concurrent_unordered_set _radiusIgnoredNodeIDs; mutable QReadWriteLock _ignoredSetLock; tbb::concurrent_unordered_set _ignoredNodeIDs; mutable QReadWriteLock _personalMutedSetLock; diff --git a/libraries/networking/src/udt/PacketHeaders.h b/libraries/networking/src/udt/PacketHeaders.h index 848bfd97cf..6c42193e11 100644 --- a/libraries/networking/src/udt/PacketHeaders.h +++ b/libraries/networking/src/udt/PacketHeaders.h @@ -105,6 +105,7 @@ public: UsernameFromIDReply, ViewFrustum, RequestsDomainListData, + ExitingSpaceBubble, PerAvatarGainSet, EntityScriptGetStatus, EntityScriptGetStatusReply, From 7e9ea596a086fd0a1512938ae1cd7e60742b359b Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 7 Jul 2017 19:07:19 -0700 Subject: [PATCH 35/39] Add more efficient overlay getters, don't use blocking calls --- interface/src/ui/overlays/Overlays.cpp | 41 +++++++++++++++++++++----- interface/src/ui/overlays/Overlays.h | 4 +++ 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index bcf9897dd8..2f22b62306 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -414,20 +414,47 @@ OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { } OverlayPropertyResult Overlays::getProperty(OverlayID id, const QString& property) { - if (QThread::currentThread() != thread()) { - OverlayPropertyResult result; - BLOCKING_INVOKE_METHOD(this, "getProperty", Q_RETURN_ARG(OverlayPropertyResult, result), Q_ARG(OverlayID, id), Q_ARG(QString, property)); - return result; - } - - OverlayPropertyResult result; Overlay::Pointer thisOverlay = getOverlay(id); + OverlayPropertyResult result; if (thisOverlay && thisOverlay->supportsGetProperty()) { result.value = thisOverlay->getProperty(property); } return result; } +OverlayPropertyResult Overlays::getProperties(const OverlayID& id, const QStringList& properties) { + Overlay::Pointer thisOverlay = getOverlay(id); + OverlayPropertyResult result; + if (thisOverlay && thisOverlay->supportsGetProperty()) { + QVariantMap mapResult; + for (const auto& property : properties) { + mapResult.insert(property, thisOverlay->getProperty(property)); + } + result.value = mapResult; + } + return result; +} + +OverlayPropertyResult Overlays::getOverlaysProperties(const QVariant& propertiesById) { + QVariantMap map = propertiesById.toMap(); + OverlayPropertyResult result; + QVariantMap resultMap; + for (const auto& key : map.keys()) { + OverlayID id = OverlayID(key); + QVariantMap overlayResult; + Overlay::Pointer thisOverlay = getOverlay(id); + if (thisOverlay && thisOverlay->supportsGetProperty()) { + QStringList propertiesToFetch = map[key].toStringList(); + for (const auto& property : propertiesToFetch) { + overlayResult[property] = thisOverlay->getProperty(property); + } + } + resultMap[key] = overlayResult; + } + result.value = resultMap; + return result; +} + OverlayPropertyResult::OverlayPropertyResult() { } diff --git a/interface/src/ui/overlays/Overlays.h b/interface/src/ui/overlays/Overlays.h index bfb775b041..100f853a96 100644 --- a/interface/src/ui/overlays/Overlays.h +++ b/interface/src/ui/overlays/Overlays.h @@ -190,6 +190,10 @@ public slots: */ OverlayPropertyResult getProperty(OverlayID id, const QString& property); + OverlayPropertyResult getProperties(const OverlayID& id, const QStringList& properties); + + OverlayPropertyResult getOverlaysProperties(const QVariant& overlaysProperties); + /*jsdoc * Find the closest 3D overlay hit by a pick ray. * From 148eece065c3a8c2dc34daac1f6c8d098d3b0f96 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 7 Jul 2017 13:56:28 -0700 Subject: [PATCH 36/39] Tweak frame timing to avoid overloading the main thread --- interface/src/Application.cpp | 67 ++++++++++++++--------------------- 1 file changed, 26 insertions(+), 41 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 7d397adf96..3cbc6208ad 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2729,56 +2729,41 @@ bool Application::importSVOFromURL(const QString& urlString) { return true; } +bool _renderRequested { false }; + bool Application::event(QEvent* event) { if (!Menu::getInstance()) { return false; } - // Presentation/painting logic - // TODO: Decouple presentation and painting loops - static bool isPaintingThrottled = false; - if ((int)event->type() == (int)Present) { - if (isPaintingThrottled) { - // If painting (triggered by presentation) is hogging the main thread, - // repost as low priority to avoid hanging the GUI. - // This has the effect of allowing presentation to exceed the paint budget by X times and - // only dropping every (1/X) frames, instead of every ceil(X) frames - // (e.g. at a 60FPS target, painting for 17us would fall to 58.82FPS instead of 30FPS). - removePostedEvents(this, Present); - postEvent(this, new QEvent(static_cast(Present)), Qt::LowEventPriority); - isPaintingThrottled = false; + int type = event->type(); + switch (type) { + case Event::Lambda: + static_cast(event)->call(); return true; - } - float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed(); - if (shouldPaint(nsecsElapsed)) { - _lastTimeUpdated.start(); - idle(nsecsElapsed); - postEvent(this, new QEvent(static_cast(Paint)), Qt::HighEventPriority); - } - isPaintingThrottled = true; + case Event::Present: + if (!_renderRequested) { + float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed(); + if (shouldPaint(nsecsElapsed)) { + _renderRequested = true; + _lastTimeUpdated.start(); + idle(nsecsElapsed); + postEvent(this, new QEvent(static_cast(Paint)), Qt::HighEventPriority); + } + } + return true; - return true; - } else if ((int)event->type() == (int)Paint) { - // NOTE: This must be updated as close to painting as possible, - // or AvatarInputs will mysteriously move to the bottom-right - AvatarInputs::getInstance()->update(); + case Event::Paint: + // NOTE: This must be updated as close to painting as possible, + // or AvatarInputs will mysteriously move to the bottom-right + AvatarInputs::getInstance()->update(); + paintGL(); + _renderRequested = false; + return true; - paintGL(); - - isPaintingThrottled = false; - - return true; - } else if ((int)event->type() == (int)Idle) { - float nsecsElapsed = (float)_lastTimeUpdated.nsecsElapsed(); - idle(nsecsElapsed); - - return true; - } - - if ((int)event->type() == (int)Lambda) { - static_cast(event)->call(); - return true; + default: + break; } { From cd11f5cfa6edda943b9015e13d0bc645a6f83024 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Fri, 7 Jul 2017 22:02:56 -0700 Subject: [PATCH 37/39] More tweaks for improved script performance --- interface/src/Application.cpp | 4 ++- interface/src/ui/overlays/Overlays.cpp | 37 +++++++++++--------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3cbc6208ad..565d86cc69 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2751,7 +2751,7 @@ bool Application::event(QEvent* event) { idle(nsecsElapsed); postEvent(this, new QEvent(static_cast(Paint)), Qt::HighEventPriority); } - } + } return true; case Event::Paint: @@ -2759,6 +2759,8 @@ bool Application::event(QEvent* event) { // or AvatarInputs will mysteriously move to the bottom-right AvatarInputs::getInstance()->update(); paintGL(); + // wait for the next present event before starting idle / paint again + removePostedEvents(this, Present); _renderRequested = false; return true; diff --git a/interface/src/ui/overlays/Overlays.cpp b/interface/src/ui/overlays/Overlays.cpp index 2f22b62306..72682fcb8c 100644 --- a/interface/src/ui/overlays/Overlays.cpp +++ b/interface/src/ui/overlays/Overlays.cpp @@ -152,6 +152,7 @@ Overlay::Pointer Overlays::getOverlay(OverlayID id) const { OverlayID Overlays::addOverlay(const QString& type, const QVariant& properties) { if (QThread::currentThread() != thread()) { OverlayID result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "addOverlay", Q_RETURN_ARG(OverlayID, result), Q_ARG(QString, type), Q_ARG(QVariant, properties)); return result; } @@ -220,6 +221,7 @@ OverlayID Overlays::addOverlay(const Overlay::Pointer& overlay) { OverlayID Overlays::cloneOverlay(OverlayID id) { if (QThread::currentThread() != thread()) { OverlayID result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "cloneOverlay", Q_RETURN_ARG(OverlayID, result), Q_ARG(OverlayID, id)); return result; } @@ -315,6 +317,7 @@ void Overlays::deleteOverlay(OverlayID id) { QString Overlays::getOverlayType(OverlayID overlayId) { if (QThread::currentThread() != thread()) { QString result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "getOverlayType", Q_RETURN_ARG(QString, result), Q_ARG(OverlayID, overlayId)); return result; } @@ -329,6 +332,7 @@ QString Overlays::getOverlayType(OverlayID overlayId) { QObject* Overlays::getOverlayObject(OverlayID id) { if (QThread::currentThread() != thread()) { QObject* result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "getOverlayObject", Q_RETURN_ARG(QObject*, result), Q_ARG(OverlayID, id)); return result; } @@ -384,12 +388,6 @@ void Overlays::setParentPanel(OverlayID childId, OverlayID panelId) { #endif OverlayID Overlays::getOverlayAtPoint(const glm::vec2& point) { - if (QThread::currentThread() != thread()) { - OverlayID result; - BLOCKING_INVOKE_METHOD(this, "getOverlayAtPoint", Q_RETURN_ARG(OverlayID, result), Q_ARG(glm::vec2, point)); - return result; - } - if (!_enabled) { return UNKNOWN_OVERLAY_ID; } @@ -486,18 +484,6 @@ RayToOverlayIntersectionResult Overlays::findRayIntersectionInternal(const PickR const QVector& overlaysToInclude, const QVector& overlaysToDiscard, bool visibleOnly, bool collidableOnly) { - if (QThread::currentThread() != thread()) { - RayToOverlayIntersectionResult result; - BLOCKING_INVOKE_METHOD(this, "findRayIntersectionInternal", Q_RETURN_ARG(RayToOverlayIntersectionResult, result), - Q_ARG(PickRay, ray), - Q_ARG(bool, precisionPicking), - Q_ARG(QVector, overlaysToInclude), - Q_ARG(QVector, overlaysToDiscard), - Q_ARG(bool, visibleOnly), - Q_ARG(bool, collidableOnly)); - return result; - } - float bestDistance = std::numeric_limits::max(); bool bestIsFront = false; @@ -616,6 +602,7 @@ void RayToOverlayIntersectionResultFromScriptValue(const QScriptValue& objectVar bool Overlays::isLoaded(OverlayID id) { if (QThread::currentThread() != thread()) { bool result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "isLoaded", Q_RETURN_ARG(bool, result), Q_ARG(OverlayID, id)); return result; } @@ -630,6 +617,7 @@ bool Overlays::isLoaded(OverlayID id) { QSizeF Overlays::textSize(OverlayID id, const QString& text) { if (QThread::currentThread() != thread()) { QSizeF result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "textSize", Q_RETURN_ARG(QSizeF, result), Q_ARG(OverlayID, id), Q_ARG(QString, text)); return result; } @@ -708,6 +696,7 @@ void Overlays::deletePanel(OverlayID panelId) { bool Overlays::isAddedOverlay(OverlayID id) { if (QThread::currentThread() != thread()) { bool result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "isAddedOverlay", Q_RETURN_ARG(bool, result), Q_ARG(OverlayID, id)); return result; } @@ -743,6 +732,7 @@ void Overlays::sendHoverLeaveOverlay(OverlayID id, PointerEvent event) { OverlayID Overlays::getKeyboardFocusOverlay() { if (QThread::currentThread() != thread()) { OverlayID result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "getKeyboardFocusOverlay", Q_RETURN_ARG(OverlayID, result)); return result; } @@ -762,6 +752,7 @@ void Overlays::setKeyboardFocusOverlay(OverlayID id) { float Overlays::width() { if (QThread::currentThread() != thread()) { float result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "width", Q_RETURN_ARG(float, result)); return result; } @@ -773,6 +764,7 @@ float Overlays::width() { float Overlays::height() { if (QThread::currentThread() != thread()) { float result; + PROFILE_RANGE(script, __FUNCTION__); BLOCKING_INVOKE_METHOD(this, "height", Q_RETURN_ARG(float, result)); return result; } @@ -982,10 +974,11 @@ bool Overlays::mouseMoveEvent(QMouseEvent* event) { QVector Overlays::findOverlays(const glm::vec3& center, float radius) { QVector result; - if (QThread::currentThread() != thread()) { - BLOCKING_INVOKE_METHOD(this, "findOverlays", Q_RETURN_ARG(QVector, result), Q_ARG(glm::vec3, center), Q_ARG(float, radius)); - return result; - } + //if (QThread::currentThread() != thread()) { + // PROFILE_RANGE(script, __FUNCTION__); + // BLOCKING_INVOKE_METHOD(this, "findOverlays", Q_RETURN_ARG(QVector, result), Q_ARG(glm::vec3, center), Q_ARG(float, radius)); + // return result; + //} QMutexLocker locker(&_mutex); QMapIterator i(_overlaysWorld); From 4edea433ce0eac525dbda824498511eb29a8cf93 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 10 Jul 2017 12:16:53 +0200 Subject: [PATCH 38/39] Rename the _pipeline into _shapePipeline in the render::Args --- interface/src/ui/overlays/Circle3DOverlay.cpp | 4 ++-- interface/src/ui/overlays/Cube3DOverlay.cpp | 10 +++++----- interface/src/ui/overlays/Shape3DOverlay.cpp | 10 +++++----- interface/src/ui/overlays/Sphere3DOverlay.cpp | 10 +++++----- interface/src/ui/overlays/Text3DOverlay.cpp | 4 ++-- libraries/render-utils/src/MeshPartPayload.cpp | 4 ++-- libraries/render-utils/src/RenderShadowTask.cpp | 6 +++--- libraries/render/src/render/Args.h | 2 +- libraries/render/src/render/DrawTask.cpp | 12 ++++++------ 9 files changed, 31 insertions(+), 31 deletions(-) diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index ae0173f054..827417a912 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -80,8 +80,8 @@ void Circle3DOverlay::render(RenderArgs* args) { Q_ASSERT(args->_batch); auto& batch = *args->_batch; - if (args->_pipeline) { - batch.setPipeline(args->_pipeline->pipeline); + if (args->_shapePipeline) { + batch.setPipeline(args->_shapePipeline->pipeline); } // FIXME: THe line width of _lineWidth is not supported anymore, we ll need a workaround diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 707aabc241..a353545245 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -65,15 +65,15 @@ void Cube3DOverlay::render(RenderArgs* args) { transform.setTranslation(position); transform.setRotation(rotation); auto geometryCache = DependencyManager::get(); - auto pipeline = args->_pipeline; - if (!pipeline) { - pipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); + auto shapePipeline = args->_shapePipeline; + if (!shapePipeline) { + shapePipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); } if (_isSolid) { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderSolidCubeInstance(args, *batch, cubeColor, pipeline); + geometryCache->renderSolidCubeInstance(args, *batch, cubeColor, shapePipeline); } else { geometryCache->bindSimpleProgram(*batch, false, false, false, true, true); if (getIsDashedLine()) { @@ -109,7 +109,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { transform.setScale(dimensions); batch->setModelTransform(transform); - geometryCache->renderWireCubeInstance(args, *batch, cubeColor, pipeline); + geometryCache->renderWireCubeInstance(args, *batch, cubeColor, shapePipeline); } } } diff --git a/interface/src/ui/overlays/Shape3DOverlay.cpp b/interface/src/ui/overlays/Shape3DOverlay.cpp index 72c57565d4..a6fcacc769 100644 --- a/interface/src/ui/overlays/Shape3DOverlay.cpp +++ b/interface/src/ui/overlays/Shape3DOverlay.cpp @@ -45,17 +45,17 @@ void Shape3DOverlay::render(RenderArgs* args) { transform.setTranslation(position); transform.setRotation(rotation); auto geometryCache = DependencyManager::get(); - auto pipeline = args->_pipeline; - if (!pipeline) { - pipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); + auto shapePipeline = args->_shapePipeline; + if (!shapePipeline) { + shapePipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); } transform.setScale(dimensions); batch->setModelTransform(transform); if (_isSolid) { - geometryCache->renderSolidShapeInstance(args, *batch, _shape, cubeColor, pipeline); + geometryCache->renderSolidShapeInstance(args, *batch, _shape, cubeColor, shapePipeline); } else { - geometryCache->renderWireShapeInstance(args, *batch, _shape, cubeColor, pipeline); + geometryCache->renderWireShapeInstance(args, *batch, _shape, cubeColor, shapePipeline); } } } diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 67e11cf1d8..5bbf41eb94 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -44,15 +44,15 @@ void Sphere3DOverlay::render(RenderArgs* args) { batch->setModelTransform(transform); auto geometryCache = DependencyManager::get(); - auto pipeline = args->_pipeline; - if (!pipeline) { - pipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); + auto shapePipeline = args->_shapePipeline; + if (!shapePipeline) { + shapePipeline = _isSolid ? geometryCache->getOpaqueShapePipeline() : geometryCache->getWireShapePipeline(); } if (_isSolid) { - geometryCache->renderSolidSphereInstance(args, *batch, sphereColor, pipeline); + geometryCache->renderSolidSphereInstance(args, *batch, sphereColor, shapePipeline); } else { - geometryCache->renderWireSphereInstance(args, *batch, sphereColor, pipeline); + geometryCache->renderWireSphereInstance(args, *batch, sphereColor, shapePipeline); } } } diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index ed29bc4e1b..4b110b8099 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -137,8 +137,8 @@ void Text3DOverlay::render(RenderArgs* args) { // Text renderer sets its own pipeline, _textRenderer->draw(batch, 0, 0, getText(), textColor, glm::vec2(-1.0f), getDrawInFront()); // so before we continue, we must reset the pipeline - batch.setPipeline(args->_pipeline->pipeline); - args->_pipeline->prepare(batch, args); + batch.setPipeline(args->_shapePipeline->pipeline); + args->_shapePipeline->prepare(batch, args); } const render::ShapeKey Text3DOverlay::getShapeKey() { diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index b16134db5f..f6cb55deed 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -259,7 +259,7 @@ void MeshPartPayload::render(RenderArgs* args) { gpu::Batch& batch = *(args->_batch); - auto locations = args->_pipeline->locations; + auto locations = args->_shapePipeline->locations; assert(locations); // Bind the model transform and the skinCLusterMatrices if needed @@ -583,7 +583,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) { } gpu::Batch& batch = *(args->_batch); - auto locations = args->_pipeline->locations; + auto locations = args->_shapePipeline->locations; assert(locations); bindTransform(batch, locations, args->_renderMode); diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index a817a6abff..5b840bd330 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -68,7 +68,7 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, std::vector skinnedShapeKeys{}; // Iterate through all inShapes and render the unskinned - args->_pipeline = shadowPipeline; + args->_shapePipeline = shadowPipeline; batch.setPipeline(shadowPipeline->pipeline); for (auto items : inShapes) { if (items.first.isSkinned()) { @@ -79,13 +79,13 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, } // Reiterate to render the skinned - args->_pipeline = shadowSkinnedPipeline; + args->_shapePipeline = shadowSkinnedPipeline; batch.setPipeline(shadowSkinnedPipeline->pipeline); for (const auto& key : skinnedShapeKeys) { renderItems(renderContext, inShapes.at(key)); } - args->_pipeline = nullptr; + args->_shapePipeline = nullptr; args->_batch = nullptr; }); } diff --git a/libraries/render/src/render/Args.h b/libraries/render/src/render/Args.h index c2e03d4f46..449a3ac22b 100644 --- a/libraries/render/src/render/Args.h +++ b/libraries/render/src/render/Args.h @@ -103,7 +103,7 @@ namespace render { std::shared_ptr _context; std::shared_ptr _blitFramebuffer; - std::shared_ptr _pipeline; + std::shared_ptr _shapePipeline; QSharedPointer _renderData; std::stack _viewFrustums; glm::ivec4 _viewport { 0.0f, 0.0f, 1.0f, 1.0f }; diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index b6f3440d5c..1153a737a1 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -43,11 +43,11 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons assert(item.getKey().isShape()); auto key = item.getShapeKey() | globalKey; if (key.isValid() && !key.hasOwnPipeline()) { - args->_pipeline = shapeContext->pickPipeline(args, key); - if (args->_pipeline) { + args->_shapePipeline = shapeContext->pickPipeline(args, key); + if (args->_shapePipeline) { item.render(args); } - args->_pipeline = nullptr; + args->_shapePipeline = nullptr; } else if (key.hasOwnPipeline()) { item.render(args); } else { @@ -109,15 +109,15 @@ void render::renderStateSortShapes(const RenderContextPointer& renderContext, // Then render for (auto& pipelineKey : sortedPipelines) { auto& bucket = sortedShapes[pipelineKey]; - args->_pipeline = shapeContext->pickPipeline(args, pipelineKey); - if (!args->_pipeline) { + args->_shapePipeline = shapeContext->pickPipeline(args, pipelineKey); + if (!args->_shapePipeline) { continue; } for (auto& item : bucket) { item.render(args); } } - args->_pipeline = nullptr; + args->_shapePipeline = nullptr; for (auto& item : ownPipelineBucket) { item.render(args); } From 0c3755483b99ecc1a88af17ac9bb8bd1ba598e6a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 10 Jul 2017 12:37:26 +0200 Subject: [PATCH 39/39] adding assert or checks whenever getting a scene stage --- .../entities-renderer/src/RenderableZoneEntityItem.cpp | 2 ++ libraries/render-utils/src/BackgroundStage.cpp | 2 ++ libraries/render-utils/src/DebugDeferredBuffer.cpp | 1 + libraries/render-utils/src/DeferredLightingEffect.cpp | 2 ++ libraries/render-utils/src/LightClusters.cpp | 1 + libraries/render-utils/src/LightPayload.cpp | 2 ++ libraries/render-utils/src/RenderShadowTask.cpp | 3 ++- libraries/render-utils/src/SubsurfaceScattering.cpp | 3 ++- libraries/render-utils/src/ZoneRenderer.cpp | 8 +++++--- 9 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp index a57a6e5d52..eda304ef91 100644 --- a/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableZoneEntityItem.cpp @@ -555,10 +555,12 @@ void RenderableZoneEntityItemMeta::setProceduralUserData(QString userData) { void RenderableZoneEntityItemMeta::render(RenderArgs* args) { if (!_stage) { _stage = args->_scene->getStage(); + assert(_stage); } if (!_backgroundStage) { _backgroundStage = args->_scene->getStage(); + assert(_backgroundStage); } { // Sun diff --git a/libraries/render-utils/src/BackgroundStage.cpp b/libraries/render-utils/src/BackgroundStage.cpp index 5d04f188f1..2ea3683c4a 100644 --- a/libraries/render-utils/src/BackgroundStage.cpp +++ b/libraries/render-utils/src/BackgroundStage.cpp @@ -61,6 +61,8 @@ void DrawBackgroundStage::run(const render::RenderContextPointer& renderContext, // Background rendering decision auto backgroundStage = renderContext->_scene->getStage(); + assert(backgroundStage); + model::SunSkyStagePointer background; model::SkyboxPointer skybox; if (backgroundStage->_currentFrame._backgrounds.size()) { diff --git a/libraries/render-utils/src/DebugDeferredBuffer.cpp b/libraries/render-utils/src/DebugDeferredBuffer.cpp index 8887de81ef..44e2bd290b 100644 --- a/libraries/render-utils/src/DebugDeferredBuffer.cpp +++ b/libraries/render-utils/src/DebugDeferredBuffer.cpp @@ -433,6 +433,7 @@ void DebugDeferredBuffer::run(const RenderContextPointer& renderContext, const I } auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); assert(lightStage->getNumLights() > 0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 7b1ea1768d..2b5fdc1d74 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -429,6 +429,7 @@ void PrepareDeferred::run(const RenderContextPointer& renderContext, const Input // Prepare a fresh Light Frame auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); lightStage->_currentFrame.clear(); } @@ -493,6 +494,7 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Global directional light and ambient pass auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); assert(lightStage->getNumLights() > 0); auto lightAndShadow = lightStage->getLightAndShadow(0); const auto& globalShadow = lightAndShadow.second; diff --git a/libraries/render-utils/src/LightClusters.cpp b/libraries/render-utils/src/LightClusters.cpp index 74209ce951..ab1e194498 100644 --- a/libraries/render-utils/src/LightClusters.cpp +++ b/libraries/render-utils/src/LightClusters.cpp @@ -575,6 +575,7 @@ void LightClusteringPass::run(const render::RenderContextPointer& renderContext, // From the LightStage and the current frame, update the light cluster Grid auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); _lightClusters->updateLightStage(lightStage); _lightClusters->updateLightFrame(lightStage->_currentFrame, lightingModel->isPointLightEnabled(), lightingModel->isSpotLightEnabled()); diff --git a/libraries/render-utils/src/LightPayload.cpp b/libraries/render-utils/src/LightPayload.cpp index 5f7f7236f2..afa17bee19 100644 --- a/libraries/render-utils/src/LightPayload.cpp +++ b/libraries/render-utils/src/LightPayload.cpp @@ -56,6 +56,7 @@ LightPayload::~LightPayload() { void LightPayload::render(RenderArgs* args) { if (!_stage) { _stage = args->_scene->getStage(); + assert(_stage); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { @@ -124,6 +125,7 @@ KeyLightPayload::~KeyLightPayload() { void KeyLightPayload::render(RenderArgs* args) { if (!_stage) { _stage = args->_scene->getStage(); + assert(_stage); } // Do we need to allocate the light in the stage ? if (LightStage::isIndexInvalid(_index)) { diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index 5b840bd330..03a2a4f9b1 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -36,7 +36,7 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, assert(renderContext->args->hasViewFrustum()); auto lightStage = renderContext->_scene->getStage(); - + assert(lightStage); LightStage::Index globalLightIndex { 0 }; const auto globalLight = lightStage->getLight(globalLightIndex); @@ -141,6 +141,7 @@ void RenderShadowTask::configure(const Config& configuration) { void RenderShadowSetup::run(const render::RenderContextPointer& renderContext, Output& output) { auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); const auto globalShadow = lightStage->getShadow(0); // Cache old render args diff --git a/libraries/render-utils/src/SubsurfaceScattering.cpp b/libraries/render-utils/src/SubsurfaceScattering.cpp index d67369774c..1786898e57 100644 --- a/libraries/render-utils/src/SubsurfaceScattering.cpp +++ b/libraries/render-utils/src/SubsurfaceScattering.cpp @@ -532,7 +532,8 @@ void DebugSubsurfaceScattering::run(const render::RenderContextPointer& renderCo - auto lightStage = renderContext->_scene->getStage("LIGHT_STAGE"); + auto lightStage = renderContext->_scene->getStage(); + assert(lightStage); // const auto light = DependencyManager::get()->getLightStage()->getLight(0); const auto light = lightStage->getLight(0); diff --git a/libraries/render-utils/src/ZoneRenderer.cpp b/libraries/render-utils/src/ZoneRenderer.cpp index 8fa243c13b..787ef47282 100644 --- a/libraries/render-utils/src/ZoneRenderer.cpp +++ b/libraries/render-utils/src/ZoneRenderer.cpp @@ -52,19 +52,21 @@ void ZoneRendererTask::build(JobModel& task, const Varying& input, Varying& oupu } void SetupZones::run(const RenderContextPointer& context, const Inputs& inputs) { - auto backgroundStage = context->_scene->getStage("BACKGROUND_STAGE"); + auto backgroundStage = context->_scene->getStage(); + assert(backgroundStage); backgroundStage->_currentFrame.clear(); // call render in the correct order first... render::renderItems(context, inputs); // Finally add the default lights and background: - auto lightStage = context->_scene->getStage("LIGHT_STAGE"); + auto lightStage = context->_scene->getStage(); + assert(lightStage); + lightStage->_currentFrame.pushSunLight(0); lightStage->_currentFrame.pushAmbientLight(0); backgroundStage->_currentFrame.pushBackground(0); - } const gpu::PipelinePointer& DebugZoneLighting::getKeyLightPipeline() {