Move shapeContext to jobContext

This commit is contained in:
Zach Pomerantz 2016-01-05 01:18:57 -08:00 committed by Zach Pomerantz
parent dfcb74c3be
commit cf35974f02
6 changed files with 36 additions and 24 deletions

View file

@ -193,7 +193,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderShapes(sceneContext, renderContext, this, inItems, opaque.maxDrawn);
renderShapes(sceneContext, renderContext, _context, inItems, opaque.maxDrawn);
args->_batch = nullptr;
});
}
@ -219,7 +219,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderShapes(sceneContext, renderContext, this, inItems, transparent.maxDrawn);
renderShapes(sceneContext, renderContext, _context, inItems, transparent.maxDrawn);
args->_batch = nullptr;
});
}
@ -292,7 +292,7 @@ void DrawOverlay3D::run(const SceneContextPointer& sceneContext, const RenderCon
batch.setPipeline(getOpaquePipeline());
batch.setResourceTexture(0, args->_whiteTexture);
renderShapes(sceneContext, renderContext, this, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
renderShapes(sceneContext, renderContext, _context, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
});
args->_batch = nullptr;
args->_whiteTexture.reset();

View file

@ -50,14 +50,16 @@ public:
typedef render::Job::Model<ToneMappingDeferred> JobModel;
};
class DrawOpaqueDeferred : public ShapeRender {
class DrawOpaqueDeferred {
class JobContext : public render::Job::Context, public ShapeRender {} _context;
public:
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemIDsBounds& inItems);
typedef render::Job::ModelI<DrawOpaqueDeferred, render::ItemIDsBounds> JobModel;
};
class DrawTransparentDeferred : public ShapeRender {
class DrawTransparentDeferred {
class JobContext : public render::Job::Context, public ShapeRender {} _context;
public:
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const render::ItemIDsBounds& inItems);
@ -81,13 +83,15 @@ public:
typedef render::Job::Model<DrawBackgroundDeferred> JobModel;
};
class DrawOverlay3D : public ShapeRender {
class DrawOverlay3D {
static gpu::PipelinePointer _opaquePipeline; //lazy evaluation hence mutable
class JobContext : public render::Job::Context, public ShapeRender {} _context;
public:
static const gpu::PipelinePointer& getOpaquePipeline();
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
typedef render::Job::Model<DrawOverlay3D> JobModel;
};

View file

@ -37,6 +37,13 @@
#include "model_lightmap_specular_map_frag.h"
#include "model_translucent_frag.h"
void ShapeRender::ShapeRender() {
// TODO: There is probably a cleaner way to init the pipeline that in a derived class
if (_pipelineLib.empty()) {
initPipeline();
}
}
void ShapeRender::initPipeline() {
assert(_pipelineLib.empty());
@ -164,10 +171,6 @@ void ShapeRender::initPipeline() {
const render::PipelinePointer ShapeRender::pickPipeline(RenderArgs* args, Key& key) {
PerformanceTimer perfTimer("ShapeRender::pickPipeline");
// TODO: There is probably a cleaner way to init the pipeline that in a derived class
if (_pipelineLib.empty()) {
initPipeline();
}
auto pipeline = _pickPipeline(args, key);
if (!pipeline) {

View file

@ -18,6 +18,7 @@ class ShapeRender : public render::Shape {
static model::MaterialPointer _collisionHullMaterial;
public:
ShapeRender();
static void initPipeline();
const render::PipelinePointer pickPipeline(RenderArgs* args, Key& key) override;

View file

@ -209,7 +209,7 @@ void DepthSortItems::run(const SceneContextPointer& sceneContext, const RenderCo
depthSortItems(sceneContext, renderContext, _frontToBack, inItems, outItems);
}
void render::renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems) {
void render::renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->getArgs();
@ -219,31 +219,31 @@ void render::renderLights(const SceneContextPointer& sceneContext, const RenderC
}
}
void renderShape(RenderArgs* args, const Item& item, const ShapeKey& lastKey) {
void renderShape(RenderArgs* args, const Job::ContextPointer& jobContext, const Item& item) {
assert(item.isShape());
const auto& key = item._payload.getShapeKey();
args->_pipeline = shapeContext->pickPipeline(args, key);
args->_pipeline = jobContext->pickPipeline(args, key);
// only render with a pipeline
if (args->_pipeline) {
item.render(args);
}
}
void render::renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems) {
void render::renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems, int maxDrawnItems) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->getArgs();
if ((maxDrawnItems < 0) || (maxDrawnItems > (int)inItems.size())) {
for (const auto& itemDetails : inItems) {
const auto& item = scene->getItem(itemDetails.id);
renderShape(args, item);
renderShape(args, jobContext, item);
}
} else {
int numItems = 0;
for (const auto& itemDetails : inItems) {
numItems++;
const auto& item = scene->getItem(itemDetails.id);
renderShape(args, item);
renderShape(args, jobContext, item);
if (numItems >= maxDrawnItems) {
break;
}

View file

@ -57,7 +57,7 @@ public:
void addJobConsumer(const std::shared_ptr<Job>& job) {
_consumerJobs.push_back(job);
}
class Concept {
public:
virtual ~Concept() = default;
@ -101,8 +101,12 @@ public:
_concept->run(sceneContext, renderContext);
}
protected:
public:
class Context {
public:
virtual ShapePipeline pickPipeline(RenderArgs* args, const ShapeKey& key) = 0;
};
using ContextPointer = std::shared_ptr<Context>;
class Concept {
std::string _name;
@ -111,7 +115,7 @@ public:
Concept() : _name() {}
Concept(const std::string& name) : _name(name) {}
virtual ~Concept() = default;
void setName(const std::string& name) { _name = name; }
const std::string& getName() const { return _name; }
@ -175,7 +179,7 @@ public:
const Varying getOutput() const { return _output; }
ModelO(const std::string& name): Concept(name), _output(Output()) {
}
ModelO(const std::string& name, Data data): Concept(name), _data(data), _output(Output()) {}
@ -223,7 +227,7 @@ typedef std::vector<Job> Jobs;
void cullItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems, ItemIDsBounds& outITems);
void depthSortItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, bool frontToBack, const ItemIDsBounds& inItems, ItemIDsBounds& outITems);
void renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemIDsBounds& inItems);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems = -1);
void renderShapes(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Job::ContextPointer& jobContext, const ItemIDsBounds& inItems, int maxDrawnItems = -1);
class FetchItems {
@ -290,7 +294,7 @@ public:
// A map of ItemIDs allowing to create bucket lists of SHAPE type items which are filtered by their
// Material
// Material
class ItemMaterialBucketMap : public std::map<model::MaterialFilter, ItemIDs, model::MaterialFilter::Less> {
public: