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
524 _shapes[shape].drawWire(batch);524 _shapes[shape].drawWire(batch);
525}525}
526 526
527void GeometryCache::renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer) {527void GeometryCache::renderShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer) {
528 batch.setInputFormat(getInstancedSolidStreamFormat());528 batch.setInputFormat(getInstancedSolidStreamFormat());
529 setupBatchInstance(batch, colorBuffer);529 setupBatchInstance(batch, colorBuffer);
530 _shapes[shape].drawInstances(batch, count);530 _shapes[shape].drawInstances(batch, count);
531}531}
532 532
533void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& transformBuffer, gpu::BufferPointer& colorBuffer) {533void GeometryCache::renderWireShapeInstances(gpu::Batch& batch, Shape shape, size_t count, gpu::BufferPointer& colorBuffer) {
534 batch.setInputFormat(getInstancedSolidStreamFormat());534 batch.setInputFormat(getInstancedSolidStreamFormat());
535 setupBatchInstance(batch, colorBuffer);535 setupBatchInstance(batch, colorBuffer);
536 _shapes[shape].drawWireInstances(batch, count);536 _shapes[shape].drawWireInstances(batch, count);
537}537}
538 538
539void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {539void GeometryCache::renderCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
540 renderShapeInstances(batch, Cube, count, transformBuffer, colorBuffer);540 renderShapeInstances(batch, Cube, count, colorBuffer);
541}541}
542 542
543void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {543void GeometryCache::renderWireCubeInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
544 renderWireShapeInstances(batch, Cube, count, transformBuffer, colorBuffer);544 renderWireShapeInstances(batch, Cube, count, colorBuffer);
545}545}
546 546
547void GeometryCache::renderCube(gpu::Batch& batch) {547void GeometryCache::renderCube(gpu::Batch& batch) {
@@ -552,8 +552,8 @@ void GeometryCache::renderWireCube(gpu::Batch& batch) { · 4 unmodified lines
552 renderWireShape(batch, Cube);552 renderWireShape(batch, Cube);
553}553}
554 554
555void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer transformBuffer, gpu::BufferPointer colorBuffer) {555void GeometryCache::renderSphereInstances(gpu::Batch& batch, size_t count, gpu::BufferPointer colorBuffer) {
556 renderShapeInstances(batch, Sphere, count, transformBuffer, colorBuffer);556 renderShapeInstances(batch, Sphere, count, colorBuffer);
557}557}
558 558
559void GeometryCache::renderSphere(gpu::Batch& batch) {559void GeometryCache::renderSphere(gpu::Batch& batch) {
@@ -1854,37 +1854,31 @@ static const size_t INSTANCE_TRANSFORM_BUFFER = 0; · 1294 unmodified lines
1854static const size_t INSTANCE_COLOR_BUFFER = 1;1854static const size_t INSTANCE_COLOR_BUFFER = 1;
1855 1855
1856template <typename F>1856template <typename F>
1857void renderInstances(const std::string& name, gpu::Batch& batch, const Transform& transform, const glm::vec4& color, F f) {1857void renderInstances(const std::string& name, gpu::Batch& batch, const glm::vec4& color, F f) {
1858 {1858 {
1859 gpu::BufferPointer instanceTransformBuffer = batch.getNamedBuffer(name, INSTANCE_TRANSFORM_BUFFER);
1860 glm::mat4 glmTransform;
1861 instanceTransformBuffer->append(transform.getMatrix(glmTransform));
1862
1863 gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER);1859 gpu::BufferPointer instanceColorBuffer = batch.getNamedBuffer(name, INSTANCE_COLOR_BUFFER);
1864 auto compactColor = toCompactColor(color);1860 auto compactColor = toCompactColor(color);
1865 instanceColorBuffer->append(compactColor);1861 instanceColorBuffer->append(compactColor);
1866 }1862 }
1867 1863
1868 batch.setupNamedCalls(name, [f](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {1864 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);
1870 f(batch, data);1866 f(batch, data);
1871 });1867 });
1872}1868}
1873 1869
1874void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {1870void GeometryCache::renderSolidSphereInstance(gpu::Batch& batch, const glm::vec4& color) {
1875 static const std::string INSTANCE_NAME = __FUNCTION__;1871 static const std::string INSTANCE_NAME = __FUNCTION__;
1876 renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {1872 renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1877 DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, GeometryCache::Sphere, data.count,1873 DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, GeometryCache::Sphere, data.count(),
1878 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1879 data.buffers[INSTANCE_COLOR_BUFFER]);1874 data.buffers[INSTANCE_COLOR_BUFFER]);
1880 });1875 });
1881}1876}
1882 1877
1883void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {1878void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const glm::vec4& color) {
1884 static const std::string INSTANCE_NAME = __FUNCTION__;1879 static const std::string INSTANCE_NAME = __FUNCTION__;
1885 renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {1880 renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1886 DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count,1881 DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, GeometryCache::Sphere, data.count(),
1887 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1888 data.buffers[INSTANCE_COLOR_BUFFER]);1882 data.buffers[INSTANCE_COLOR_BUFFER]);
1889 });1883 });
1890}1884}
@@ -1893,12 +1887,12 @@ void GeometryCache::renderWireSphereInstance(gpu::Batch& batch, const Transform& · 2 unmodified lines
1893// available shape types, both solid and wireframes1887// available shape types, both solid and wireframes
1894//#define DEBUG_SHAPES1888//#define DEBUG_SHAPES
1895 1889
1896void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {1890void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const glm::vec4& color) {
1897 static const std::string INSTANCE_NAME = __FUNCTION__;1891 static const std::string INSTANCE_NAME = __FUNCTION__;
1898 1892
1899#ifdef DEBUG_SHAPES1893#ifdef DEBUG_SHAPES
1900 static auto startTime = usecTimestampNow();1894 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) {
1902 1896
1903 auto usecs = usecTimestampNow();1897 auto usecs = usecTimestampNow();
1904 usecs -= startTime;1898 usecs -= startTime;
@@ -1923,29 +1917,25 @@ void GeometryCache::renderSolidCubeInstance(gpu::Batch& batch, const Transform& · 18 unmodified lines
1923 1917
1924 // For the first half second for a given shape, show the wireframe, for the second half, show the solid.1918 // For the first half second for a given shape, show the wireframe, for the second half, show the solid.
1925 if (fractionalSeconds > 0.5f) {1919 if (fractionalSeconds > 0.5f) {
1926 DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count,1920 DependencyManager::get<GeometryCache>()->renderShapeInstances(batch, shape, data.count(),
1927 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1928 data.buffers[INSTANCE_COLOR_BUFFER]);1921 data.buffers[INSTANCE_COLOR_BUFFER]);
1929 } else {1922 } else {
1930 DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count,1923 DependencyManager::get<GeometryCache>()->renderWireShapeInstances(batch, shape, data.count(),
1931 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1932 data.buffers[INSTANCE_COLOR_BUFFER]);1924 data.buffers[INSTANCE_COLOR_BUFFER]);
1933 }1925 }
1934 });1926 });
1935#else1927#else
1936 renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {1928 renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1937 DependencyManager::get<GeometryCache>()->renderCubeInstances(batch, data.count,1929 DependencyManager::get<GeometryCache>()->renderCubeInstances(batch, data.count(),
1938 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1939 data.buffers[INSTANCE_COLOR_BUFFER]);1930 data.buffers[INSTANCE_COLOR_BUFFER]);
1940 });1931 });
1941#endif1932#endif
1942}1933}
1943 1934
1944void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const Transform& transform, const glm::vec4& color) {1935void GeometryCache::renderWireCubeInstance(gpu::Batch& batch, const glm::vec4& color) {
1945 static const std::string INSTANCE_NAME = __FUNCTION__;1936 static const std::string INSTANCE_NAME = __FUNCTION__;
1946 renderInstances(INSTANCE_NAME, batch, transform, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {1937 renderInstances(INSTANCE_NAME, batch, color, [](gpu::Batch& batch, gpu::Batch::NamedBatchData& data) {
1947 DependencyManager::get<GeometryCache>()->renderWireCubeInstances(batch, data.count,1938 DependencyManager::get<GeometryCache>()->renderWireCubeInstances(batch, data.count(),
1948 data.buffers[INSTANCE_TRANSFORM_BUFFER],
1949 data.buffers[INSTANCE_COLOR_BUFFER]);1939 data.buffers[INSTANCE_COLOR_BUFFER]);
1950 });1940 });
1951}1941}