Clean up geometry instanced calls

This commit is contained in:
Zach Pomerantz 2016-02-05 11:22:45 -08:00
parent b0a9c299ed
commit d9132f3973
2 changed files with 19 additions and 43 deletions

View file

@ -548,14 +548,6 @@ void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, siz
_shapes[shape].drawWireInstances(batch, count); _shapes[shape].drawWireInstances(batch, count);
} }
void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
renderShapeInstances(batch, Cube, count, colorBuffer);
}
void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
renderWireShapeInstances(batch, Cube, count, colorBuffer);
}
void GeometryCache::renderCube(gpu::Batch& batch) { void GeometryCache::renderCube(gpu::Batch& batch) {
renderShape(batch, Cube); renderShape(batch, Cube);
} }
@ -564,10 +556,6 @@ void GeometryCache::renderWireCube(gpu::Batch& batch) {
renderWireShape(batch, Cube); renderWireShape(batch, Cube);
} }
void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
renderShapeInstances(batch, Sphere, count, colorBuffer);
}
void GeometryCache::renderSphere(gpu::Batch& batch) { void GeometryCache::renderSphere(gpu::Batch& batch) {
renderShape(batch, Sphere); renderShape(batch, Sphere);
} }
@ -1925,8 +1913,8 @@ uint32_t toCompactColor(const glm::vec4& color) {
static const size_t INSTANCE_COLOR_BUFFER = 0; static const size_t INSTANCE_COLOR_BUFFER = 0;
void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, bool isWire,
const render::ShapePipelinePointer& pipeline, gpu::Batch::NamedBatchData::Function f) { const render::ShapePipelinePointer& pipeline, GeometryCache::Shape shape) {
// Add pipeline to name // Add pipeline to name
std::string instanceName = name + std::to_string(std::hash<render::ShapePipelinePointer>()(pipeline)); std::string instanceName = name + std::to_string(std::hash<render::ShapePipelinePointer>()(pipeline));
@ -1938,27 +1926,26 @@ void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4
} }
// Add call to named buffer // Add call to named buffer
batch.setupNamedCalls(instanceName, [f, pipeline](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { batch.setupNamedCalls(instanceName, [isWire, pipeline, shape](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
batch.setPipeline(pipeline->pipeline); batch.setPipeline(pipeline->pipeline);
pipeline->prepare(batch); pipeline->prepare(batch);
f(batch, data);
if (isWire) {
DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]);
} else {
DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count(), data.buffers[INSTANCE_COLOR_BUFFER]);
}
}); });
} }
void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) {
static const std::string INSTANCE_NAME = __FUNCTION__; static const std::string INSTANCE_NAME = __FUNCTION__;
renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { renderInstances(INSTANCE_NAME, batch, color, false, pipeline, GeometryCache::Sphere);
DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, GeometryCache::Sphere, data.count(),
data.buffers[INSTANCE_COLOR_BUFFER]);
});
} }
void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) {
static const std::string INSTANCE_NAME = __FUNCTION__; static const std::string INSTANCE_NAME = __FUNCTION__;
renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { renderInstances(INSTANCE_NAME, batch, color, true, pipeline, GeometryCache::Sphere);
DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count(),
data.buffers[INSTANCE_COLOR_BUFFER]);
});
} }
// Enable this in a debug build to cause 'box' entities to iterate through all the // Enable this in a debug build to cause 'box' entities to iterate through all the
@ -1995,25 +1982,17 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4&
// For the first half second for a given shape, show the wireframe, for the second half, show the solid. // For the first half second for a given shape, show the wireframe, for the second half, show the solid.
if (fractionalSeconds > 0.5f) { if (fractionalSeconds > 0.5f) {
DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count(), renderInstances(INSTANCE_NAME, batch, color, true, pipeline, shape);
data.buffers[INSTANCE_COLOR_BUFFER]);
} else { } else {
DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count(), renderInstances(INSTANCE_NAME, batch, color, false, pipeline, shape);
data.buffers[INSTANCE_COLOR_BUFFER]);
} }
}); });
#else #else
renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { renderInstances(INSTANCE_NAME, batch, color, false, pipeline, GeometryCache::Cube);
DependencyManager::get<GeometryCache>()->renderCubeInstances(batch, data.count(),
data.buffers[INSTANCE_COLOR_BUFFER]);
});
#endif #endif
} }
void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) { void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color, const render::ShapePipelinePointer& pipeline) {
static const std::string INSTANCE_NAME = __FUNCTION__; static const std::string INSTANCE_NAME = __FUNCTION__;
renderInstances(INSTANCE_NAME, batch, color, pipeline, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) { renderInstances(INSTANCE_NAME, batch, color, true, pipeline, GeometryCache::Cube);
DependencyManager::get<GeometryCache>()->renderWireCubeInstances(batch, data.count(),
data.buffers[INSTANCE_COLOR_BUFFER]);
});
} }

View file

@ -158,7 +158,10 @@ public:
bool emissive = false, bool depthBias = false); bool emissive = false, bool depthBias = false);
render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; } render::ShapePipelinePointer getShapePipeline() { return GeometryCache::_simplePipeline; }
// Static geometry // Static (instanced) geometry
void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer);
void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer);
void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color, void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color,
const render::ShapePipelinePointer& pipeline = _simplePipeline); const render::ShapePipelinePointer& pipeline = _simplePipeline);
void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color, void renderSolidSphereInstance(gpu::Batch& batch, const glm::vec3& color,
@ -188,20 +191,14 @@ public:
} }
// Dynamic geometry // Dynamic geometry
void renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer);
void renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer);
void renderShape(gpu::Batch& batch, Shape shape); void renderShape(gpu::Batch& batch, Shape shape);
void renderWireShape(gpu::Batch& batch, Shape shape); void renderWireShape(gpu::Batch& batch, Shape shape);
size_t getShapeTriangleCount(Shape shape); size_t getShapeTriangleCount(Shape shape);
void renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer);
void renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer);
void renderCube(gpu::Batch& batch); void renderCube(gpu::Batch& batch);
void renderWireCube(gpu::Batch& batch); void renderWireCube(gpu::Batch& batch);
size_t getCubeTriangleCount(); size_t getCubeTriangleCount();
void renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer);
void renderWireSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer);
void renderSphere(gpu::Batch& batch); void renderSphere(gpu::Batch& batch);
void renderWireSphere(gpu::Batch& batch); void renderWireSphere(gpu::Batch& batch);
size_t getSphereTriangleCount(); size_t getSphereTriangleCount();