History

some cleanup

ZappoMan committed 11 years ago

Commit 30f985a1 parent 96317613 files · +59 −64Browse files

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

Unified · Split

libraries/render-utils/src/GeometryCache.cpp+52−61
@@ -38,10 +38,12 @@ GeometryCache::GeometryCache() : · 37 unmodified lines
38}38}
39 39
40GeometryCache::~GeometryCache() {40GeometryCache::~GeometryCache() {
41 qDebug() << "GeometryCache::~GeometryCache()... ";41 #ifdef WANT_DEBUG
42 qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size();42 qDebug() << "GeometryCache::~GeometryCache()... ";
43 qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size();43 qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size();
44 qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population;44 qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size();
45 qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population;
46 #endif //def WANT_DEBUG
45}47}
46 48
47const int NUM_VERTICES_PER_TRIANGLE = 3;49const int NUM_VERTICES_PER_TRIANGLE = 3;
@@ -53,21 +55,16 @@ const int NUM_BYTES_PER_INDEX = sizeof(GLushort); · 5 unmodified lines
53 55
54void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) {56void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) {
55 57
56 Vec2Pair keyRadius(glm::vec2(radius, slices), glm::vec2(stacks, 0));58 Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0));
57 IntPair keySlicesStacks(slices, stacks);59 IntPair slicesStacksKey(slices, stacks);
58
59//qDebug() << " key:" << key;
60//qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks;
61
62 Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks));60 Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks));
63 61
64
65 int vertices = slices * (stacks - 1) + 2; 62 int vertices = slices * (stacks - 1) + 2;
66 int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD;63 int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD;
67 64
68 if (!_sphereVertices.contains(keyRadius)) {65 if (!_sphereVertices.contains(radiusKey)) {
69 gpu::BufferPointer verticesBuffer(new gpu::Buffer());66 gpu::BufferPointer verticesBuffer(new gpu::Buffer());
70 _sphereVertices[keyRadius] = verticesBuffer;67 _sphereVertices[radiusKey] = verticesBuffer;
71 68
72 GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX];69 GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX];
73 GLfloat* vertex = vertexData;70 GLfloat* vertex = vertexData;
@@ -99,17 +96,20 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm · 25 unmodified lines
99 96
100 verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData);97 verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData);
101 delete[] vertexData;98 delete[] vertexData;
102qDebug() << "GeometryCache::renderSphere()... --- CREATING VERTICES BUFFER";
103qDebug() << " radius:" << radius;
104qDebug() << " slices:" << slices;
105qDebug() << " stacks:" << stacks;
106 99
107qDebug() << " _sphereVertices.size():" << _sphereVertices.size();100 #ifdef WANT_DEBUG
101 qDebug() << "GeometryCache::renderSphere()... --- CREATING VERTICES BUFFER";
102 qDebug() << " radius:" << radius;
103 qDebug() << " slices:" << slices;
104 qDebug() << " stacks:" << stacks;
105
106 qDebug() << " _sphereVertices.size():" << _sphereVertices.size();
107 #endif
108 }108 }
109 109
110 if (!_sphereIndices.contains(keySlicesStacks)) {110 if (!_sphereIndices.contains(slicesStacksKey)) {
111 gpu::BufferPointer indicesBuffer(new gpu::Buffer());111 gpu::BufferPointer indicesBuffer(new gpu::Buffer());
112 _sphereIndices[keySlicesStacks] = indicesBuffer;112 _sphereIndices[slicesStacksKey] = indicesBuffer;
113 113
114 GLushort* indexData = new GLushort[indices];114 GLushort* indexData = new GLushort[indices];
115 GLushort* index = indexData;115 GLushort* index = indexData;
@@ -162,14 +162,16 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); · 46 unmodified lines
162 }162 }
163 indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData);163 indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData);
164 delete[] indexData;164 delete[] indexData;
165qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER";165
166qDebug() << " radius:" << radius;166 #ifdef WANT_DEBUG
167qDebug() << " slices:" << slices;167 qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER";
168qDebug() << " stacks:" << stacks;168 qDebug() << " radius:" << radius;
169qDebug() << "indexCount:" << indexCount;169 qDebug() << " slices:" << slices;
170qDebug() << " indices:" << indices;170 qDebug() << " stacks:" << stacks;
171 171 qDebug() << "indexCount:" << indexCount;
172qDebug() << " _sphereIndices.size():" << _sphereIndices.size();172 qDebug() << " indices:" << indices;
173 qDebug() << " _sphereIndices.size():" << _sphereIndices.size();
174 #endif
173 }175 }
174 176
175 if (!_sphereColors.contains(colorKey)) {177 if (!_sphereColors.contains(colorKey)) {
@@ -191,27 +193,20 @@ qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); · 15 unmodified lines
191 colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData);193 colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData);
192 delete[] colorData;194 delete[] colorData;
193 195
194qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER";196 #ifdef WANT_DEBUG
195qDebug() << " vertices:" << vertices;197 qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER";
196qDebug() << " color:" << color;198 qDebug() << " vertices:" << vertices;
197qDebug() << " slices:" << slices;199 qDebug() << " color:" << color;
198qDebug() << " stacks:" << stacks;200 qDebug() << " slices:" << slices;
199 201 qDebug() << " stacks:" << stacks;
200qDebug() << " _sphereColors.size():" << _sphereColors.size();202 qDebug() << " _sphereColors.size():" << _sphereColors.size();
203 #endif
201 204
202 }205 }
203 gpu::BufferPointer verticesBuffer = _sphereVertices[keyRadius];206 gpu::BufferPointer verticesBuffer = _sphereVertices[radiusKey];
204 gpu::BufferPointer indicesBuffer = _sphereIndices[keySlicesStacks];207 gpu::BufferPointer indicesBuffer = _sphereIndices[slicesStacksKey];
205 gpu::BufferPointer colorBuffer = _sphereColors[colorKey];208 gpu::BufferPointer colorBuffer = _sphereColors[colorKey];
206 209
207 #ifdef WANT_DEBUG
208 qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks;
209 qDebug() << " vertices:" << vertices;
210 qDebug() << " indices:" << indices;
211 qDebug() << " colorBuffer->getSize():" << colorBuffer->getSize();
212 #endif //def WANT_DEBUG
213
214
215 const int VERTICES_SLOT = 0;210 const int VERTICES_SLOT = 0;
216 const int NORMALS_SLOT = 1;211 const int NORMALS_SLOT = 1;
217 const int COLOR_SLOT = 2;212 const int COLOR_SLOT = 2;
@@ -348,8 +343,6 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) · 130 unmodified lines
348}343}
349 344
350void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) {345void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) {
351 //qDebug() << "GeometryCache::renderGrid(xDivisions["<<xDivisions<<"], yDivisions["<<yDivisions<<"])";
352
353 IntPair key(xDivisions, yDivisions);346 IntPair key(xDivisions, yDivisions);
354 Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions),glm::vec3(color.z, color.y, xDivisions));347 Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions),glm::vec3(color.z, color.y, xDivisions));
355 348
@@ -436,13 +429,15 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& · 80 unmodified lines
436// TODO: properly handle the x,y,w,h changing for an ID429// TODO: properly handle the x,y,w,h changing for an ID
437// TODO: why do we seem to create extra BatchItemDetails when we resize the window?? what's that??430// TODO: why do we seem to create extra BatchItemDetails when we resize the window?? what's that??
438void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) {431void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) {
439 qDebug() << "GeometryCache::renderGrid(x["<<x<<"], "432 #ifdef WANT_DEBUG
433 qDebug() << "GeometryCache::renderGrid(x["<<x<<"], "
440 "y["<<y<<"],"434 "y["<<y<<"],"
441 "w["<<width<<"],"435 "w["<<width<<"],"
442 "h["<<height<<"],"436 "h["<<height<<"],"
443 "rows["<<rows<<"],"437 "rows["<<rows<<"],"
444 "cols["<<cols<<"],"438 "cols["<<cols<<"],"
445 " id:"<<id<<")...";439 " id:"<<id<<")...";
440 #endif
446 441
447 bool registered = (id != UNKNOWN_ID);442 bool registered = (id != UNKNOWN_ID);
448 Vec3Pair key(glm::vec3(x, y, width), glm::vec3(height, rows, cols));443 Vec3Pair key(glm::vec3(x, y, width), glm::vec3(height, rows, cols));
@@ -542,7 +537,6 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in · 93 unmodified lines
542}537}
543 538
544void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) {539void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) {
545 //qDebug() << "GeometryCache::updateVertices(vec2.... id=" << id <<")...";
546 BatchItemDetails& details = _registeredVertices[id];540 BatchItemDetails& details = _registeredVertices[id];
547 541
548 if (details.isCreated) {542 if (details.isCreated) {
@@ -605,7 +599,6 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 56 unmodified lines
605}599}
606 600
607void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) {601void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) {
608 //qDebug() << "GeometryCache::updateVertices(id=" << id <<")...";
609 BatchItemDetails& details = _registeredVertices[id];602 BatchItemDetails& details = _registeredVertices[id];
610 603
611 if (details.isCreated) {604 if (details.isCreated) {
@@ -669,8 +662,6 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 57 unmodified lines
669}662}
670 663
671void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) {664void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) {
672 //qDebug() << "GeometryCache::renderVertices(id=" << id <<")...";
673
674 BatchItemDetails& details = _registeredVertices[id];665 BatchItemDetails& details = _registeredVertices[id];
675 if (details.isCreated) {666 if (details.isCreated) {
676 gpu::Batch batch;667 gpu::Batch batch;
@@ -900,7 +891,6 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { · 223 unmodified lines
900}891}
901 892
902void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) {893void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) {
903 //qDebug() << "GeometryCache::renderBevelCornersRect(id=" << id <<")...";
904 bool registered = (id != UNKNOWN_ID);894 bool registered = (id != UNKNOWN_ID);
905 Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance));895 Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance));
906 BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key];896 BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key];
@@ -1008,7 +998,6 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, · 101 unmodified lines
1008}998}
1009 999
1010void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {1000void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) {
1011 //qDebug() << "GeometryCache::renderQuad(vec2,id=" << id <<")...";
1012 bool registered = (id != UNKNOWN_ID);1001 bool registered = (id != UNKNOWN_ID);
1013 Vec2Pair key(minCorner, maxCorner);1002 Vec2Pair key(minCorner, maxCorner);
1014 BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key];1003 BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key];
@@ -1092,7 +1081,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 77 unmodified lines
1092 const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, 1081 const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner,
1093 const glm::vec4& color, int id) {1082 const glm::vec4& color, int id) {
1094 1083
1095 //qDebug() << "GeometryCache::renderQuad(vec2/texture,id=" << id <<")...";
1096 bool registered = (id != UNKNOWN_ID);1084 bool registered = (id != UNKNOWN_ID);
1097 Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner));1085 Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner));
1098 BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key];1086 BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key];
@@ -1183,7 +1171,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC · 84 unmodified lines
1183}1171}
1184 1172
1185void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {1173void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) {
1186 //qDebug() << "GeometryCache::renderQuad(vec3,id=" << id <<")...";
1187 bool registered = (id != UNKNOWN_ID);1174 bool registered = (id != UNKNOWN_ID);
1188 Vec3Pair key(minCorner, maxCorner);1175 Vec3Pair key(minCorner, maxCorner);
1189 BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key];1176 BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key];
@@ -1471,7 +1458,9 @@ GeometryCache::BatchItemDetails::BatchItemDetails() : · 281 unmodified lines
1471 isCreated(false)1458 isCreated(false)
1472{1459{
1473 population++;1460 population++;
1474 qDebug() << "BatchItemDetails()... population:" << population << "**********************************";1461 #ifdef WANT_DEBUG
1462 qDebug() << "BatchItemDetails()... population:" << population << "**********************************";
1463 #endif
1475}1464}
1476 1465
1477GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) :1466GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) :
@@ -1484,13 +1473,17 @@ GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItem · 6 unmodified lines
1484 isCreated(other.isCreated)1473 isCreated(other.isCreated)
1485{1474{
1486 population++;1475 population++;
1487 qDebug() << "BatchItemDetails()... population:" << population << "**********************************";1476 #ifdef WANT_DEBUG
1477 qDebug() << "BatchItemDetails()... population:" << population << "**********************************";
1478 #endif
1488}1479}
1489 1480
1490GeometryCache::BatchItemDetails::~BatchItemDetails() {1481GeometryCache::BatchItemDetails::~BatchItemDetails() {
1491 population--;1482 population--;
1492 clear(); 1483 clear();
1493 qDebug() << "~BatchItemDetails()... population:" << population << "**********************************";1484 #ifdef WANT_DEBUG
1485 qDebug() << "~BatchItemDetails()... population:" << population << "**********************************";
1486 #endif
1494}1487}
1495 1488
1496void GeometryCache::BatchItemDetails::clear() {1489void GeometryCache::BatchItemDetails::clear() {
@@ -1504,7 +1497,6 @@ void GeometryCache::BatchItemDetails::clear() { · 7 unmodified lines
1504void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, 1497void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2,
1505 const glm::vec4& color1, const glm::vec4& color2, int id) {1498 const glm::vec4& color1, const glm::vec4& color2, int id) {
1506 1499
1507 //qDebug() << "GeometryCache::renderLine(vec3)...";
1508 bool registered = (id != UNKNOWN_ID);1500 bool registered = (id != UNKNOWN_ID);
1509 Vec3Pair key(p1, p2);1501 Vec3Pair key(p1, p2);
1510 1502
@@ -1597,7 +1589,6 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, · 86 unmodified lines
1597void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, 1589void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2,
1598 const glm::vec4& color1, const glm::vec4& color2, int id) {1590 const glm::vec4& color1, const glm::vec4& color2, int id) {
1599 1591
1600 //qDebug() << "GeometryCache::renderLine(vec2)...";
1601 bool registered = (id != UNKNOWN_ID);1592 bool registered = (id != UNKNOWN_ID);
1602 Vec2Pair key(p1, p2);1593 Vec2Pair key(p1, p2);
1603 1594

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t