History

Support alpha and color gradients in circle overlays

Brad Davis committed 10 years ago

Commit 31948bc1 parent e893b174 files · +213 −192Browse 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+35−17
@@ -432,7 +432,7 @@ void GeometryCache::renderGrid(gpu::Batch& batch, const glm::vec2& minCorner, co · 431 unmodified lines
432 renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id);432 renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id);
433}433}
434 434
435void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) {435void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const QVector<glm::vec4>& colors) {
436 BatchItemDetails& details = _registeredVertices[id];436 BatchItemDetails& details = _registeredVertices[id];
437 437
438 if (details.isCreated) {438 if (details.isCreated) {
@@ -469,11 +469,6 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 30 unmodified lines
469 details.vertices = points.size();469 details.vertices = points.size();
470 details.vertexSize = FLOATS_PER_VERTEX;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 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];472 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];
478 float* vertex = vertexData;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 int* colorDataAt = colorData;476 int* colorDataAt = colorData;
482 477
483 const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f);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 *(vertex++) = point.x;484 *(vertex++) = point.x;
486 *(vertex++) = point.y;485 *(vertex++) = point.y;
487 *(vertex++) = NORMAL.x;486 *(vertex++) = NORMAL.x;
488 *(vertex++) = NORMAL.y;487 *(vertex++) = NORMAL.y;
489 *(vertex++) = NORMAL.z;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 *(colorDataAt++) = compactColor;496 *(colorDataAt++) = compactColor;
492 }497 }
493
494 details.verticesBuffer->append(sizeof(float) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);498 details.verticesBuffer->append(sizeof(float) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);
495 details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);499 details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);
496 delete[] vertexData;500 delete[] vertexData;
@@ -501,7 +505,11 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 4 unmodified lines
501#endif505#endif
502}506}
503 507
504void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) {508void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, const glm::vec4& color) {
509 updateVertices(id, points, QVector<glm::vec4>({ color }));
510}
511
512void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec4>& colors) {
505 BatchItemDetails& details = _registeredVertices[id];513 BatchItemDetails& details = _registeredVertices[id];
506 if (details.isCreated) {514 if (details.isCreated) {
507 details.clear();515 details.clear();
@@ -537,11 +545,8 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 29 unmodified lines
537 details.vertices = points.size();545 details.vertices = points.size();
538 details.vertexSize = FLOATS_PER_VERTEX;546 details.vertexSize = FLOATS_PER_VERTEX;
539 547
540 int compactColor = ((int(color.x * 255.0f) & 0xFF)) |548 // Default to white
541 ((int(color.y * 255.0f) & 0xFF) << 8) |549 int compactColor = 0xFFFFFFFF;
542 ((int(color.z * 255.0f) & 0xFF) << 16) |
543 ((int(color.w * 255.0f) & 0xFF) << 24);
544
545 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];550 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];
546 float* vertex = vertexData;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 int* colorDataAt = colorData;554 int* colorDataAt = colorData;
550 555
551 const glm::vec3 NORMAL(0.0f, 0.0f, 1.0f);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 *(vertex++) = point.x;568 *(vertex++) = point.x;
554 *(vertex++) = point.y;569 *(vertex++) = point.y;
555 *(vertex++) = point.z;570 *(vertex++) = point.z;
556 *(vertex++) = NORMAL.x;571 *(vertex++) = NORMAL.x;
557 *(vertex++) = NORMAL.y;572 *(vertex++) = NORMAL.y;
558 *(vertex++) = NORMAL.z;573 *(vertex++) = NORMAL.z;
559
560 *(colorDataAt++) = compactColor;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#endif584#endif
571}585}
572 586
587void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const glm::vec4& color) {
588 updateVertices(id, points, QVector<glm::vec4>({ color }));
589}
590
573void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) {591void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) {
574 BatchItemDetails& details = _registeredVertices[id];592 BatchItemDetails& details = _registeredVertices[id];
575 593

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