Use PipelinePointer for rendering Shape

This commit is contained in:
Zach Pomerantz 2016-01-01 17:53:58 -08:00
parent 59a354ea8c
commit 1a3a9be605
3 changed files with 10 additions and 6 deletions

View file

@ -83,6 +83,9 @@ public:
};
ItemKey(const Builder& builder) : ItemKey(builder._flags) {}
bool isShape() const { return _flags[TYPE_SHAPE]; }
bool isLight() const { return _flags[TYPE_LIGHT]; }
bool isOpaque() const { return !_flags[TRANSLUCENT]; }
bool isTransparent() const { return _flags[TRANSLUCENT]; }

View file

@ -17,7 +17,7 @@ using namespace render;
Shape::PipelineLib _pipelineLip;
const Shape::Pipeline& Shape::_pickPipeline(RenderArgs* args, const Key& key) {
const Shape::PipelinePointer& Shape::_pickPipeline(RenderArgs* args, const Key& key) {
assert(!_pipelineLib.empty());
assert(args);
assert(args->_batch);
@ -27,14 +27,14 @@ const Shape::Pipeline& Shape::_pickPipeline(RenderArgs* args, const Key& key) {
const auto& pipelineIterator = _pipelineLib.find(key);
if (pipelineIterator == _pipelineLib.end()) {
qDebug() << "Couldn't find a pipeline from ShapeKey ?" << key;
return Shape::Pipeline(); // uninitialized _pipeline == nullptr
return std::make_shared<Pipeline>();
}
const auto& shapePipeline = pipelineIterator->second;
Shape::PipelinePointer shapePipeline(&(pipelineIterator->second));
auto& batch = args->_batch;
// Setup the one pipeline (to rule them all)
batch->setPipeline(shapePipeline.pipeline);
batch->setPipeline(shapePipeline->pipeline);
return shapePipeline;
}

View file

@ -152,6 +152,7 @@ class Shape {
public:
using Key = ShapeKey;
using Pipeline = ShapePipeline;
using PipelinePointer = std::shared_ptr<Pipeline>;
using Slots = ShapePipeline::Slots;
using Locations = ShapePipeline::Locations;
@ -164,12 +165,12 @@ public:
static void addPipeline(Key key, gpu::ShaderPointer& vertexShader, gpu::ShaderPointer& pixelShader) {
_pipelineLib.addPipeline(key, vertexShader, pixelShader);
}
virtual const Pipeline& pickPipeline(RenderArgs* args, const Key& key) {
virtual const PipelinePointer& pickPipeline(RenderArgs* args, const Key& key) {
return Shape::_pickPipeline(args, key);
}
protected:
static const Pipeline& _pickPipeline(RenderArgs* args, const Key& key);
static const PipelinePointer& _pickPipeline(RenderArgs* args, const Key& key);
static PipelineLib _pipelineLib;
};