Move instanced pipeline setup to lambda from batch

This commit is contained in:
Zach Pomerantz 2016-02-04 15:32:28 -08:00
parent cb06d4a9e4
commit f0797d8ea0
4 changed files with 10 additions and 14 deletions

View file

@ -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);
}

View file

@ -1925,16 +1925,19 @@ uint32_t toCompactColor(const glm::vec4& color) {
static const size_t INSTANCE_COLOR_BUFFER = 0;
template <typename F>
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);
});
}

View file

@ -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) {

View file

@ -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> locations;