mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 17:01:06 +02:00
Drafting a better SHape plumber to render the items
This commit is contained in:
parent
d91516c630
commit
53ffca796f
5 changed files with 39 additions and 17 deletions
|
@ -345,7 +345,7 @@ public:
|
||||||
// Don't actually crash in debug builds, in case this apparent deadlock is simply from
|
// Don't actually crash in debug builds, in case this apparent deadlock is simply from
|
||||||
// the developer actively debugging code
|
// the developer actively debugging code
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
deadlockDetectionCrash();
|
// deadlockDetectionCrash();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -459,7 +459,8 @@ _nextID(0) {
|
||||||
// Set the defaults needed for a simple program
|
// Set the defaults needed for a simple program
|
||||||
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
|
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
|
||||||
DependencyManager::get<TextureCache>()->getWhiteTexture());
|
DependencyManager::get<TextureCache>()->getWhiteTexture());
|
||||||
}
|
},
|
||||||
|
nullptr
|
||||||
);
|
);
|
||||||
GeometryCache::_simpleTransparentPipeline =
|
GeometryCache::_simpleTransparentPipeline =
|
||||||
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, true, true, false), nullptr,
|
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, true, true, false), nullptr,
|
||||||
|
@ -467,11 +468,13 @@ _nextID(0) {
|
||||||
// Set the defaults needed for a simple program
|
// Set the defaults needed for a simple program
|
||||||
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
|
batch.setResourceTexture(render::ShapePipeline::Slot::MAP::ALBEDO,
|
||||||
DependencyManager::get<TextureCache>()->getWhiteTexture());
|
DependencyManager::get<TextureCache>()->getWhiteTexture());
|
||||||
}
|
},
|
||||||
|
nullptr
|
||||||
);
|
);
|
||||||
GeometryCache::_simpleWirePipeline =
|
GeometryCache::_simpleWirePipeline =
|
||||||
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, false, true, true), nullptr,
|
std::make_shared<render::ShapePipeline>(getSimplePipeline(false, false, true, true), nullptr,
|
||||||
[](const render::ShapePipeline&, gpu::Batch& batch) {});
|
[](const render::ShapePipeline&, gpu::Batch& batch) {},
|
||||||
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
GeometryCache::~GeometryCache() {
|
GeometryCache::~GeometryCache() {
|
||||||
|
|
|
@ -45,6 +45,7 @@ void renderShape(RenderArgs* args, const ShapePlumberPointer& shapeContext, cons
|
||||||
if (key.isValid() && !key.hasOwnPipeline()) {
|
if (key.isValid() && !key.hasOwnPipeline()) {
|
||||||
args->_pipeline = shapeContext->pickPipeline(args, key);
|
args->_pipeline = shapeContext->pickPipeline(args, key);
|
||||||
if (args->_pipeline) {
|
if (args->_pipeline) {
|
||||||
|
args->_pipeline->prepareShapeItem(args, key, item);
|
||||||
item.render(args);
|
item.render(args);
|
||||||
}
|
}
|
||||||
args->_pipeline = nullptr;
|
args->_pipeline = nullptr;
|
||||||
|
@ -114,6 +115,7 @@ void render::renderStateSortShapes(const RenderContextPointer& renderContext,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (auto& item : bucket) {
|
for (auto& item : bucket) {
|
||||||
|
args->_pipeline->prepareShapeItem(args, pipelineKey, item);
|
||||||
item.render(args);
|
item.render(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,18 @@
|
||||||
using namespace render;
|
using namespace render;
|
||||||
|
|
||||||
void ShapePipeline::prepare(gpu::Batch& batch) {
|
void ShapePipeline::prepare(gpu::Batch& batch) {
|
||||||
if (batchSetter) {
|
if (_batchSetter) {
|
||||||
batchSetter(*this, batch);
|
_batchSetter(*this, batch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ShapePipeline::prepareShapeItem(RenderArgs* args, const ShapeKey& key, const Item& shape) {
|
||||||
|
if (_itemSetter) {
|
||||||
|
_itemSetter(*this, args, shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ShapeKey::Filter::Builder::Builder() {
|
ShapeKey::Filter::Builder::Builder() {
|
||||||
_mask.set(OWN_PIPELINE);
|
_mask.set(OWN_PIPELINE);
|
||||||
_mask.set(INVALID);
|
_mask.set(INVALID);
|
||||||
|
@ -48,12 +55,12 @@ void ShapePlumber::addPipelineHelper(const Filter& filter, ShapeKey key, int bit
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
void ShapePlumber::addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
||||||
BatchSetter batchSetter) {
|
BatchSetter batchSetter, ItemSetter itemSetter) {
|
||||||
addPipeline(Filter{key}, program, state, batchSetter);
|
addPipeline(Filter{key}, program, state, batchSetter, itemSetter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
||||||
BatchSetter batchSetter) {
|
BatchSetter batchSetter, ItemSetter itemSetter) {
|
||||||
gpu::Shader::BindingSet slotBindings;
|
gpu::Shader::BindingSet slotBindings;
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL));
|
slotBindings.insert(gpu::Shader::Binding(std::string("lightingModelBuffer"), Slot::BUFFER::LIGHTING_MODEL));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING));
|
slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), Slot::BUFFER::SKINNING));
|
||||||
|
@ -90,7 +97,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
|
||||||
|
|
||||||
ShapeKey key{filter._flags};
|
ShapeKey key{filter._flags};
|
||||||
auto gpuPipeline = gpu::Pipeline::create(program, state);
|
auto gpuPipeline = gpu::Pipeline::create(program, state);
|
||||||
auto shapePipeline = std::make_shared<Pipeline>(gpuPipeline, locations, batchSetter);
|
auto shapePipeline = std::make_shared<Pipeline>(gpuPipeline, locations, batchSetter, itemSetter);
|
||||||
addPipelineHelper(filter, key, 0, shapePipeline);
|
addPipelineHelper(filter, key, 0, shapePipeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +125,8 @@ const ShapePipelinePointer ShapePlumber::pickPipeline(RenderArgs* args, const Ke
|
||||||
batch->setPipeline(shapePipeline->pipeline);
|
batch->setPipeline(shapePipeline->pipeline);
|
||||||
|
|
||||||
// Run the pipeline's BatchSetter on the passed in batch
|
// Run the pipeline's BatchSetter on the passed in batch
|
||||||
if (shapePipeline->batchSetter) {
|
if (shapePipeline->_batchSetter) {
|
||||||
shapePipeline->batchSetter(*shapePipeline, *batch);
|
shapePipeline->_batchSetter(*shapePipeline, *batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return shapePipeline;
|
return shapePipeline;
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "Args.h"
|
#include "Args.h"
|
||||||
|
|
||||||
namespace render {
|
namespace render {
|
||||||
|
class Item;
|
||||||
|
|
||||||
class ShapeKey {
|
class ShapeKey {
|
||||||
public:
|
public:
|
||||||
|
@ -242,8 +243,13 @@ public:
|
||||||
|
|
||||||
using BatchSetter = std::function<void(const ShapePipeline&, gpu::Batch&)>;
|
using BatchSetter = std::function<void(const ShapePipeline&, gpu::Batch&)>;
|
||||||
|
|
||||||
ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter) :
|
using ItemSetter = std::function<void(const ShapePipeline&, render::Args*, const render::Item&)>;
|
||||||
pipeline(pipeline), locations(locations), batchSetter(batchSetter) {}
|
|
||||||
|
ShapePipeline(gpu::PipelinePointer pipeline, LocationsPointer locations, BatchSetter batchSetter, ItemSetter itemSetter) :
|
||||||
|
pipeline(pipeline),
|
||||||
|
locations(locations),
|
||||||
|
_batchSetter(batchSetter),
|
||||||
|
_itemSetter(itemSetter) {}
|
||||||
|
|
||||||
// Normally, a pipeline is accessed thorugh pickPipeline. If it needs to be set manually,
|
// 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.
|
// after calling setPipeline this method should be called to prepare the pipeline with default buffers.
|
||||||
|
@ -252,10 +258,13 @@ public:
|
||||||
gpu::PipelinePointer pipeline;
|
gpu::PipelinePointer pipeline;
|
||||||
std::shared_ptr<Locations> locations;
|
std::shared_ptr<Locations> locations;
|
||||||
|
|
||||||
|
void prepareShapeItem(Args* args, const ShapeKey& key, const Item& shape);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
friend class ShapePlumber;
|
friend class ShapePlumber;
|
||||||
|
|
||||||
BatchSetter batchSetter;
|
BatchSetter _batchSetter;
|
||||||
|
ItemSetter _itemSetter;
|
||||||
};
|
};
|
||||||
using ShapePipelinePointer = std::shared_ptr<ShapePipeline>;
|
using ShapePipelinePointer = std::shared_ptr<ShapePipeline>;
|
||||||
|
|
||||||
|
@ -270,11 +279,12 @@ public:
|
||||||
using Locations = Pipeline::Locations;
|
using Locations = Pipeline::Locations;
|
||||||
using LocationsPointer = Pipeline::LocationsPointer;
|
using LocationsPointer = Pipeline::LocationsPointer;
|
||||||
using BatchSetter = Pipeline::BatchSetter;
|
using BatchSetter = Pipeline::BatchSetter;
|
||||||
|
using ItemSetter = Pipeline::ItemSetter;
|
||||||
|
|
||||||
void addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
void addPipeline(const Key& key, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
||||||
BatchSetter batchSetter = nullptr);
|
BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr);
|
||||||
void addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
void addPipeline(const Filter& filter, const gpu::ShaderPointer& program, const gpu::StatePointer& state,
|
||||||
BatchSetter batchSetter = nullptr);
|
BatchSetter batchSetter = nullptr, ItemSetter itemSetter = nullptr);
|
||||||
|
|
||||||
const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const;
|
const PipelinePointer pickPipeline(RenderArgs* args, const Key& key) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue