Showing the changes to libraries/render-utils/src/GeometryCache.cpp (1 of 4 files). Show all
Unified · Split
| @@ -432,7 +432,7 @@ void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, co · 431 unmodified lines | ||
| 432 | 432 | renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id); |
| 433 | 433 | } |
| 434 | 434 | |
| 435 | −void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) { | |
| 435 | +void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const QVector<glm::vec4>& colors) { | |
| 436 | 436 | BatchItemDetails& details = _registeredVertices[id]; |
| 437 | 437 | |
| 438 | 438 | if (details.isCreated) { |
| @@ -469,11 +469,6 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 30 unmodified lines | ||
| 469 | 469 | details.vertices = points.size(); |
| 470 | 470 | details.vertexSize = FLOATS_PER_VERTEX; |
| 471 | 471 | |
| 472 | − int compactColor = ((int(color.x * 255.0f) & 0xFF)) | | |
| 473 | − ((int(color.y * 255.0f) & 0xFF) << 8) | | |
| 474 | − ((int(color.z * 255.0f) & 0xFF) << 16) | | |
| 475 | − ((int(color.w * 255.0f) & 0xFF) << 24); | |
| 476 | − | |
| 477 | 472 | float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX]; |
| 478 | 473 | float* vertex = vertexData; |
| 479 | 474 | |
| @@ -481,16 +476,25 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 1 unmodified line | ||
| 481 | 476 | int* colorDataAt = colorData; |
| 482 | 477 | |
| 483 | 478 | const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); |
| 484 | − foreach(const glm::vec2& point, points) { | |
| 479 | + auto pointCount = points.size(); | |
| 480 | + auto colorCount = colors.size(); | |
| 481 | + int compactColor; | |
| 482 | + for (auto i = 0; i < pointCount; ++i) { | |
| 483 | + const auto& point = points[i]; | |
| 485 | 484 | *(vertex++) = point.x; |
| 486 | 485 | *(vertex++) = point.y; |
| 487 | 486 | *(vertex++) = NORMAL.x; |
| 488 | 487 | *(vertex++) = NORMAL.y; |
| 489 | 488 | *(vertex++) = NORMAL.z; |
| 490 | − | |
| 489 | + if (i < colorCount) { | |
| 490 | + const auto& color = colors[i]; | |
| 491 | + compactColor = ((int(color.x * 255.0f) & 0xFF)) | | |
| 492 | + ((int(color.y * 255.0f) & 0xFF) << 8) | | |
| 493 | + ((int(color.z * 255.0f) & 0xFF) << 16) | | |
| 494 | + ((int(color.w * 255.0f) & 0xFF) << 24); | |
| 495 | + } | |
| 491 | 496 | *(colorDataAt++) = compactColor; |
| 492 | 497 | } |
| 493 | − | |
| 494 | 498 | details.verticesBuffer->append(sizeof(float) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData); |
| 495 | 499 | details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData); |
| 496 | 500 | delete[] vertexData; |
| @@ -501,7 +505,11 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 4 unmodified lines | ||
| 501 | 505 | #endif |
| 502 | 506 | } |
| 503 | 507 | |
| 504 | −void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) { | |
| 508 | +void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) { | |
| 509 | + updateVertices(id, points, QVector<glm::vec4>({ color })); | |
| 510 | +} | |
| 511 | + | |
| 512 | +void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec4>& colors) { | |
| 505 | 513 | BatchItemDetails& details = _registeredVertices[id]; |
| 506 | 514 | if (details.isCreated) { |
| 507 | 515 | details.clear(); |
| @@ -537,11 +545,8 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 29 unmodified lines | ||
| 537 | 545 | details.vertices = points.size(); |
| 538 | 546 | details.vertexSize = FLOATS_PER_VERTEX; |
| 539 | 547 | |
| 540 | − int compactColor = ((int(color.x * 255.0f) & 0xFF)) | | |
| 541 | − ((int(color.y * 255.0f) & 0xFF) << 8) | | |
| 542 | − ((int(color.z * 255.0f) & 0xFF) << 16) | | |
| 543 | − ((int(color.w * 255.0f) & 0xFF) << 24); | |
| 544 | − | |
| 548 | + // Default to white | |
| 549 | + int compactColor = 0xFFFFFFFF; | |
| 545 | 550 | float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX]; |
| 546 | 551 | float* vertex = vertexData; |
| 547 | 552 | |
| @@ -549,14 +554,23 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 1 unmodified line | ||
| 549 | 554 | int* colorDataAt = colorData; |
| 550 | 555 | |
| 551 | 556 | const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f); |
| 552 | − foreach(const glm::vec3& point, points) { | |
| 557 | + auto pointCount = points.size(); | |
| 558 | + auto colorCount = colors.size(); | |
| 559 | + for (auto i = 0; i < pointCount; ++i) { | |
| 560 | + const glm::vec3& point = points[i]; | |
| 561 | + if (i < colorCount) { | |
| 562 | + const glm::vec4& color = colors[i]; | |
| 563 | + compactColor = ((int(color.x * 255.0f) & 0xFF)) | | |
| 564 | + ((int(color.y * 255.0f) & 0xFF) << 8) | | |
| 565 | + ((int(color.z * 255.0f) & 0xFF) << 16) | | |
| 566 | + ((int(color.w * 255.0f) & 0xFF) << 24); | |
| 567 | + } | |
| 553 | 568 | *(vertex++) = point.x; |
| 554 | 569 | *(vertex++) = point.y; |
| 555 | 570 | *(vertex++) = point.z; |
| 556 | 571 | *(vertex++) = NORMAL.x; |
| 557 | 572 | *(vertex++) = NORMAL.y; |
| 558 | 573 | *(vertex++) = NORMAL.z; |
| 559 | − | |
| 560 | 574 | *(colorDataAt++) = compactColor; |
| 561 | 575 | } |
| 562 | 576 | |
| @@ -570,6 +584,10 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 7 unmodified lines | ||
| 570 | 584 | #endif |
| 571 | 585 | } |
| 572 | 586 | |
| 587 | +void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) { | |
| 588 | + updateVertices(id, points, QVector<glm::vec4>({ color })); | |
| 589 | +} | |
| 590 | + | |
| 573 | 591 | void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) { |
| 574 | 592 | BatchItemDetails& details = _registeredVertices[id]; |
| 575 | 593 | |