Fix render::Shape::Pipeline ownership by storing shared_ptr in map

This commit is contained in:
Zach Pomerantz 2016-01-05 14:22:00 -08:00
parent ad329a9331
commit df54d1dcc9
2 changed files with 20 additions and 16 deletions

View file

@ -30,7 +30,7 @@ const Shape::PipelinePointer Shape::_pickPipeline(RenderArgs* args, const Key& k
return PipelinePointer(nullptr);
}
PipelinePointer shapePipeline(&(pipelineIterator->second));
PipelinePointer shapePipeline(pipelineIterator->second);
auto& batch = args->_batch;
// Setup the one pipeline (to rule them all)
@ -86,7 +86,7 @@ void Shape::PipelineLib::addPipeline(Key key, gpu::ShaderPointer& vertexShader,
// Add the brand new pipeline and cache its location in the lib
auto pipeline = gpu::Pipeline::create(program, state);
insert(value_type(key, Pipeline(pipeline, locations)));
insert(value_type(key, std::make_shared<Pipeline>(pipeline, locations)));
// Add a wireframe version
if (!key.isWireFrame()) {
@ -96,6 +96,6 @@ void Shape::PipelineLib::addPipeline(Key key, gpu::ShaderPointer& vertexShader,
wireframeState->setFillMode(gpu::State::FILL_LINE);
auto wireframePipeline = gpu::Pipeline::create(program, wireframeState);
insert(value_type(wireframeKey, Pipeline(wireframePipeline, locations)));
insert(value_type(wireframeKey, std::make_shared<Pipeline>(wireframePipeline, locations)));
}
}

View file

@ -95,18 +95,22 @@ public:
};
inline QDebug operator<<(QDebug debug, const ShapeKey& renderKey) {
debug << "[ShapeKey:"
<< "hasLightmap:" << renderKey.hasLightmap()
<< "hasTangents:" << renderKey.hasTangents()
<< "hasSpecular:" << renderKey.hasSpecular()
<< "hasEmissive:" << renderKey.hasEmissive()
<< "isTranslucent:" << renderKey.isTranslucent()
<< "isSkinned:" << renderKey.isSkinned()
<< "isStereo:" << renderKey.isStereo()
<< "isDepthOnly:" << renderKey.isDepthOnly()
<< "isShadow:" << renderKey.isShadow()
<< "isWireFrame:" << renderKey.isWireFrame()
<< "]";
if (renderKey.isValid()) {
debug << "[ShapeKey:"
<< "hasLightmap:" << renderKey.hasLightmap()
<< "hasTangents:" << renderKey.hasTangents()
<< "hasSpecular:" << renderKey.hasSpecular()
<< "hasEmissive:" << renderKey.hasEmissive()
<< "isTranslucent:" << renderKey.isTranslucent()
<< "isSkinned:" << renderKey.isSkinned()
<< "isStereo:" << renderKey.isStereo()
<< "isDepthOnly:" << renderKey.isDepthOnly()
<< "isShadow:" << renderKey.isShadow()
<< "isWireFrame:" << renderKey.isWireFrame()
<< "]";
} else {
debug << "[ShapeKey: INVALID]";
}
return debug;
}
@ -157,7 +161,7 @@ public:
using Slots = ShapePipeline::Slots;
using Locations = ShapePipeline::Locations;
using PipelineMap = std::unordered_map<ShapeKey, Pipeline, ShapeKey::Hash, ShapeKey::KeyEqual>;
using PipelineMap = std::unordered_map<ShapeKey, PipelinePointer, ShapeKey::Hash, ShapeKey::KeyEqual>;
class PipelineLib : public PipelineMap {
public:
void addPipeline(Key key, gpu::ShaderPointer& vertexShader, gpu::ShaderPointer& pixelShader);