From 331d32ef78ea3a8a5b7cf04d375b05d22002ea96 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Fri, 15 Jan 2016 17:17:00 -0800 Subject: [PATCH] Add render Jobs for Shape sorting --- libraries/render/src/render/DrawTask.cpp | 34 ++++++++++++++++++++++-- libraries/render/src/render/DrawTask.h | 15 +++++++++++ libraries/render/src/render/Scene.h | 6 ++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/libraries/render/src/render/DrawTask.cpp b/libraries/render/src/render/DrawTask.cpp index 93cb42c2fd..a2af639c02 100755 --- a/libraries/render/src/render/DrawTask.cpp +++ b/libraries/render/src/render/DrawTask.cpp @@ -182,8 +182,6 @@ void FetchItems::run(const SceneContextPointer& sceneContext, const RenderContex } void DepthSortItems::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ItemIDsBounds& outItems) { - outItems.clear(); - outItems.reserve(inItems.size()); depthSortItems(sceneContext, renderContext, _frontToBack, inItems, outItems); } @@ -215,3 +213,35 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext args->_batch = nullptr; }); } + +void PipelineSortShapes::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ShapesIDsBounds& outShapes) { + auto& scene = sceneContext->_scene; + outShapes.clear(); + + for (const auto& item : inItems) { + auto key = scene->getItem(item.id).getShapeKey(); + auto outItems = outShapes.find(key); + if (outItems == outShapes.end()) { + outItems = outShapes.insert(std::make_pair(key, ItemIDsBounds{})).first; + outItems->second.reserve(inItems.size()); + } + + outItems->second.push_back(item); + } + + for (auto& items : outShapes) { + items.second.shrink_to_fit(); + } +} + +void DepthSortShapes::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapesIDsBounds& inShapes, ShapesIDsBounds& outShapes) { + for (auto& pipeline : inShapes) { + auto& inItems = pipeline.second; + auto outItems = outShapes.find(pipeline.first); + if (outItems == outShapes.end()) { + outItems = outShapes.insert(std::make_pair(pipeline.first, ItemIDsBounds{})).first; + } + + depthSortItems(sceneContext, renderContext, _frontToBack, inItems, outItems->second); + } +} \ No newline at end of file diff --git a/libraries/render/src/render/DrawTask.h b/libraries/render/src/render/DrawTask.h index e043d5f69e..47ce5c8476 100755 --- a/libraries/render/src/render/DrawTask.h +++ b/libraries/render/src/render/DrawTask.h @@ -66,6 +66,21 @@ public: using JobModel = Task::Job::Model; }; +class PipelineSortShapes { +public: + void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ShapesIDsBounds& outShapes); + using JobModel = Task::Job::ModelIO; +}; + +class DepthSortShapes { +public: + bool _frontToBack; + DepthSortShapes(bool frontToBack = true) : _frontToBack(frontToBack) {} + + void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ShapesIDsBounds& inShapes, ShapesIDsBounds& outShapes); + using JobModel = Task::Job::ModelIO; +}; + } #endif // hifi_render_DrawTask_h diff --git a/libraries/render/src/render/Scene.h b/libraries/render/src/render/Scene.h index 567e054a8a..e28225a899 100644 --- a/libraries/render/src/render/Scene.h +++ b/libraries/render/src/render/Scene.h @@ -432,7 +432,11 @@ public: AABox bounds; }; -typedef std::vector< ItemIDAndBounds > ItemIDsBounds; +// A list of items to be passed between rendering jobs +using ItemIDsBounds = std::vector; + +// A map of items by ShapeKey to optimize rendering pipeline assignments +using ShapesIDsBounds = std::unordered_map; // A map of ItemIDSets allowing to create bucket lists of items which are filtering correctly