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
432432 renderQuad(batch, minCorner, maxCorner, MIN_TEX_COORD, MAX_TEX_COORD, color, id);
433433 }
434434
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) {
436436 BatchItemDetails& details = _registeredVertices[id];
437437
438438 if (details.isCreated) {
@@ -469,11 +469,6 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 30 unmodified lines
469469 details.vertices = points.size();
470470 details.vertexSize = FLOATS_PER_VERTEX;
471471
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−
477472 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];
478473 float* vertex = vertexData;
479474
@@ -481,16 +476,25 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 1 unmodified line
481476 int* colorDataAt = colorData;
482477
483478 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];
485484 *(vertex++) = point.x;
486485 *(vertex++) = point.y;
487486 *(vertex++) = NORMAL.x;
488487 *(vertex++) = NORMAL.y;
489488 *(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+ }
491496 *(colorDataAt++) = compactColor;
492497 }
493−
494498 details.verticesBuffer->append(sizeof(float) * FLOATS_PER_VERTEX * details.vertices, (gpu::Byte*) vertexData);
495499 details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Byte*) colorData);
496500 delete[] vertexData;
@@ -501,7 +505,11 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec2>& points, con · 4 unmodified lines
501505 #endif
502506 }
503507
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) {
505513 BatchItemDetails& details = _registeredVertices[id];
506514 if (details.isCreated) {
507515 details.clear();
@@ -537,11 +545,8 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 29 unmodified lines
537545 details.vertices = points.size();
538546 details.vertexSize = FLOATS_PER_VERTEX;
539547
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;
545550 float* vertexData = new float[details.vertices * FLOATS_PER_VERTEX];
546551 float* vertex = vertexData;
547552
@@ -549,14 +554,23 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 1 unmodified line
549554 int* colorDataAt = colorData;
550555
551556 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+ }
553568 *(vertex++) = point.x;
554569 *(vertex++) = point.y;
555570 *(vertex++) = point.z;
556571 *(vertex++) = NORMAL.x;
557572 *(vertex++) = NORMAL.y;
558573 *(vertex++) = NORMAL.z;
559−
560574 *(colorDataAt++) = compactColor;
561575 }
562576
@@ -570,6 +584,10 @@ void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, con · 7 unmodified lines
570584 #endif
571585 }
572586
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+
573591 void GeometryCache::updateVertices(int id, const QVector<glm::vec3>& points, const QVector<glm::vec2>& texCoords, const glm::vec4& color) {
574592 BatchItemDetails& details = _registeredVertices[id];
575593

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