From f0797d8ea0408b69aaac88dbae8e2acfb61967da Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Thu, 4 Feb 2016 15:32:28 -0800 Subject: [PATCH] Move instanced pipeline setup to lambda from batch --- libraries/gpu/src/gpu/Batch.h | 2 -- libraries/render-utils/src/GeometryCache.cpp | 11 +++++++---- libraries/render/src/render/ShapePipeline.cpp | 5 ----- libraries/render/src/render/ShapePipeline.h | 6 +++--- 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 6b8816d50a..a2ee57759f 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -73,12 +73,10 @@ public: BufferPointers buffers; Function function; DrawCallInfoBuffer drawCallInfos; - Pipeline::Pointer pipeline; size_t count() const { return drawCallInfos.size(); } void process(Batch& batch) { - batch.setPipeline(pipeline); if (function) { function(batch, *this); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index c63d24973f..f943ee6d00 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1925,16 +1925,19 @@ uint32_t toCompactColor(const glm::vec4& color) { static const size_t INSTANCE_COLOR_BUFFER = 0; -template -void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline, F f) { +void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, + const render::ShapePipelinePointer& pipeline, gpu::Batch::NamedBatchData::Function f) { + // Add color to named buffer { gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER); auto compactColor = toCompactColor(color); instanceColorBuffer->append(compactColor); } - + + // Add call to named buffer batch.setupNamedCalls(name, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { - batch.setPipeline(pipeline->get(batch)); + batch.setPipeline(pipeline->pipeline); + pipeline->prepare(batch); f(batch, data); }); } diff --git a/libraries/render/src/render/ShapePipeline.cpp b/libraries/render/src/render/ShapePipeline.cpp index 9108d31757..588b02a316 100644 --- a/libraries/render/src/render/ShapePipeline.cpp +++ b/libraries/render/src/render/ShapePipeline.cpp @@ -22,11 +22,6 @@ ShapeKey::Filter::Builder::Builder() { _mask.set(INVALID); } -gpu::PipelinePointer ShapePipeline::get(gpu::Batch& batch) { - batchSetter(*this, batch); - return this->pipeline; -} - void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit, const PipelinePointer& pipeline) { // Iterate over all keys if (bit < (int)ShapeKey::FlagBit::NUM_FLAGS) { diff --git a/libraries/render/src/render/ShapePipeline.h b/libraries/render/src/render/ShapePipeline.h index 8993fcfcc8..d35f3a500a 100644 --- a/libraries/render/src/render/ShapePipeline.h +++ b/libraries/render/src/render/ShapePipeline.h @@ -223,9 +223,9 @@ public: 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 accessed manually, - // this method preps the pipeline with defaults set by its batchSetter and returns only the gpu::Pipeline. - gpu::PipelinePointer get(gpu::Batch& batch); + // 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) { batchSetter(*this, batch); } gpu::PipelinePointer pipeline; std::shared_ptr locations;