History

Update GeometryCache to accept gpu::Batch

Ryan Huffman committed 11 years ago

Commit 5abd4bb1 parent 3471c0a4 files · +170 −56Browse files

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

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+89−54
@@ -56,6 +56,12 @@ const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); · 55 unmodified lines
5656 const int NUM_BYTES_PER_INDEX = sizeof(GLushort);
5757
5858 void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) {
59+ gpu::Batch batch;
60+ renderSphere(batch, radius, slices, stacks, color, solid, id);
61+ gpu::GLBackend::renderBatch(batch);
62+}
63+
64+void GeometryCache::renderSphere(gpu::Batch& batch, float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) {
5965 bool registered = (id != UNKNOWN_ID);
6066
6167 Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0));
@@ -279,8 +285,6 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm · 217 unmodified lines
279285 gpu::BufferView normalsView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element);
280286 gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
281287
282− gpu::Batch batch;
283−
284288 batch.setInputFormat(streamFormat);
285289 batch.setInputBuffer(VERTICES_SLOT, verticesView);
286290 batch.setInputBuffer(NORMALS_SLOT, normalsView);
@@ -293,8 +297,6 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm · 6 unmodified lines
293297 batch.drawIndexed(gpu::LINES, indices);
294298 }
295299
296− gpu::GLBackend::renderBatch(batch);
297−
298300 glDisableClientState(GL_VERTEX_ARRAY);
299301 glDisableClientState(GL_COLOR_ARRAY);
300302
@@ -402,7 +404,14 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) · 101 unmodified lines
402404 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
403405 }
404406
407+
405408 void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) {
409+ gpu::Batch batch;
410+ renderGrid(batch, xDivisions, yDivisions, color);
411+ gpu::GLBackend::renderBatch(batch);
412+}
413+
414+void GeometryCache::renderGrid(gpu::Batch& batch, int xDivisions, int yDivisions, const glm::vec4& color) {
406415 IntPair key(xDivisions, yDivisions);
407416 Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions), glm::vec3(color.z, color.y, xDivisions));
408417
@@ -470,15 +479,11 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& · 61 unmodified lines
470479 gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element);
471480 gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
472481
473− gpu::Batch batch;
474−
475482 batch.setInputFormat(streamFormat);
476483 batch.setInputBuffer(VERTICES_SLOT, verticesView);
477484 batch.setInputBuffer(COLOR_SLOT, colorView);
478485 batch.draw(gpu::LINES, vertices, 0);
479486
480− gpu::GLBackend::renderBatch(batch);
481−
482487 glDisableClientState(GL_VERTEX_ARRAY);
483488 glDisableClientState(GL_COLOR_ARRAY);
484489
@@ -486,9 +491,15 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& · 1 unmodified line
486491
487492 }
488493
494+void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) {
495+ gpu::Batch batch;
496+ renderGrid(x, y, width, height, rows, cols, color, id);
497+ gpu::GLBackend::renderBatch(batch);
498+}
499+
489500 // TODO: properly handle the x,y,w,h changing for an ID
490501 // TODO: why do we seem to create extra BatchItemDetails when we resize the window?? what's that??
491−void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) {
502+void GeometryCache::renderGrid(gpu::Batch& batch, int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) {
492503 #ifdef WANT_DEBUG
493504 qCDebug(renderutils) << "GeometryCache::renderGrid(x["<<x<<"], "
494505 "y["<<y<<"],"
@@ -580,16 +591,12 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in · 85 unmodified lines
580591
581592 gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element);
582593 gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
583−
584− gpu::Batch batch;
585594
586595 batch.setInputFormat(streamFormat);
587596 batch.setInputBuffer(VERTICES_SLOT, verticesView);
588597 batch.setInputBuffer(COLOR_SLOT, colorView);
589598 batch.draw(gpu::LINES, vertices, 0);
590599
591− gpu::GLBackend::renderBatch(batch);
592−
593600 glDisableClientState(GL_VERTEX_ARRAY);
594601 glDisableClientState(GL_COLOR_ARRAY);
595602
@@ -810,6 +817,12 @@ void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { · 214 unmodified lines
810817 }
811818
812819 void GeometryCache::renderSolidCube(float size, const glm::vec4& color) {
820+ gpu::Batch batch;
821+ renderSolidCube(batch, size, color);
822+ gpu::GLBackend::renderBatch(batch);
823+}
824+
825+void GeometryCache::renderSolidCube(gpu::Batch& batch, float size, const glm::vec4& color) {
813826 Vec2Pair colorKey(glm::vec2(color.x, color.y), glm::vec2(color.z, color.y));
814827 const int FLOATS_PER_VERTEX = 3;
815828 const int VERTICES_PER_FACE = 4;
@@ -915,8 +928,6 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { · 99 unmodified lines
915928 gpu::BufferView normalsView(verticesBuffer, NORMALS_OFFSET, verticesBuffer->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element);
916929 gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
917930
918− gpu::Batch batch;
919−
920931 batch.setInputFormat(streamFormat);
921932 batch.setInputBuffer(VERTICES_SLOT, verticesView);
922933 batch.setInputBuffer(NORMALS_SLOT, normalsView);
@@ -924,8 +935,6 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { · 1 unmodified line
924935 batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0);
925936 batch.drawIndexed(gpu::TRIANGLES, indices);
926937
927− gpu::GLBackend::renderBatch(batch);
928−
929938 glDisableClientState(GL_VERTEX_ARRAY);
930939 glDisableClientState(GL_COLOR_ARRAY);
931940
@@ -934,6 +943,12 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { · 2 unmodified lines
934943 }
935944
936945 void GeometryCache::renderWireCube(float size, const glm::vec4& color) {
946+ gpu::Batch batch;
947+ renderWireCube(batch, size, color);
948+ gpu::GLBackend::renderBatch(batch);
949+}
950+
951+void GeometryCache::renderWireCube(gpu::Batch& batch, float size, const glm::vec4& color) {
937952 Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y));
938953 const int FLOATS_PER_VERTEX = 3;
939954 const int VERTICES_PER_EDGE = 2;
@@ -1003,16 +1018,12 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { · 63 unmodified lines
10031018 gpu::BufferView verticesView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element);
10041019 gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element);
10051020
1006− gpu::Batch batch;
1007−
10081021 batch.setInputFormat(streamFormat);
10091022 batch.setInputBuffer(VERTICES_SLOT, verticesView);
10101023 batch.setInputBuffer(COLOR_SLOT, colorView);
10111024 batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0);
10121025 batch.drawIndexed(gpu::LINES, indices);
10131026
1014− gpu::GLBackend::renderBatch(batch);
1015−
10161027 glDisableClientState(GL_VERTEX_ARRAY);
10171028 glDisableClientState(GL_COLOR_ARRAY);
10181029
@@ -1021,6 +1032,12 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { · 2 unmodified lines
10211032 }
10221033
10231034 void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) {
1035+ gpu::Batch batch;
1036+ renderBevelCornersRect(batch, x, y, width, height, bevelDistance, color, id);
1037+ gpu::GLBackend::renderBatch(batch);
1038+}
1039+
1040+void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) {
10241041 bool registered = (id != UNKNOWN_ID);
10251042 Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance));
10261043 BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key];
@@ -1113,14 +1130,10 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, · 86 unmodified lines
11131130 delete[] vertexBuffer;
11141131 }
11151132
1116− gpu::Batch batch;
1117−
11181133 batch.setInputFormat(details.streamFormat);
11191134 batch.setInputStream(0, *details.stream);
11201135 batch.draw(gpu::QUADS, 4, 0);
11211136
1122− gpu::GLBackend::renderBatch(batch);
1123−
11241137 glDisableClientState(GL_VERTEX_ARRAY);
11251138 glDisableClientState(GL_COLOR_ARRAY);
11261139
@@ -1128,6 +1141,12 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, · 1 unmodified line
11281141 }
11291142
11301143 void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {
1144+ gpu::Batch batch;
1145+ renderQuad(batch, minCorner, maxCorner, color, id);
1146+ gpu::GLBackend::renderBatch(batch);
1147+}
1148+
1149+void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {
11311150 bool registered = (id != UNKNOWN_ID);
11321151 Vec4Pair key(glm::vec4(minCorner.x, minCorner.y, maxCorner.x, maxCorner.y), color);
11331152 BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key];
@@ -1193,14 +1212,10 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 59 unmodified lines
11931212 details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
11941213 }
11951214
1196− gpu::Batch batch;
1197−
11981215 batch.setInputFormat(details.streamFormat);
11991216 batch.setInputStream(0, *details.stream);
12001217 batch.draw(gpu::QUADS, 4, 0);
12011218
1202− gpu::GLBackend::renderBatch(batch);
1203−
12041219 glDisableClientState(GL_VERTEX_ARRAY);
12051220 glDisableClientState(GL_COLOR_ARRAY);
12061221
@@ -1210,6 +1225,14 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 3 unmodified lines
12101225 void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner,
12111226 const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner,
12121227 const glm::vec4& color, int id) {
1228+ gpu::Batch batch;
1229+ renderQuad(batch, minCorner, maxCorner, texCoordMinCorner, texCoordMaxCorner, color, id);
1230+ gpu::GLBackend::renderBatch(batch);
1231+}
1232+
1233+void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec2& minCorner, const glm::vec2& maxCorner,
1234+ const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner,
1235+ const glm::vec4& color, int id) {
12131236
12141237 bool registered = (id != UNKNOWN_ID);
12151238 Vec4PairVec4 key(Vec4Pair(glm::vec4(minCorner.x, minCorner.y, maxCorner.x, maxCorner.y),
@@ -1282,8 +1305,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 66 unmodified lines
12821305 details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
12831306 }
12841307
1285− gpu::Batch batch;
1286−
12871308 // glEnable(GL_TEXTURE_2D);
12881309 //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific...
12891310
@@ -1291,8 +1312,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 1 unmodified line
12911312 batch.setInputStream(0, *details.stream);
12921313 batch.draw(gpu::QUADS, 4, 0);
12931314
1294− gpu::GLBackend::renderBatch(batch);
1295−
12961315 glDisableClientState(GL_VERTEX_ARRAY);
12971316 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
12981317 glDisableClientState(GL_COLOR_ARRAY);
@@ -1303,6 +1322,12 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 4 unmodified lines
13031322 }
13041323
13051324 void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {
1325+ gpu::Batch batch;
1326+ renderQuad(batch, minCorner, maxCorner, color, id);
1327+ gpu::GLBackend::renderBatch(batch);
1328+}
1329+
1330+void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {
13061331 bool registered = (id != UNKNOWN_ID);
13071332 Vec3PairVec4 key(Vec3Pair(minCorner, maxCorner), color);
13081333 BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key];
@@ -1368,14 +1393,10 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC · 59 unmodified lines
13681393 details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
13691394 }
13701395
1371− gpu::Batch batch;
1372−
13731396 batch.setInputFormat(details.streamFormat);
13741397 batch.setInputStream(0, *details.stream);
13751398 batch.draw(gpu::QUADS, 4, 0);
13761399
1377− gpu::GLBackend::renderBatch(batch);
1378−
13791400 glDisableClientState(GL_VERTEX_ARRAY);
13801401 glDisableClientState(GL_COLOR_ARRAY);
13811402
@@ -1387,6 +1408,17 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 5 unmodified lines
13871408 const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
13881409 const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight,
13891410 const glm::vec4& color, int id) {
1411+ gpu::Batch batch;
1412+ renderQuad(batch, topLeft, bottomLeft, bottomRight, topRight, texCoordTopLeft, texCoordBottomLeft,
1413+ texCoordBottomRight, texCoordTopRight, color, id);
1414+ gpu::GLBackend::renderBatch(batch);
1415+}
1416+
1417+void GeometryCache::renderQuad(gpu::Batch& batch, const glm::vec3& topLeft, const glm::vec3& bottomLeft,
1418+ const glm::vec3& bottomRight, const glm::vec3& topRight,
1419+ const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft,
1420+ const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight,
1421+ const glm::vec4& color, int id) {
13901422
13911423 #ifdef WANT_DEBUG
13921424 qCDebug(renderutils) << "renderQuad() vec3 + texture VBO...";
@@ -1470,8 +1502,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 77 unmodified lines
14701502 details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors);
14711503 }
14721504
1473− gpu::Batch batch;
1474−
14751505 glEnable(GL_TEXTURE_2D);
14761506 //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific...
14771507
@@ -1479,8 +1509,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 1 unmodified line
14791509 batch.setInputStream(0, *details.stream);
14801510 batch.draw(gpu::QUADS, 4, 0);
14811511
1482− gpu::GLBackend::renderBatch(batch);
1483−
14841512 glDisableClientState(GL_VERTEX_ARRAY);
14851513 glDisableClientState(GL_TEXTURE_COORD_ARRAY);
14861514 glDisableClientState(GL_COLOR_ARRAY);
@@ -1495,6 +1523,12 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom · 8 unmodified lines
14951523 }
14961524
14971525 void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {
1526+ gpu::Batch batch;
1527+ renderDashedLine(batch, start, end, color, id);
1528+ gpu::GLBackend::renderBatch(batch);
1529+}
1530+
1531+void GeometryCache::renderDashedLine(gpu::Batch& batch, const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {
14981532 bool registered = (id != UNKNOWN_ID);
14991533 Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w)));
15001534 BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key];
@@ -1594,14 +1628,10 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en · 93 unmodified lines
15941628 #endif
15951629 }
15961630
1597− gpu::Batch batch;
1598−
15991631 batch.setInputFormat(details.streamFormat);
16001632 batch.setInputStream(0, *details.stream);
16011633 batch.draw(gpu::LINES, details.vertices, 0);
16021634
1603− gpu::GLBackend::renderBatch(batch);
1604−
16051635 glDisableClientState(GL_VERTEX_ARRAY);
16061636 glDisableClientState(GL_COLOR_ARRAY);
16071637
@@ -1659,6 +1689,13 @@ void GeometryCache::BatchItemDetails::clear() { · 51 unmodified lines
16591689
16601690 void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2,
16611691 const glm::vec4& color1, const glm::vec4& color2, int id) {
1692+ gpu::Batch batch;
1693+ renderLine(batch, p1, p2, color1, color2, id);
1694+ gpu::GLBackend::renderBatch(batch);
1695+}
1696+
1697+void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec3& p1, const glm::vec3& p2,
1698+ const glm::vec4& color1, const glm::vec4& color2, int id) {
16621699
16631700 bool registered = (id != UNKNOWN_ID);
16641701 Vec3Pair key(p1, p2);
@@ -1735,21 +1772,23 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, · 70 unmodified lines
17351772 #endif
17361773 }
17371774
1738− gpu::Batch batch;
1739−
17401775 // this is what it takes to render a quad
17411776 batch.setInputFormat(details.streamFormat);
17421777 batch.setInputStream(0, *details.stream);
17431778 batch.draw(gpu::LINES, 2, 0);
17441779
1745− gpu::GLBackend::renderBatch(batch);
1746−
17471780 glDisableClientState(GL_VERTEX_ARRAY);
17481781 glDisableClientState(GL_COLOR_ARRAY);
17491782 glBindBuffer(GL_ARRAY_BUFFER, 0);
17501783 }
17511784
1752−void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2,
1785+void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) {
1786+ gpu::Batch batch;
1787+ renderLine(batch, p1, p2, color1, color2, id);
1788+ gpu::GLBackend::renderBatch(batch);
1789+}
1790+
1791+void GeometryCache::renderLine(gpu::Batch& batch, const glm::vec2& p1, const glm::vec2& p2,
17531792 const glm::vec4& color1, const glm::vec4& color2, int id) {
17541793
17551794 bool registered = (id != UNKNOWN_ID);
@@ -1827,15 +1866,11 @@ void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, · 71 unmodified lines
18271866 #endif
18281867 }
18291868
1830− gpu::Batch batch;
1831−
18321869 // this is what it takes to render a quad
18331870 batch.setInputFormat(details.streamFormat);
18341871 batch.setInputStream(0, *details.stream);
18351872 batch.draw(gpu::LINES, 2, 0);
18361873
1837− gpu::GLBackend::renderBatch(batch);
1838−
18391874 glDisableClientState(GL_VERTEX_ARRAY);
18401875 glDisableClientState(GL_COLOR_ARRAY);
18411876 glBindBuffer(GL_ARRAY_BUFFER, 0);