Split renderItems to Lights/Shapes

This commit is contained in:
Zach Pomerantz 2016-01-04 13:12:06 -08:00 committed by Zach Pomerantz
parent 7913ca7f3b
commit dfcb74c3be
3 changed files with 37 additions and 33 deletions

View file

@ -193,7 +193,7 @@ void DrawOpaqueDeferred::run(const SceneContextPointer& sceneContext, const Rend
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderItems(sceneContext, renderContext, this, inItems, opaque.maxDrawn);
renderShapes(sceneContext, renderContext, this, inItems, opaque.maxDrawn);
args->_batch = nullptr;
});
}
@ -219,7 +219,7 @@ void DrawTransparentDeferred::run(const SceneContextPointer& sceneContext, const
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderItems(sceneContext, renderContext, this, inItems, transparent.maxDrawn);
renderShapes(sceneContext, renderContext, this, 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);
renderItems(sceneContext, renderContext, this, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
renderShapes(sceneContext, renderContext, this, inItems, renderContext->getItemsConfig().overlay3D.maxDrawn);
});
args->_batch = nullptr;
args->_whiteTexture.reset();
@ -381,7 +381,7 @@ void DrawBackgroundDeferred::run(const SceneContextPointer& sceneContext, const
batch.setProjectionTransform(projMat);
batch.setViewTransform(viewMat);
renderItems(sceneContext, renderContext, nullptr, inItems);
renderLights(sceneContext, renderContext, inItems);
});
args->_batch = nullptr;
}

View file

@ -209,39 +209,43 @@ void DepthSortItems::run(const SceneContextPointer& sceneContext, const RenderCo
depthSortItems(sceneContext, renderContext, _frontToBack, inItems, outItems);
}
void render::renderItem(RenderArgs* args, const Shape* shapeContext, Item& item) {
if (item.isShape()) {
assert(shapeContext);
const auto& key = item._payload.getShapeKey();
args->_pipeline = shapeContext->pickPipeline(args, key);
if (!args->pipeline) {
return;
}
}
item.render(args);
}
void render::renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems) {
void render::renderLights(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems) {
auto& scene = sceneContext->_scene;
RenderArgs* args = renderContext->getArgs();
// render
if ((maxDrawnItems < 0) || (maxDrawnItems > (int) inItems.size())) {
for (auto itemDetails : inItems) {
auto item = scene->getItem(itemDetails.id);
renderItem(args, shapeContext, item);
for (const auto& itemDetails : inItems) {
const auto& item = scene->getItem(itemDetails.id);
item.render(args);
}
}
void renderShape(RenderArgs* args, const Item& item, const ShapeKey& lastKey) {
assert(item.isShape());
const auto& key = item._payload.getShapeKey();
args->_pipeline = shapeContext->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) {
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);
}
} else {
int numItems = 0;
for (auto itemDetails : inItems) {
auto item = scene->getItem(itemDetails.id);
if (numItems + 1 >= maxDrawnItems) {
renderItem(args, shapeContext, item);
return;
}
renderItem(args, jobContext, item);
for (const auto& itemDetails : inItems) {
numItems++;
const auto& item = scene->getItem(itemDetails.id);
renderShape(args, item);
if (numItems >= maxDrawnItems) {
return;
break;
}
}
}
@ -255,7 +259,6 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext
auto& scene = sceneContext->_scene;
auto& items = scene->getMasterBucket().at(ItemFilter::Builder::light());
ItemIDsBounds inItems;
inItems.reserve(items.size());
for (auto id : items) {
@ -271,7 +274,7 @@ void DrawLight::run(const SceneContextPointer& sceneContext, const RenderContext
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
args->_batch = &batch;
renderItems(sceneContext, renderContext, this, culledItems);
renderLights(sceneContext, renderContext, culledItems);
});
args->_batch = nullptr;
}

View file

@ -222,7 +222,8 @@ 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 renderItems(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Shape* shapeContext, const ItemIDsBounds& inItems, int maxDrawnItems = -1);
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);
class FetchItems {