History

Update primitive instance rendering calls

Atlante45 committed 10 years ago

Commit 7e8ea4d1 parent 1658c1513 files · +87 −90Browse files

Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 13 files). Show all

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+25−35
@@ -524,24 +524,24 @@ void GeometryCache::renderWireShape(gpu::Batch& batch, Shape shape) { · 523 unmodified lines
524524 _shapes[shape].drawWire(batch);
525525 }
526526
527−void GeometryCache::renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer) {
527+void GeometryCache::renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer) {
528528 batch.setInputFormat(getInstancedSolidStreamFormat());
529529 setupBatchInstance(batch, colorBuffer);
530530 _shapes[shape].drawInstances(batch, count);
531531 }
532532
533−void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer) {
533+void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer) {
534534 batch.setInputFormat(getInstancedSolidStreamFormat());
535535 setupBatchInstance(batch, colorBuffer);
536536 _shapes[shape].drawWireInstances(batch, count);
537537 }
538538
539−void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {
540− renderShapeInstances(batch, Cube, count, transformBuffer, colorBuffer);
539+void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
540+ renderShapeInstances(batch, Cube, count, colorBuffer);
541541 }
542542
543−void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {
544− renderWireShapeInstances(batch, Cube, count, transformBuffer, colorBuffer);
543+void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
544+ renderWireShapeInstances(batch, Cube, count, colorBuffer);
545545 }
546546
547547 void GeometryCache::renderCube(gpu::Batch& batch) {
@@ -552,8 +552,8 @@ void GeometryCache::renderWireCube(gpu::Batch& batch) { · 4 unmodified lines
552552 renderWireShape(batch, Cube);
553553 }
554554
555−void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {
556− renderShapeInstances(batch, Sphere, count, transformBuffer, colorBuffer);
555+void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
556+ renderShapeInstances(batch, Sphere, count, colorBuffer);
557557 }
558558
559559 void GeometryCache::renderSphere(gpu::Batch& batch) {
@@ -1854,37 +1854,31 @@ static const size_t INSTANCE_TRANSFORM_BUFFER = 0; · 1294 unmodified lines
18541854 static const size_t INSTANCE_COLOR_BUFFER = 1;
18551855
18561856 template <typename F>
1857−void renderInstances(const std::string& name, gpu::Batch& batch, const Transform& transform, const glm::vec4& color, F f) {
1857+void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, F f) {
18581858 {
1859− gpu::BufferPointer instanceTransformBuffer = batch.getNamedBuffer(name, INSTANCE_TRANSFORM_BUFFER);
1860− glm::mat4 glmTransform;
1861− instanceTransformBuffer->append(transform.getMatrix(glmTransform));
1862−
18631859 gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER);
18641860 auto compactColor = toCompactColor(color);
18651861 instanceColorBuffer->append(compactColor);
18661862 }
18671863
18681864 batch.setupNamedCalls(name, [f](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1869− auto pipeline = DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch);
1865+ DependencyManager::get<GeometryCache>()->bindSimpleProgram(batch);
18701866 f(batch, data);
18711867 });
18721868 }
18731869
1874−void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {
1870+void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color) {
18751871 static const std::string INSTANCE_NAME = __FUNCTION__;
1876− renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1877− DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, GeometryCache::Sphere, data.count,
1878− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1872+ renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1873+ DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, GeometryCache::Sphere, data.count(),
18791874 data.buffers[INSTANCE_COLOR_BUFFER]);
18801875 });
18811876 }
18821877
1883−void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {
1878+void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color) {
18841879 static const std::string INSTANCE_NAME = __FUNCTION__;
1885− renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1886− DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count,
1887− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1880+ renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1881+ DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count(),
18881882 data.buffers[INSTANCE_COLOR_BUFFER]);
18891883 });
18901884 }
@@ -1893,12 +1887,12 @@ void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const Transform& · 2 unmodified lines
18931887 // available shape types, both solid and wireframes
18941888 //#define DEBUG_SHAPES
18951889
1896−void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {
1890+void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color) {
18971891 static const std::string INSTANCE_NAME = __FUNCTION__;
18981892
18991893 #ifdef DEBUG_SHAPES
19001894 static auto startTime = usecTimestampNow();
1901− renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1895+ renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
19021896
19031897 auto usecs = usecTimestampNow();
19041898 usecs -= startTime;
@@ -1923,29 +1917,25 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const Transform& · 18 unmodified lines
19231917
19241918 // For the first half second for a given shape, show the wireframe, for the second half, show the solid.
19251919 if (fractionalSeconds > 0.5f) {
1926− DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count,
1927− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1920+ DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count(),
19281921 data.buffers[INSTANCE_COLOR_BUFFER]);
19291922 } else {
1930− DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count,
1931− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1923+ DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count(),
19321924 data.buffers[INSTANCE_COLOR_BUFFER]);
19331925 }
19341926 });
19351927 #else
1936− renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1937− DependencyManager::get<GeometryCache>()->renderCubeInstances(batch, data.count,
1938− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1928+ renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1929+ DependencyManager::get<GeometryCache>()->renderCubeInstances(batch, data.count(),
19391930 data.buffers[INSTANCE_COLOR_BUFFER]);
19401931 });
19411932 #endif
19421933 }
19431934
1944−void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {
1935+void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color) {
19451936 static const std::string INSTANCE_NAME = __FUNCTION__;
1946− renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1947− DependencyManager::get<GeometryCache>()->renderWireCubeInstances(batch, data.count,
1948− data.buffers[INSTANCE_TRANSFORM_BUFFER],
1937+ renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1938+ DependencyManager::get<GeometryCache>()->renderWireCubeInstances(batch, data.count(),
19491939 data.buffers[INSTANCE_COLOR_BUFFER]);
19501940 });
19511941 }