Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 2 files). Show all
Unified · Split
| @@ -223,8 +223,8 @@ void MetavoxelSystem::render() { · 222 unmodified lines | ||
| 223 | 223 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 224 | 224 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 225 | 225 | |
| 226 | − batch.vertexBuffer->bind(); | |
| 227 | − batch.indexBuffer->bind(); | |
| 226 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 227 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 228 | 228 | |
| 229 | 229 | HeightfieldPoint* point = 0; |
| 230 | 230 | glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex); |
| @@ -245,8 +245,8 @@ void MetavoxelSystem::render() { · 14 unmodified lines | ||
| 245 | 245 | glActiveTexture(GL_TEXTURE0); |
| 246 | 246 | glBindTexture(GL_TEXTURE_2D, 0); |
| 247 | 247 | |
| 248 | − batch.vertexBuffer->release(); | |
| 249 | − batch.indexBuffer->release(); | |
| 248 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 249 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 250 | 250 | |
| 251 | 251 | glPopMatrix(); |
| 252 | 252 | } |
| @@ -273,8 +273,8 @@ void MetavoxelSystem::render() { · 20 unmodified lines | ||
| 273 | 273 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 274 | 274 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 275 | 275 | |
| 276 | − batch.vertexBuffer->bind(); | |
| 277 | − batch.indexBuffer->bind(); | |
| 276 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 277 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 278 | 278 | |
| 279 | 279 | HeightfieldPoint* point = 0; |
| 280 | 280 | glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex); |
| @@ -324,8 +324,8 @@ void MetavoxelSystem::render() { · 43 unmodified lines | ||
| 324 | 324 | glActiveTexture(GL_TEXTURE0); |
| 325 | 325 | glBindTexture(GL_TEXTURE_2D, 0); |
| 326 | 326 | |
| 327 | − batch.vertexBuffer->release(); | |
| 328 | − batch.indexBuffer->release(); | |
| 327 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 328 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 329 | 329 | |
| 330 | 330 | glPopMatrix(); |
| 331 | 331 | } |
| @@ -368,8 +368,8 @@ void MetavoxelSystem::render() { · 36 unmodified lines | ||
| 368 | 368 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 369 | 369 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 370 | 370 | |
| 371 | − batch.vertexBuffer->bind(); | |
| 372 | − batch.indexBuffer->bind(); | |
| 371 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 372 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 373 | 373 | |
| 374 | 374 | VoxelPoint* point = 0; |
| 375 | 375 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); |
| @@ -378,8 +378,8 @@ void MetavoxelSystem::render() { · 2 unmodified lines | ||
| 378 | 378 | |
| 379 | 379 | glDrawRangeElements(GL_QUADS, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0); |
| 380 | 380 | |
| 381 | − batch.vertexBuffer->release(); | |
| 382 | − batch.indexBuffer->release(); | |
| 381 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 382 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 383 | 383 | |
| 384 | 384 | glPopMatrix(); |
| 385 | 385 | } |
| @@ -409,8 +409,8 @@ void MetavoxelSystem::render() { · 23 unmodified lines | ||
| 409 | 409 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 410 | 410 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 411 | 411 | |
| 412 | − batch.vertexBuffer->bind(); | |
| 413 | − batch.indexBuffer->bind(); | |
| 412 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 413 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 414 | 414 | |
| 415 | 415 | VoxelPoint* point = 0; |
| 416 | 416 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); |
| @@ -453,8 +453,8 @@ void MetavoxelSystem::render() { · 36 unmodified lines | ||
| 453 | 453 | |
| 454 | 454 | glActiveTexture(GL_TEXTURE0); |
| 455 | 455 | |
| 456 | − batch.vertexBuffer->release(); | |
| 457 | − batch.indexBuffer->release(); | |
| 456 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 457 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 458 | 458 | |
| 459 | 459 | glPopMatrix(); |
| 460 | 460 | } |
| @@ -492,13 +492,13 @@ void MetavoxelSystem::render() { · 31 unmodified lines | ||
| 492 | 492 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 493 | 493 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 494 | 494 | |
| 495 | − batch.vertexBuffer->bind(); | |
| 495 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 496 | 496 | |
| 497 | 497 | glVertexPointer(3, GL_FLOAT, 0, 0); |
| 498 | 498 | |
| 499 | 499 | glDrawArrays(GL_LINES, 0, batch.vertexCount); |
| 500 | 500 | |
| 501 | − batch.vertexBuffer->release(); | |
| 501 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 502 | 502 | |
| 503 | 503 | glPopMatrix(); |
| 504 | 504 | } |
| @@ -547,6 +547,12 @@ void MetavoxelSystem::deleteTextures(int heightTextureID, int colorTextureID, in · 42 unmodified lines | ||
| 547 | 547 | glDeleteTextures(1, (const GLuint*)&materialTextureID); |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | +void MetavoxelSystem::deleteBuffers(int vertexBufferID, int indexBufferID, int hermiteBufferID) const { | |
| 551 | + glDeleteBuffers(1, (const GLuint*)&vertexBufferID); | |
| 552 | + glDeleteBuffers(1, (const GLuint*)&indexBufferID); | |
| 553 | + glDeleteBuffers(1, (const GLuint*)&hermiteBufferID); | |
| 554 | +} | |
| 555 | + | |
| 550 | 556 | class SpannerRenderVisitor : public SpannerVisitor { |
| 551 | 557 | public: |
| 552 | 558 | |
| @@ -649,8 +655,8 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 96 unmodified lines | ||
| 649 | 655 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 650 | 656 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 651 | 657 | |
| 652 | − batch.vertexBuffer->bind(); | |
| 653 | − batch.indexBuffer->bind(); | |
| 658 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 659 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 654 | 660 | |
| 655 | 661 | HeightfieldPoint* point = 0; |
| 656 | 662 | glVertexPointer(3, GL_FLOAT, sizeof(HeightfieldPoint), &point->vertex); |
| @@ -662,8 +668,8 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 5 unmodified lines | ||
| 662 | 668 | |
| 663 | 669 | glBindTexture(GL_TEXTURE_2D, 0); |
| 664 | 670 | |
| 665 | − batch.vertexBuffer->release(); | |
| 666 | − batch.indexBuffer->release(); | |
| 671 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 672 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 667 | 673 | |
| 668 | 674 | glPopMatrix(); |
| 669 | 675 | } |
| @@ -687,16 +693,16 @@ void MetavoxelSystem::renderHeightfieldCursor(const glm::vec3& position, float r · 17 unmodified lines | ||
| 687 | 693 | glRotatef(glm::degrees(glm::angle(batch.rotation)), axis.x, axis.y, axis.z); |
| 688 | 694 | glScalef(batch.scale.x, batch.scale.y, batch.scale.z); |
| 689 | 695 | |
| 690 | − batch.vertexBuffer->bind(); | |
| 691 | − batch.indexBuffer->bind(); | |
| 696 | + glBindBuffer(GL_ARRAY_BUFFER, batch.vertexBufferID); | |
| 697 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, batch.indexBufferID); | |
| 692 | 698 | |
| 693 | 699 | VoxelPoint* point = 0; |
| 694 | 700 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); |
| 695 | 701 | |
| 696 | 702 | glDrawRangeElements(GL_QUADS, 0, batch.vertexCount - 1, batch.indexCount, GL_UNSIGNED_INT, 0); |
| 697 | 703 | |
| 698 | − batch.vertexBuffer->release(); | |
| 699 | − batch.indexBuffer->release(); | |
| 704 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 705 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 700 | 706 | |
| 701 | 707 | glPopMatrix(); |
| 702 | 708 | } |
| @@ -1033,10 +1039,17 @@ VoxelBuffer::VoxelBuffer(const QVector<VoxelPoint>& vertices, const QVector<int> · 330 unmodified lines | ||
| 1033 | 1039 | _vertexCount(vertices.size()), |
| 1034 | 1040 | _indexCount(indices.size()), |
| 1035 | 1041 | _hermiteCount(hermite.size()), |
| 1036 | − _indexBuffer(QOpenGLBuffer::IndexBuffer), | |
| 1042 | + _vertexBufferID(0), | |
| 1043 | + _indexBufferID(0), | |
| 1044 | + _hermiteBufferID(0), | |
| 1037 | 1045 | _materials(materials) { |
| 1038 | 1046 | } |
| 1039 | 1047 | |
| 1048 | +VoxelBuffer::~VoxelBuffer() { | |
| 1049 | + QMetaObject::invokeMethod(Application::getInstance()->getMetavoxels(), "deleteBuffers", Q_ARG(int, _vertexBufferID), | |
| 1050 | + Q_ARG(int, _indexBufferID), Q_ARG(int, _hermiteBufferID)); | |
| 1051 | +} | |
| 1052 | + | |
| 1040 | 1053 | bool VoxelBuffer::findRayIntersection(const glm::vec3& origin, const glm::vec3& direction, |
| 1041 | 1054 | float boundsDistance, float& distance) const { |
| 1042 | 1055 | float highest = _size - 1.0f; |
| @@ -1106,16 +1119,16 @@ bool VoxelBuffer::findRayIntersection(const glm::vec3& origin, const glm::vec3& · 63 unmodified lines | ||
| 1106 | 1119 | } |
| 1107 | 1120 | |
| 1108 | 1121 | void VoxelBuffer::render(const glm::vec3& translation, const glm::quat& rotation, const glm::vec3& scale, bool cursor) { |
| 1109 | − if (!_vertexBuffer.isCreated()) { | |
| 1110 | − _vertexBuffer.create(); | |
| 1111 | − _vertexBuffer.bind(); | |
| 1112 | − _vertexBuffer.allocate(_vertices.constData(), _vertices.size() * sizeof(VoxelPoint)); | |
| 1113 | − _vertexBuffer.release(); | |
| 1122 | + if (_vertexBufferID == 0) { | |
| 1123 | + glGenBuffers(1, &_vertexBufferID); | |
| 1124 | + glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferID); | |
| 1125 | + glBufferData(GL_ARRAY_BUFFER, _vertices.size() * sizeof(VoxelPoint), _vertices.constData(), GL_STATIC_DRAW); | |
| 1126 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 1114 | 1127 | |
| 1115 | − _indexBuffer.create(); | |
| 1116 | − _indexBuffer.bind(); | |
| 1117 | − _indexBuffer.allocate(_indices.constData(), _indices.size() * sizeof(int)); | |
| 1118 | − _indexBuffer.release(); | |
| 1128 | + glGenBuffers(1, &_indexBufferID); | |
| 1129 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBufferID); | |
| 1130 | + glBufferData(GL_ELEMENT_ARRAY_BUFFER, _indices.size() * sizeof(int), _indices.constData(), GL_STATIC_DRAW); | |
| 1131 | + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); | |
| 1119 | 1132 | |
| 1120 | 1133 | if (!_materials.isEmpty()) { |
| 1121 | 1134 | _networkTextures.resize(_materials.size()); |
| @@ -1134,8 +1147,8 @@ void VoxelBuffer::render(const glm::vec3& translation, const glm::quat& rotation · 12 unmodified lines | ||
| 1134 | 1147 | baseBatch.translation = translation; |
| 1135 | 1148 | baseBatch.rotation = rotation; |
| 1136 | 1149 | baseBatch.scale = scale; |
| 1137 | − baseBatch.vertexBuffer = &_vertexBuffer; | |
| 1138 | − baseBatch.indexBuffer = &_indexBuffer; | |
| 1150 | + baseBatch.vertexBufferID = _vertexBufferID; | |
| 1151 | + baseBatch.indexBufferID = _indexBufferID; | |
| 1139 | 1152 | baseBatch.vertexCount = _vertexCount; |
| 1140 | 1153 | baseBatch.indexCount = _indexCount; |
| 1141 | 1154 | Application::getInstance()->getMetavoxels()->addVoxelBaseBatch(baseBatch); |
| @@ -1145,8 +1158,8 @@ void VoxelBuffer::render(const glm::vec3& translation, const glm::quat& rotation · 3 unmodified lines | ||
| 1145 | 1158 | splatBatch.translation = translation; |
| 1146 | 1159 | splatBatch.rotation = rotation; |
| 1147 | 1160 | splatBatch.scale = scale; |
| 1148 | − splatBatch.vertexBuffer = &_vertexBuffer; | |
| 1149 | − splatBatch.indexBuffer = &_indexBuffer; | |
| 1161 | + splatBatch.vertexBufferID = _vertexBufferID; | |
| 1162 | + splatBatch.indexBufferID = _indexBufferID; | |
| 1150 | 1163 | splatBatch.vertexCount = _vertexCount; |
| 1151 | 1164 | splatBatch.indexCount = _indexCount; |
| 1152 | 1165 | splatBatch.splatTextureOffset = glm::vec3( |
| @@ -1178,18 +1191,18 @@ void VoxelBuffer::render(const glm::vec3& translation, const glm::quat& rotation · 25 unmodified lines | ||
| 1178 | 1191 | } |
| 1179 | 1192 | |
| 1180 | 1193 | if (_hermiteCount > 0) { |
| 1181 | − if (!_hermiteBuffer.isCreated()) { | |
| 1182 | − _hermiteBuffer.create(); | |
| 1183 | − _hermiteBuffer.bind(); | |
| 1184 | − _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3)); | |
| 1185 | − _hermiteBuffer.release(); | |
| 1194 | + if (_hermiteBufferID == 0) { | |
| 1195 | + glGenBuffers(1, &_hermiteBufferID); | |
| 1196 | + glBindBuffer(GL_ARRAY_BUFFER, _hermiteBufferID); | |
| 1197 | + glBufferData(GL_ARRAY_BUFFER, _hermite.size() * sizeof(glm::vec3), _hermite.constData(), GL_STATIC_DRAW); | |
| 1198 | + glBindBuffer(GL_ARRAY_BUFFER, 0); | |
| 1186 | 1199 | _hermite.clear(); |
| 1187 | 1200 | } |
| 1188 | 1201 | HermiteBatch hermiteBatch; |
| 1189 | 1202 | hermiteBatch.translation = translation; |
| 1190 | 1203 | hermiteBatch.rotation = rotation; |
| 1191 | 1204 | hermiteBatch.scale = scale; |
| 1192 | − hermiteBatch.vertexBuffer = &_hermiteBuffer; | |
| 1205 | + hermiteBatch.vertexBufferID = _hermiteBufferID; | |
| 1193 | 1206 | hermiteBatch.vertexCount = _hermiteCount; |
| 1194 | 1207 | Application::getInstance()->getMetavoxels()->addHermiteBatch(hermiteBatch); |
| 1195 | 1208 | } |
| @@ -1741,29 +1754,19 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 545 unmodified lines | ||
| 1741 | 1754 | const int NO_CORNERS = 0; |
| 1742 | 1755 | const int ALL_CORNERS = UPPER_LEFT_CORNER | UPPER_RIGHT_CORNER | LOWER_LEFT_CORNER | LOWER_RIGHT_CORNER; |
| 1743 | 1756 | int corners = NO_CORNERS; |
| 1744 | − int stitchMinimumY = INT_MAX, stitchMaximumY = -1; | |
| 1745 | 1757 | if (heightfieldHeight != 0.0f) { |
| 1746 | 1758 | corners |= UPPER_LEFT_CORNER; |
| 1747 | − stitchMinimumY = qMin(stitchMinimumY, (int)heightfieldHeight); | |
| 1748 | − stitchMaximumY = qMax(stitchMaximumY, (int)heightfieldHeight); | |
| 1749 | 1759 | } |
| 1750 | 1760 | if (nextHeightfieldHeightX != 0.0f && x != stackWidth) { |
| 1751 | 1761 | corners |= UPPER_RIGHT_CORNER; |
| 1752 | − stitchMinimumY = qMin(stitchMinimumY, (int)nextHeightfieldHeightX); | |
| 1753 | − stitchMaximumY = qMax(stitchMaximumY, (int)nextHeightfieldHeightX); | |
| 1754 | 1762 | } |
| 1755 | 1763 | if (nextHeightfieldHeightZ != 0.0f && z != stackHeight) { |
| 1756 | 1764 | corners |= LOWER_LEFT_CORNER; |
| 1757 | − stitchMinimumY = qMin(stitchMinimumY, (int)nextHeightfieldHeightZ); | |
| 1758 | − stitchMaximumY = qMax(stitchMaximumY, (int)nextHeightfieldHeightZ); | |
| 1759 | 1765 | } |
| 1760 | 1766 | if (nextHeightfieldHeightXZ != 0.0f && x != stackWidth && z != stackHeight) { |
| 1761 | 1767 | corners |= LOWER_RIGHT_CORNER; |
| 1762 | − stitchMinimumY = qMin(stitchMinimumY, (int)nextHeightfieldHeightXZ); | |
| 1763 | − stitchMaximumY = qMax(stitchMaximumY, (int)nextHeightfieldHeightXZ); | |
| 1764 | 1768 | } |
| 1765 | 1769 | bool stitchable = x != 0 && z != 0 && !(corners == NO_CORNERS || corners == ALL_CORNERS); |
| 1766 | − bool stitched = false; | |
| 1767 | 1770 | VoxelPoint cornerPoints[4]; |
| 1768 | 1771 | int clampedX = qMax(x - 1, 0), clampedZ = qMax(z - 1, 0); |
| 1769 | 1772 | if (stitchable) { |
| @@ -2105,7 +2108,7 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 335 unmodified lines | ||
| 2105 | 2108 | vertices.append(point); |
| 2106 | 2109 | } |
| 2107 | 2110 | |
| 2108 | − if (stitchable && !stitched && y >= stitchMinimumY && y <= stitchMaximumY) { | |
| 2111 | + if (stitchable) { | |
| 2109 | 2112 | int nextIndex = vertices.size(); |
| 2110 | 2113 | const NormalIndex& previousIndexX = lastIndicesX.getClosest(y); |
| 2111 | 2114 | const NormalIndex& previousIndexZ = lastIndicesZ[x].getClosest(y); |
| @@ -2270,7 +2273,6 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 158 unmodified lines | ||
| 2270 | 2273 | break; |
| 2271 | 2274 | } |
| 2272 | 2275 | } |
| 2273 | − stitched = true; | |
| 2274 | 2276 | } |
| 2275 | 2277 | } |
| 2276 | 2278 | |
| @@ -2395,8 +2397,8 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 118 unmodified lines | ||
| 2395 | 2397 | } |
| 2396 | 2398 | |
| 2397 | 2399 | HeightfieldBaseLayerBatch baseBatch; |
| 2398 | − baseBatch.vertexBuffer = &bufferPair.first; | |
| 2399 | − baseBatch.indexBuffer = &bufferPair.second; | |
| 2400 | + baseBatch.vertexBufferID = bufferPair.first.bufferId(); | |
| 2401 | + baseBatch.indexBufferID = bufferPair.second.bufferId(); | |
| 2400 | 2402 | baseBatch.translation = translation; |
| 2401 | 2403 | baseBatch.rotation = rotation; |
| 2402 | 2404 | baseBatch.scale = scale; |
| @@ -2410,8 +2412,8 @@ void HeightfieldNodeRenderer::render(const HeightfieldNodePointer& node, const g · 7 unmodified lines | ||
| 2410 | 2412 | |
| 2411 | 2413 | if (!(cursor || _networkTextures.isEmpty())) { |
| 2412 | 2414 | HeightfieldSplatBatch splatBatch; |
| 2413 | − splatBatch.vertexBuffer = &bufferPair.first; | |
| 2414 | − splatBatch.indexBuffer = &bufferPair.second; | |
| 2415 | + splatBatch.vertexBufferID = bufferPair.first.bufferId(); | |
| 2416 | + splatBatch.indexBufferID = bufferPair.second.bufferId(); | |
| 2415 | 2417 | splatBatch.translation = translation; |
| 2416 | 2418 | splatBatch.rotation = rotation; |
| 2417 | 2419 | splatBatch.scale = scale; |