From 53ffca796f2b4d0408b60eca1e2ddb43f05bf360 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 6 Jul 2017 16:35:40 +0200 Subject: [PATCH] Drafting a better SHape plumber to render the items --- interface/src/Application.cpp | 2 +- libraries/render-utils/src/GeometryCache.cpp | 9 +++++--- libraries/render/src/render/DrawTask.cpp | 2 ++ libraries/render/src/render/ShapePipeline.cpp | 23 ++++++++++++------- libraries/render/src/render/ShapePipeline.h | 20 ++++++++++++---- 5 files changed, 39 insertions(+), 17 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 377819c0a0..3de3e19347 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -345,7 +345,7 @@ public: // Don't actually crash in debug builds, in case this apparent deadlock is simply from // the developer actively debugging code #ifdef NDEBUG - deadlockDetectionCrash(); + // deadlockDetectionCrash(); #endif } } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index dcf90012c1..8c7637faf9 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -459,7 +459,8 @@ _nextID(0) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); - } + }, + nullptr ); GeometryCache::_simpleTransparentPipeline = std::make_shared(getSimplePipeline(false, true, true, false), nullptr, @@ -467,11 +468,13 @@ _nextID(0) { // Set the defaults needed for a simple program batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO, DependencyManager::get()->getWhiteTexture()); - } + }, + nullptr ); GeometryCache::_simpleWirePipeline = std::make_shared(getSimplePipeline(false, false, true, true), nullptr, - [](const render::ShapePipeline&, gpu::Batch& batch) {}); + [](const render::ShapePipeline&, gpu::Batch& batch) {}, + nullptr); } GeometryCache::~GeometryCache() { diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index b6f3440d5c..13d454e393 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -45,6 +45,7 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons if (key.isValid() && !key.hasOwnPipeline()) { args->_pipeline = shapeContext->pickPipeline(args, key); if (args->_pipeline) { + args->_pipeline->prepareShapeItem(args, key, item); item.render(args); } args->_pipeline = nullptr; @@ -114,6 +115,7 @@ void render::renderStateSortShapes(const RenderContextPointer& renderContext, continue; } for (auto& item : bucket) { + args->_pipeline->prepareShapeItem(args, pipelineKey, item); item.render(args); } } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index d51d7f8cb6..e07af139b5 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -18,11 +18,18 @@ using namespace render; void ShapePipeline::prepare(gpu::Batch& batch) { - if (batchSetter) { - batchSetter(*this, batch); + if (_batchSetter) { + _batchSetter(*this, batch); } } +void ShapePipeline::prepareShapeItem(RenderArgs* args, const ShapeKey& key, const Item& shape) { + if (_itemSetter) { + _itemSetter(*this, args, shape); + } +} + + ShapeKey::Filter::Builder::Builder() { _mask.set(OWN_PIPELINE); _mask.set(INVALID); @@ -48,12 +55,12 @@ void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit } void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state, - BatchSetter batchSetter) { - addPipeline(Filter{key}, program, state, batchSetter); + BatchSetter batchSetter, ItemSetter itemSetter) { + addPipeline(Filter{key}, program, state, batchSetter, itemSetter); } void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state, - BatchSetter batchSetter) { + BatchSetter batchSetter, ItemSetter itemSetter) { gpu::Shader::BindingSet slotBindings; slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL)); slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING)); @@ -90,7 +97,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p ShapeKey key{filter._flags}; auto gpuPipeline = gpu::Pipeline::create(program, state); - auto shapePipeline = std::make_shared(gpuPipeline, locations, batchSetter); + auto shapePipeline = std::make_shared(gpuPipeline, locations, batchSetter, itemSetter); addPipelineHelper(filter, key, 0, shapePipeline); } @@ -118,8 +125,8 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke batch->setPipeline(shapePipeline->pipeline); // Run the pipeline's BatchSetter on the passed in batch - if (shapePipeline->batchSetter) { - shapePipeline->batchSetter(*shapePipeline, *batch); + if (shapePipeline->_batchSetter) { + shapePipeline->_batchSetter(*shapePipeline, *batch); } return shapePipeline; diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 434c909198..f846b562c6 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -19,6 +19,7 @@ #include "Args.h" namespace render { +class Item; class ShapeKey { public: @@ -242,8 +243,13 @@ public: using BatchSetter = std::function; - ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) : - pipeline(pipeline), locations(locations), batchSetter(batchSetter) {} + using ItemSetter = std::function; + + ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter, ItemSetter itemSetter) : + pipeline(pipeline), + locations(locations), + _batchSetter(batchSetter), + _itemSetter(itemSetter) {} // 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. @@ -252,10 +258,13 @@ public: gpu::PipelinePointer pipeline; std::shared_ptr locations; + void prepareShapeItem(Args* args, const ShapeKey& key, const Item& shape); + protected: friend class ShapePlumber; - BatchSetter batchSetter; + BatchSetter _batchSetter; + ItemSetter _itemSetter; }; using ShapePipelinePointer = std::shared_ptr; @@ -270,11 +279,12 @@ public: using Locations = Pipeline::Locations; using LocationsPointer = Pipeline::LocationsPointer; using BatchSetter = Pipeline::BatchSetter; + using ItemSetter = Pipeline::ItemSetter; void addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state, - BatchSetter batchSetter = nullptr); + BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr); void addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state, - BatchSetter batchSetter = nullptr); + BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr); const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const;