From a03c2b79fa2ff6f61aa0199305760ae15e9f5f8f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 8 Jan 2015 15:52:33 -0800 Subject: [PATCH 01/50] first cut at adding colors to GeometryCache and supporting batch internally --- interface/src/Util.cpp | 30 +++-- interface/src/avatar/Avatar.cpp | 6 +- interface/src/avatar/Head.cpp | 9 +- interface/src/avatar/SkeletonModel.cpp | 12 +- interface/src/ui/overlays/Line3DOverlay.cpp | 3 +- libraries/render-utils/src/GeometryCache.cpp | 111 ++++++++++--------- libraries/render-utils/src/GeometryCache.h | 63 +++++++++-- 7 files changed, 138 insertions(+), 96 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index cd01996622..3d106895df 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -36,22 +36,18 @@ void renderWorldBox() { GeometryCache::SharedPointer geometryCache = DependencyManager::get(); // Show edge of world - float red[] = {1, 0, 0}; - float green[] = {0, 1, 0}; - float blue[] = {0, 0, 1}; - float gray[] = {0.5, 0.5, 0.5}; + glm::vec3 red(1.0f, 0.0f, 0.0f); + glm::vec3 green(0.0f, 1.0f, 0.0f); + glm::vec3 blue(0.0f, 0.0f, 1.0f); + glm::vec3 grey(0.5f, 0.5f, 0.5f); glDisable(GL_LIGHTING); glLineWidth(1.0); - glColor3fv(red); - geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(TREE_SCALE, 0, 0)); - glColor3fv(green); - geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, TREE_SCALE, 0)); - glColor3fv(blue); - geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, TREE_SCALE)); - glColor3fv(gray); - geometryCache->renderLine(glm::vec3(0, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, TREE_SCALE)); - geometryCache->renderLine(glm::vec3(TREE_SCALE, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, 0)); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(TREE_SCALE, 0, 0), red); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, TREE_SCALE, 0), green); + geometryCache->renderLine(glm::vec3(0, 0, 0), glm::vec3(0, 0, TREE_SCALE), blue); + geometryCache->renderLine(glm::vec3(0, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, TREE_SCALE), grey); + geometryCache->renderLine(glm::vec3(TREE_SCALE, 0, TREE_SCALE), glm::vec3(TREE_SCALE, 0, 0), grey); // Draw meter markers along the 3 axis to help with measuring things @@ -60,21 +56,21 @@ void renderWorldBox() { glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(MARKER_DISTANCE, 0, 0); - glColor3fv(red); + glColor3f(red.x, red.y, red.z); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0, MARKER_DISTANCE, 0); - glColor3fv(green); + glColor3f(green.x, green.y, green.z); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); glTranslatef(0, 0, MARKER_DISTANCE); - glColor3fv(blue); + glColor3f(blue.x, blue.y, blue.z); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); glPushMatrix(); - glColor3fv(gray); + glColor3f(grey.x, grey.y, grey.z); glTranslatef(MARKER_DISTANCE, 0, MARKER_DISTANCE); geometryCache->renderSphere(MARKER_RADIUS, 10, 10); glPopMatrix(); diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index ddbaeece72..c97db94eb6 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -301,8 +301,7 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool glm::vec3 axis = glm::axis(rotation); glRotatef(angle, axis.x, axis.y, axis.z); - glColor3f(laserColor.x, laserColor.y, laserColor.z); - geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f)); + geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } glPopMatrix(); } @@ -327,8 +326,7 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool float angle = glm::degrees(glm::angle(rotation)); glm::vec3 axis = glm::axis(rotation); glRotatef(angle, axis.x, axis.y, axis.z); - glColor3f(laserColor.x, laserColor.y, laserColor.z); - geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f)); + geometryCache->renderLine(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } glPopMatrix(); } diff --git a/interface/src/avatar/Head.cpp b/interface/src/avatar/Head.cpp index 32594a7225..f53975a4e8 100644 --- a/interface/src/avatar/Head.cpp +++ b/interface/src/avatar/Head.cpp @@ -345,11 +345,10 @@ void Head::renderLookatVectors(glm::vec3 leftEyePosition, glm::vec3 rightEyePosi glLineWidth(2.0); - // TODO: implement support for lines with gradient colors - // glColor4f(0.2f, 0.2f, 0.2f, 1.0f); --> to --> glColor4f(1.0f, 1.0f, 1.0f, 0.0f); - glColor4f(0.5f, 0.5f, 0.5f, 0.5f); - geometryCache->renderLine(leftEyePosition, lookatPosition, _leftEyeLookAtID); - geometryCache->renderLine(rightEyePosition, lookatPosition, _rightEyeLookAtID); + glm::vec4 startColor(0.2f, 0.2f, 0.2f, 1.0f); + glm::vec4 endColor(1.0f, 1.0f, 1.0f, 0.0f); + geometryCache->renderLine(leftEyePosition, lookatPosition, startColor, endColor, _leftEyeLookAtID); + geometryCache->renderLine(rightEyePosition, lookatPosition, startColor, endColor, _rightEyeLookAtID); DependencyManager::get()->end(); } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 54cd6c0bfe..31fa648d17 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -396,14 +396,14 @@ void SkeletonModel::renderOrientationDirections(int jointIndex, glm::vec3 positi glm::vec3 pUp = position + orientation * IDENTITY_UP * size; glm::vec3 pFront = position + orientation * IDENTITY_FRONT * size; - glColor3f(1.0f, 0.0f, 0.0f); - geometryCache->renderLine(position, pRight, jointLineIDs._right); + glm::vec3 red(1.0f, 0.0f, 0.0f); + geometryCache->renderLine(position, pRight, red, jointLineIDs._right); - glColor3f(0.0f, 1.0f, 0.0f); - geometryCache->renderLine(position, pUp, jointLineIDs._up); + glm::vec3 green(0.0f, 1.0f, 0.0f); + geometryCache->renderLine(position, pUp, green, jointLineIDs._up); - glColor3f(0.0f, 0.0f, 1.0f); - geometryCache->renderLine(position, pFront, jointLineIDs._front); + glm::vec3 blue(0.0f, 0.0f, 1.0f); + geometryCache->renderLine(position, pFront, blue, jointLineIDs._front); } diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index 48a995b80b..ab537eea89 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -50,6 +50,7 @@ void Line3DOverlay::render(RenderArgs* args) { xColor color = getColor(); const float MAX_COLOR = 255.0f; glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); glm::quat rotation = getRotation(); @@ -61,7 +62,7 @@ void Line3DOverlay::render(RenderArgs* args) { if (getIsDashedLine()) { DependencyManager::get()->renderDashedLine(_position, _end, _geometryCacheID); } else { - DependencyManager::get()->renderLine(_start, _end, _geometryCacheID); + DependencyManager::get()->renderLine(_start, _end, colorv4, _geometryCacheID); } glEnable(GL_LIGHTING); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 553e460a5c..4d09ab0163 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -18,6 +18,9 @@ #include #include +#include +#include + #include #include "TextureCache.h" @@ -1397,18 +1400,30 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en details.buffer.release(); } -void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) { - bool registeredLine = (id != UNKNOWN_ID); +void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2, int id) { + + bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); - VerticesIndices& vbo = registeredLine ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; + BatchItemDetails& details = registered ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; + + int compactColor1 = ((int(color1.x * 255.0f) & 0xFF)) | + ((int(color1.y * 255.0f) & 0xFF) << 8) | + ((int(color1.z * 255.0f) & 0xFF) << 16) | + ((int(color1.w * 255.0f) & 0xFF) << 24); + + int compactColor2 = ((int(color2.x * 255.0f) & 0xFF)) | + ((int(color2.y * 255.0f) & 0xFF) << 8) | + ((int(color2.z * 255.0f) & 0xFF) << 16) | + ((int(color2.w * 255.0f) & 0xFF) << 24); + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredLine && vbo.first != 0) { + if (registered && details.isCreated) { Vec3Pair& lastKey = _lastRegisteredLine3D[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredLine3D[id] = key; #ifdef WANT_DEBUG qDebug() << "renderLine() 3D ... RELEASING REGISTERED line"; #endif // def WANT_DEBUG @@ -1421,46 +1436,38 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) } const int FLOATS_PER_VERTEX = 3; - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 2; - const int indices = 2; - if (vbo.first == 0) { - _lastRegisteredLine3D[id] = key; + if (!details.isCreated) { - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1}; - - int vertexPoint = 0; + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; - // p1 - vertex[vertexPoint++] = p1.x; - vertex[vertexPoint++] = p1.y; - vertex[vertexPoint++] = p1.z; + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); - // p2 - vertex[vertexPoint++] = p2.x; - vertex[vertexPoint++] = p2.y; - vertex[vertexPoint++] = p2.z; - + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { p1.x, p1.y, p1.z, p2.x, p2.y, p2.z }; + + const int NUM_COLOR_SCALARS = 2; + int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 }; + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - #ifdef WANT_DEBUG if (id == UNKNOWN_ID) { qDebug() << "new renderLine() 3D VBO made -- _line3DVBOs.size():" << _line3DVBOs.size(); @@ -1468,18 +1475,20 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, int id) qDebug() << "new registered renderLine() 3D VBO made -- _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); } #endif - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + gpu::Batch batch; + + // this is what it takes to render a quad + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::LINES, 2, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 17b23da945..96e3f4c398 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -111,7 +111,20 @@ public: const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id = UNKNOWN_ID); - void renderLine(const glm::vec3& p1, const glm::vec3& p2, int id = UNKNOWN_ID); + void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) + { renderLine(p1, p2, color, color, id); } + + void renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) + { renderLine(p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } + + void renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color, int id = UNKNOWN_ID) + { renderLine(p1, p2, color, color, id); } + + void renderLine(const glm::vec3& p1, const glm::vec3& p2, + const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); + void renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); @@ -128,13 +141,46 @@ protected: virtual QSharedPointer createResource(const QUrl& url, const QSharedPointer& fallback, bool delayLoad, const void* extra); - + private: GeometryCache(); virtual ~GeometryCache(); typedef QPair IntPair; typedef QPair VerticesIndices; + struct BufferDetails { + QOpenGLBuffer buffer; + int vertices; + int vertexSize; + }; + + class BatchItemDetails { + public: + gpu::BufferPointer verticesBuffer; + gpu::BufferPointer colorBuffer; + gpu::Stream::FormatPointer streamFormat; + gpu::BufferStreamPointer stream; + + int vertices; + int vertexSize; + bool isCreated; + + BatchItemDetails() : + verticesBuffer(NULL), + colorBuffer(NULL), + streamFormat(NULL), + stream(NULL), + vertices(0), + vertexSize(0), + isCreated(false) + { + } + + void clear() { + // TODO: add the proper de-allocation of the gpu items + isCreated = false; + } + }; QHash _hemisphereVBOs; QHash _sphereVBOs; @@ -160,27 +206,20 @@ private: QHash _registeredRectVBOs; QHash _lastRegisteredLine3D; - QHash _line3DVBOs; - QHash _registeredLine3DVBOs; + QHash _line3DVBOs; + QHash _registeredLine3DVBOs; QHash _lastRegisteredLine2D; QHash _line2DVBOs; QHash _registeredLine2DVBOs; - struct BufferDetails { - QOpenGLBuffer buffer; - int vertices; - int vertexSize; - }; - QHash _registeredVertices; QHash _lastRegisteredDashedLines; QHash _dashedLines; QHash _registeredDashedLines; - - + QHash _colors; QHash _gridBuffers; QHash _registeredAlternateGridBuffers; From 17e48554d8f123c9a888245093a0f12b5c5af6fe Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Fri, 9 Jan 2015 15:06:11 -0800 Subject: [PATCH 02/50] implement support for proper cleanup in BatchItemDetails --- libraries/render-utils/src/GeometryCache.cpp | 44 ++++++++++++++++++++ libraries/render-utils/src/GeometryCache.h | 20 +++------ 2 files changed, 49 insertions(+), 15 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 4d09ab0163..0207b47fa1 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -40,6 +40,10 @@ GeometryCache::~GeometryCache() { glDeleteBuffers(1, &vbo.first); glDeleteBuffers(1, &vbo.second); } + qDebug() << "GeometryCache::~GeometryCache()... "; + qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); + qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size(); + qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population; } void GeometryCache::renderHemisphere(int slices, int stacks) { @@ -1400,11 +1404,51 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en details.buffer.release(); } +int GeometryCache::BatchItemDetails::population = 0; +GeometryCache::BatchItemDetails::BatchItemDetails() : + verticesBuffer(NULL), + colorBuffer(NULL), + streamFormat(NULL), + stream(NULL), + vertices(0), + vertexSize(0), + isCreated(false) +{ + population++; +} + +GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) : + verticesBuffer(other.verticesBuffer), + colorBuffer(other.colorBuffer), + streamFormat(other.streamFormat), + stream(other.stream), + vertices(other.vertices), + vertexSize(other.vertexSize), + isCreated(other.isCreated) +{ + population++; +} + +GeometryCache::BatchItemDetails::~BatchItemDetails() { + population--; + clear(); + qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; +} + +void GeometryCache::BatchItemDetails::clear() { + isCreated = false; + verticesBuffer.clear(); + colorBuffer.clear(); + streamFormat.clear(); + stream.clear(); +} + void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); + BatchItemDetails& details = registered ? _registeredLine3DVBOs[id] : _line3DVBOs[key]; int compactColor1 = ((int(color1.x * 255.0f) & 0xFF)) | diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 96e3f4c398..0e216a5bc1 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -156,6 +156,7 @@ private: class BatchItemDetails { public: + static int population; gpu::BufferPointer verticesBuffer; gpu::BufferPointer colorBuffer; gpu::Stream::FormatPointer streamFormat; @@ -165,21 +166,10 @@ private: int vertexSize; bool isCreated; - BatchItemDetails() : - verticesBuffer(NULL), - colorBuffer(NULL), - streamFormat(NULL), - stream(NULL), - vertices(0), - vertexSize(0), - isCreated(false) - { - } - - void clear() { - // TODO: add the proper de-allocation of the gpu items - isCreated = false; - } + BatchItemDetails(); + BatchItemDetails(const GeometryCache::BatchItemDetails& other); + ~BatchItemDetails(); + void clear(); }; QHash _hemisphereVBOs; From e6388a65b9296cb3be47f0c48e8b7d191a832002 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 13 Jan 2015 20:53:05 -0800 Subject: [PATCH 03/50] rough pass at adding color to geometry cache --- interface/src/Application.cpp | 2 +- interface/src/Environment.cpp | 2 +- interface/src/MetavoxelSystem.cpp | 8 +- interface/src/Util.cpp | 19 +-- interface/src/Util.h | 2 - interface/src/audio/AudioIOStatsRenderer.cpp | 5 +- interface/src/audio/AudioScope.cpp | 28 ++-- interface/src/audio/AudioScope.h | 8 +- interface/src/audio/AudioToolBox.cpp | 12 +- interface/src/avatar/Avatar.cpp | 22 ++- interface/src/avatar/Avatar.h | 3 +- interface/src/avatar/Hand.cpp | 13 +- interface/src/avatar/MyAvatar.cpp | 9 +- interface/src/avatar/SkeletonModel.cpp | 31 ++-- interface/src/octree/OctreeFade.cpp | 3 +- interface/src/ui/ApplicationOverlay.cpp | 50 +++---- interface/src/ui/BandwidthMeter.cpp | 32 +++-- interface/src/ui/BandwidthMeter.h | 5 +- interface/src/ui/MetavoxelEditor.cpp | 14 +- interface/src/ui/NodeBounds.cpp | 13 +- interface/src/ui/RearMirrorTools.cpp | 7 +- interface/src/ui/Stats.cpp | 12 +- .../src/ui/overlays/BillboardOverlay.cpp | 4 +- interface/src/ui/overlays/Circle3DOverlay.cpp | 24 ++-- interface/src/ui/overlays/Cube3DOverlay.cpp | 14 +- interface/src/ui/overlays/Grid3DOverlay.cpp | 6 +- interface/src/ui/overlays/ImageOverlay.cpp | 6 +- .../src/ui/overlays/Rectangle3DOverlay.cpp | 6 +- interface/src/ui/overlays/Sphere3DOverlay.cpp | 4 +- interface/src/ui/overlays/Text3DOverlay.cpp | 4 +- interface/src/ui/overlays/TextOverlay.cpp | 4 +- .../src/EntityTreeRenderer.cpp | 39 ++--- .../src/RenderableBoxEntityItem.cpp | 4 +- .../src/RenderableModelEntityItem.cpp | 12 +- .../src/RenderableSphereEntityItem.cpp | 4 +- .../src/RenderableTextEntityItem.cpp | 4 +- .../src/DeferredLightingEffect.cpp | 20 ++- .../render-utils/src/DeferredLightingEffect.h | 8 +- libraries/render-utils/src/GeometryCache.cpp | 136 ++++++++++-------- libraries/render-utils/src/GeometryCache.h | 53 ++++--- libraries/render-utils/src/GlowEffect.cpp | 1 - libraries/render-utils/src/RenderUtil.cpp | 3 +- 42 files changed, 321 insertions(+), 335 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 22a2b6bc22..81ecff3df1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2769,7 +2769,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs // draw a red sphere float originSphereRadius = 0.05f; glColor3f(1,0,0); - DependencyManager::get()->renderSphere(originSphereRadius, 15, 15); + DependencyManager::get()->renderSphere(originSphereRadius, 15, 15, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)); // also, metavoxels if (Menu::getInstance()->isOptionChecked(MenuOption::Metavoxels)) { diff --git a/interface/src/Environment.cpp b/interface/src/Environment.cpp index 645bbbdc4f..5cc132bb7f 100644 --- a/interface/src/Environment.cpp +++ b/interface/src/Environment.cpp @@ -263,7 +263,7 @@ void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); - DependencyManager::get()->renderSphere(1.0f, 100, 50); //Draw a unit sphere + DependencyManager::get()->renderSphere(1.0f, 100, 50, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); //Draw a unit sphere glDepthMask(GL_TRUE); program->release(); diff --git a/interface/src/MetavoxelSystem.cpp b/interface/src/MetavoxelSystem.cpp index 9a26ca6bb5..7f96e61cf0 100644 --- a/interface/src/MetavoxelSystem.cpp +++ b/interface/src/MetavoxelSystem.cpp @@ -1973,7 +1973,6 @@ SphereRenderer::SphereRenderer() { void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { Sphere* sphere = static_cast(_spanner); const QColor& color = sphere->getColor(); - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); glPushMatrix(); const glm::vec3& translation = sphere->getTranslation(); @@ -1982,7 +1981,8 @@ void SphereRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor glm::vec3 axis = glm::axis(rotation); glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); - DependencyManager::get()->renderSolidSphere(sphere->getScale(), 32, 32); + DependencyManager::get()->renderSolidSphere(sphere->getScale(), 32, 32, + glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())); glPopMatrix(); } @@ -1993,7 +1993,6 @@ CuboidRenderer::CuboidRenderer() { void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor) { Cuboid* cuboid = static_cast(_spanner); const QColor& color = cuboid->getColor(); - glColor4f(color.redF(), color.greenF(), color.blueF(), color.alphaF()); glPushMatrix(); const glm::vec3& translation = cuboid->getTranslation(); @@ -2003,7 +2002,8 @@ void CuboidRenderer::render(const MetavoxelLOD& lod, bool contained, bool cursor glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ()); - DependencyManager::get()->renderSolidCube(cuboid->getScale() * 2.0f); + DependencyManager::get()->renderSolidCube(cuboid->getScale() * 2.0f, + glm::vec4(color.redF(), color.greenF(), color.blueF(), color.alphaF())); glPopMatrix(); } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index 3d106895df..2c9840a218 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -56,23 +56,19 @@ void renderWorldBox() { glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(MARKER_DISTANCE, 0, 0); - glColor3f(red.x, red.y, red.z); - geometryCache->renderSphere(MARKER_RADIUS, 10, 10); + geometryCache->renderSphere(MARKER_RADIUS, 10, 10, red); glPopMatrix(); glPushMatrix(); glTranslatef(0, MARKER_DISTANCE, 0); - glColor3f(green.x, green.y, green.z); - geometryCache->renderSphere(MARKER_RADIUS, 10, 10); + geometryCache->renderSphere(MARKER_RADIUS, 10, 10, green); glPopMatrix(); glPushMatrix(); glTranslatef(0, 0, MARKER_DISTANCE); - glColor3f(blue.x, blue.y, blue.z); - geometryCache->renderSphere(MARKER_RADIUS, 10, 10); + geometryCache->renderSphere(MARKER_RADIUS, 10, 10, blue); glPopMatrix(); glPushMatrix(); - glColor3f(grey.x, grey.y, grey.z); glTranslatef(MARKER_DISTANCE, 0, MARKER_DISTANCE); - geometryCache->renderSphere(MARKER_RADIUS, 10, 10); + geometryCache->renderSphere(MARKER_RADIUS, 10, 10, grey); glPopMatrix(); } @@ -120,15 +116,10 @@ void drawText(int x, int y, float scale, float radians, int mono, void renderCollisionOverlay(int width, int height, float magnitude, float red, float blue, float green) { const float MIN_VISIBLE_COLLISION = 0.01f; if (magnitude > MIN_VISIBLE_COLLISION) { - glColor4f(red, blue, green, magnitude); - DependencyManager::get()->renderQuad(0, 0, width, height); + DependencyManager::get()->renderQuad(0, 0, width, height, glm::vec4(red, blue, green, magnitude)); } } -void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance) { - DependencyManager::get()->renderBevelCornersRect(x, y, width, height, bevelDistance); -} - // Do some basic timing tests and report the results void runTimingTests() { // How long does it take to make a call to get the time? diff --git a/interface/src/Util.h b/interface/src/Util.h index 74336168c0..6aeca985ec 100644 --- a/interface/src/Util.h +++ b/interface/src/Util.h @@ -27,8 +27,6 @@ void drawText(int x, int y, float scale, float radians, int mono, void renderCollisionOverlay(int width, int height, float magnitude, float red = 0, float blue = 0, float green = 0); -void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance); - void runTimingTests(); float loadSetting(QSettings* settings, const char* name, float defaultValue); diff --git a/interface/src/audio/AudioIOStatsRenderer.cpp b/interface/src/audio/AudioIOStatsRenderer.cpp index 86662a28ed..1b385a4757 100644 --- a/interface/src/audio/AudioIOStatsRenderer.cpp +++ b/interface/src/audio/AudioIOStatsRenderer.cpp @@ -50,13 +50,12 @@ void AudioIOStatsRenderer::render(const float* color, int width, int height) { int statsHeight = STATS_HEIGHT_PER_LINE * lines; - static const float backgroundColor[4] = { 0.2f, 0.2f, 0.2f, 0.6f }; + static const glm::vec4 backgroundColor = { 0.2f, 0.2f, 0.2f, 0.6f }; int x = std::max((width - (int)STATS_WIDTH) / 2, 0); int y = std::max((height - CENTERED_BACKGROUND_HEIGHT) / 2, 0); int w = STATS_WIDTH; int h = statsHeight; - glColor4fv(backgroundColor); - DependencyManager::get()->renderQuad(x, y, w, h); + DependencyManager::get()->renderQuad(x, y, w, h, backgroundColor); glColor4f(1, 1, 1, 1); int horizontalOffset = x + 5; diff --git a/interface/src/audio/AudioScope.cpp b/interface/src/audio/AudioScope.cpp index 02e1d9ca4e..c9ca261ce4 100644 --- a/interface/src/audio/AudioScope.cpp +++ b/interface/src/audio/AudioScope.cpp @@ -111,11 +111,11 @@ void AudioScope::render(int width, int height) { return; } - static const float backgroundColor[4] = { 0.4f, 0.4f, 0.4f, 0.6f }; - static const float gridColor[4] = { 0.7f, 0.7f, 0.7f, 1.0f }; - static const float inputColor[4] = { 0.3f, 1.0f, 0.3f, 1.0f }; - static const float outputLeftColor[4] = { 1.0f, 0.3f, 0.3f, 1.0f }; - static const float outputRightColor[4] = { 0.3f, 0.3f, 1.0f, 1.0f }; + static const glm::vec4 backgroundColor = { 0.4f, 0.4f, 0.4f, 0.6f }; + static const glm::vec4 gridColor = { 0.7f, 0.7f, 0.7f, 1.0f }; + static const glm::vec4 inputColor = { 0.3f, 1.0f, 0.3f, 1.0f }; + static const glm::vec4 outputLeftColor = { 1.0f, 0.3f, 0.3f, 1.0f }; + static const glm::vec4 outputRightColor = { 0.3f, 0.3f, 1.0f, 1.0f }; static const int gridRows = 2; int gridCols = _framesPerScope; @@ -132,21 +132,15 @@ void AudioScope::render(int width, int height) { renderLineStrip(_outputRightD, outputRightColor, x, y, _samplesPerScope, _scopeOutputOffset, _scopeOutputRight); } -void AudioScope::renderBackground(const float* color, int x, int y, int width, int height) { - glColor4fv(color); - DependencyManager::get()->renderQuad(x, y, width, height); - glColor4f(1, 1, 1, 1); +void AudioScope::renderBackground(const glm::vec4& color, int x, int y, int width, int height) { + DependencyManager::get()->renderQuad(x, y, width, height, color); } -void AudioScope::renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols) { - glColor4fv(color); - DependencyManager::get()->renderGrid(x, y, width, height, rows, cols, _audioScopeGrid); - glColor4f(1, 1, 1, 1); +void AudioScope::renderGrid(const glm::vec4& color, int x, int y, int width, int height, int rows, int cols) { + DependencyManager::get()->renderGrid(x, y, width, height, rows, cols, color, _audioScopeGrid); } -void AudioScope::renderLineStrip(int id, const float* color, int x, int y, int n, int offset, const QByteArray* byteArray) { - - glColor4fv(color); +void AudioScope::renderLineStrip(int id, const glm::vec4& color, int x, int y, int n, int offset, const QByteArray* byteArray) { int16_t sample; int16_t* samples = ((int16_t*) byteArray->data()) + offset; @@ -200,7 +194,7 @@ void AudioScope::renderLineStrip(int id, const float* color, int x, int y, int n } - geometryCache->updateVertices(id, points); + geometryCache->updateVertices(id, points, color); geometryCache->renderVertices(GL_LINE_STRIP, id); glColor4f(1, 1, 1, 1); diff --git a/interface/src/audio/AudioScope.h b/interface/src/audio/AudioScope.h index a061ad65d8..2e7c5897a9 100644 --- a/interface/src/audio/AudioScope.h +++ b/interface/src/audio/AudioScope.h @@ -12,6 +12,8 @@ #ifndef hifi_AudioScope_h #define hifi_AudioScope_h +#include + #include #include @@ -46,9 +48,9 @@ private slots: private: // Audio scope methods for rendering - static void renderBackground(const float* color, int x, int y, int width, int height); - void renderGrid(const float* color, int x, int y, int width, int height, int rows, int cols); - void renderLineStrip(int id, const float* color, int x, int y, int n, int offset, const QByteArray* byteArray); + static void renderBackground(const glm::vec4& color, int x, int y, int width, int height); + void renderGrid(const glm::vec4& color, int x, int y, int width, int height, int rows, int cols); + void renderLineStrip(int id, const glm::vec4& color, int x, int y, int n, int offset, const QByteArray* byteArray); // Audio scope methods for data acquisition int addBufferToScope(QByteArray* byteArray, int frameOffset, const int16_t* source, int sourceSamples, diff --git a/interface/src/audio/AudioToolBox.cpp b/interface/src/audio/AudioToolBox.cpp index 891d317fae..efb2177abe 100644 --- a/interface/src/audio/AudioToolBox.cpp +++ b/interface/src/audio/AudioToolBox.cpp @@ -56,17 +56,19 @@ void AudioToolBox::render(int x, int y, bool boxed) { glBindTexture(GL_TEXTURE_2D, _boxTextureId); + glm::vec4 quadColor; + if (isClipping) { - glColor3f(1.0f, 0.0f, 0.0f); + quadColor = glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); } else { - glColor3f(0.41f, 0.41f, 0.41f); + quadColor = glm::vec4(0.41f, 0.41f, 0.41f, 1.0f); } glm::vec2 topLeft(boxBounds.left(), boxBounds.top()); glm::vec2 bottomRight(boxBounds.right(), boxBounds.bottom()); glm::vec2 texCoordTopLeft(1,1); glm::vec2 texCoordBottomRight(0,0); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); } float iconColor = 1.0f; @@ -92,14 +94,14 @@ void AudioToolBox::render(int x, int y, bool boxed) { iconColor = PULSE_MIN + (PULSE_MAX - PULSE_MIN) * pulseFactor; } - glColor3f(iconColor, iconColor, iconColor); + glm::vec4 quadColor(iconColor, iconColor, iconColor, 1.0f); glm::vec2 topLeft(_iconBounds.left(), _iconBounds.top()); glm::vec2 bottomRight(_iconBounds.right(), _iconBounds.bottom()); glm::vec2 texCoordTopLeft(1,1); glm::vec2 texCoordBottomRight(0,0); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); glDisable(GL_TEXTURE_2D); } \ No newline at end of file diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index d6e29e0c31..70e53f84b7 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -402,15 +402,14 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool if (_isLookAtTarget && Menu::getInstance()->isOptionChecked(MenuOption::RenderFocusIndicator)) { const float LOOK_AT_INDICATOR_RADIUS = 0.03f; const float LOOK_AT_INDICATOR_OFFSET = 0.22f; - const float LOOK_AT_INDICATOR_COLOR[] = { 0.8f, 0.0f, 0.0f, 0.75f }; + const glm::vec4 LOOK_AT_INDICATOR_COLOR = { 0.8f, 0.0f, 0.0f, 0.75f }; glPushMatrix(); - glColor4fv(LOOK_AT_INDICATOR_COLOR); if (_displayName.isEmpty() || _displayNameAlpha == 0.0f) { glTranslatef(_position.x, getDisplayNamePosition().y, _position.z); } else { glTranslatef(_position.x, getDisplayNamePosition().y + LOOK_AT_INDICATOR_OFFSET, _position.z); } - DependencyManager::get()->renderSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15); + DependencyManager::get()->renderSphere(LOOK_AT_INDICATOR_RADIUS, 15, 15, LOOK_AT_INDICATOR_COLOR); glPopMatrix(); } } @@ -434,11 +433,11 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool if (renderMode == NORMAL_RENDER_MODE && (sphereRadius > MIN_SPHERE_SIZE) && (angle < MAX_SPHERE_ANGLE) && (angle > MIN_SPHERE_ANGLE)) { - glColor4f(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE); glPushMatrix(); glTranslatef(_position.x, _position.y, _position.z); glScalef(height, height, height); - DependencyManager::get()->renderSphere(sphereRadius, 15, 15); + DependencyManager::get()->renderSphere(sphereRadius, 15, 15, + glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE)); glPopMatrix(); } @@ -569,14 +568,12 @@ void Avatar::renderBillboard() { float size = getBillboardSize(); glScalef(size, size, size); - glColor3f(1.0f, 1.0f, 1.0f); - glm::vec2 topLeft(-1.0f, -1.0f); glm::vec2 bottomRight(1.0f, 1.0f); glm::vec2 texCoordTopLeft(0.0f, 0.0f); glm::vec2 texCoordBottomRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); glPopMatrix(); @@ -703,8 +700,8 @@ void Avatar::renderDisplayName() { glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f, 1.0f); - glColor4f(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); - renderBevelCornersRect(left, bottom, right - left, top - bottom, 3); + DependencyManager::get()->renderBevelCornersRect(left, bottom, right - left, top - bottom, 3, + glm::vec4(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA)); glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); QByteArray ba = _displayName.toLocal8Bit(); @@ -946,7 +943,8 @@ int Avatar::parseDataAtOffset(const QByteArray& packet, int offset) { int Avatar::_jointConesID = GeometryCache::UNKNOWN_ID; // render a makeshift cone section that serves as a body part connecting joint spheres -void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2) { +void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, + float radius1, float radius2, const glm::vec4& color) { GeometryCache::SharedPointer geometryCache = DependencyManager::get(); @@ -991,7 +989,7 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, // TODO: this is really inefficient constantly recreating these vertices buffers. It would be // better if the avatars cached these buffers for each of the joints they are rendering - geometryCache->updateVertices(_jointConesID, points); + geometryCache->updateVertices(_jointConesID, points, color); geometryCache->renderVertices(GL_TRIANGLES, _jointConesID); } } diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index f975e8dac3..6d1a21af94 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -133,7 +133,8 @@ public: virtual int parseDataAtOffset(const QByteArray& packet, int offset); - static void renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, float radius1, float radius2); + static void renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, + float radius1, float radius2, const glm::vec4& color); virtual void applyCollision(const glm::vec3& contactPoint, const glm::vec3& penetration) { } diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 0ea0d1b725..a334b77c93 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -115,8 +115,7 @@ void Hand::render(bool isMine, Model::RenderMode renderMode) { glm::vec3 position = palm.getPosition(); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - glColor3f(0.0f, 1.0f, 0.0f); - DependencyManager::get()->renderSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10); + DependencyManager::get()->renderSphere(PALM_COLLISION_RADIUS * _owningAvatar->getScale(), 10, 10, glm::vec3(0.0f, 1.0f, 0.0f)); glPopMatrix(); } } @@ -152,8 +151,7 @@ void Hand::renderHandTargets(bool isMine) { glTranslatef(targetPosition.x, targetPosition.y, targetPosition.z); const float collisionRadius = 0.05f; - glColor4f(0.5f,0.5f,0.5f, alpha); - DependencyManager::get()->renderSphere(collisionRadius, 10, 10, false); + DependencyManager::get()->renderSphere(collisionRadius, 10, 10, glm::vec4(0.5f,0.5f,0.5f, alpha), false); glPopMatrix(); } } @@ -167,7 +165,6 @@ void Hand::renderHandTargets(bool isMine) { for (size_t i = 0; i < getNumPalms(); ++i) { PalmData& palm = getPalms()[i]; if (palm.isActive()) { - glColor4f(handColor.r, handColor.g, handColor.b, alpha); glm::vec3 tip = palm.getTipPosition(); glm::vec3 root = palm.getPosition(); @@ -175,13 +172,13 @@ void Hand::renderHandTargets(bool isMine) { myAvatar->scaleVectorRelativeToPosition(tip); myAvatar->scaleVectorRelativeToPosition(root); - Avatar::renderJointConnectingCone(root, tip, PALM_FINGER_ROD_RADIUS, PALM_FINGER_ROD_RADIUS); + Avatar::renderJointConnectingCone(root, tip, PALM_FINGER_ROD_RADIUS, PALM_FINGER_ROD_RADIUS, glm::vec4(handColor.r, handColor.g, handColor.b, alpha)); // Render sphere at palm/finger root glm::vec3 offsetFromPalm = root + palm.getNormal() * PALM_DISK_THICKNESS; - Avatar::renderJointConnectingCone(root, offsetFromPalm, PALM_DISK_RADIUS, 0.0f); + Avatar::renderJointConnectingCone(root, offsetFromPalm, PALM_DISK_RADIUS, 0.0f, glm::vec4(handColor.r, handColor.g, handColor.b, alpha)); glPushMatrix(); glTranslatef(root.x, root.y, root.z); - DependencyManager::get()->renderSphere(PALM_BALL_RADIUS, 20.0f, 20.0f); + DependencyManager::get()->renderSphere(PALM_BALL_RADIUS, 20.0f, 20.0f, glm::vec4(handColor.r, handColor.g, handColor.b, alpha)); glPopMatrix(); } } diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index 343a729298..658a5d3dc2 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -381,17 +381,15 @@ void MyAvatar::renderDebugBodyPoints() { // Torso Sphere position = torsoPosition; glPushMatrix(); - glColor4f(0, 1, 0, .5f); glTranslatef(position.x, position.y, position.z); - DependencyManager::get()->renderSphere(0.2f, 10.0f, 10.0f); + DependencyManager::get()->renderSphere(0.2f, 10.0f, 10.0f, glm::vec4(0, 1, 0, .5f)); glPopMatrix(); // Head Sphere position = headPosition; glPushMatrix(); - glColor4f(0, 1, 0, .5f); glTranslatef(position.x, position.y, position.z); - DependencyManager::get()->renderSphere(0.15f, 10.0f, 10.0f); + DependencyManager::get()->renderSphere(0.15f, 10.0f, 10.0f, glm::vec4(0, 1, 0, .5f)); glPopMatrix(); } @@ -1940,14 +1938,13 @@ void MyAvatar::renderLaserPointers() { for (size_t i = 0; i < getHand()->getNumPalms(); ++i) { PalmData& palm = getHand()->getPalms()[i]; if (palm.isActive()) { - glColor4f(0, 1, 1, 1); glm::vec3 tip = getLaserPointerTipPosition(&palm); glm::vec3 root = palm.getPosition(); //Scale the root vector with the avatar scale scaleVectorRelativeToPosition(root); - Avatar::renderJointConnectingCone(root, tip, PALM_TIP_ROD_RADIUS, PALM_TIP_ROD_RADIUS); + Avatar::renderJointConnectingCone(root, tip, PALM_TIP_ROD_RADIUS, PALM_TIP_ROD_RADIUS, glm::vec4(0, 1, 1, 1)); } } } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 31fa648d17..b5b82f091d 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -354,7 +354,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { } else { otherAxis.x = 1.0f; } - glColor4f(otherAxis.r, otherAxis.g, otherAxis.b, 0.75f); + glm::vec4 color(otherAxis.r, otherAxis.g, otherAxis.b, 0.75f); QVector points; points << glm::vec3(0.0f, 0.0f, 0.0f); @@ -366,7 +366,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { } // TODO: this is really inefficient constantly recreating these vertices buffers. It would be // better if the skeleton model cached these buffers for each of the joints they are rendering - geometryCache->updateVertices(_triangleFanID, points); + geometryCache->updateVertices(_triangleFanID, points, color); geometryCache->renderVertices(GL_TRIANGLE_FAN, _triangleFanID); } @@ -601,10 +601,8 @@ void SkeletonModel::renderRagdoll() { glm::vec3 position = points[i]._position - simulationTranslation; glTranslatef(position.x, position.y, position.z); // draw each point as a yellow hexagon with black border - glColor4f(0.0f, 0.0f, 0.0f, alpha); - geometryCache->renderSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); - glColor4f(1.0f, 1.0f, 0.0f, alpha); - geometryCache->renderSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(radius2, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.0f, 0.0f, 0.0f, alpha)); + geometryCache->renderSphere(radius1, BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(1.0f, 1.0f, 0.0f, alpha)); glPopMatrix(); } glPopMatrix(); @@ -953,9 +951,8 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { _boundingShape.getEndPoint(endPoint); endPoint = endPoint - _translation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); - glColor4f(0.6f, 0.6f, 0.8f, alpha); GeometryCache::SharedPointer geometryCache = DependencyManager::get(); - geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; @@ -963,13 +960,11 @@ void SkeletonModel::renderBoundingCollisionShapes(float alpha) { startPoint = startPoint - _translation; glm::vec3 axis = endPoint - startPoint; glTranslatef(-axis.x, -axis.y, -axis.z); - glColor4f(0.8f, 0.8f, 0.6f, alpha); - geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(_boundingShape.getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); - glColor4f(0.6f, 0.8f, 0.6f, alpha); - Avatar::renderJointConnectingCone( origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius()); + Avatar::renderJointConnectingCone( origin, axis, _boundingShape.getRadius(), _boundingShape.getRadius(), glm::vec4(0.6f, 0.8f, 0.6f, alpha)); glPopMatrix(); } @@ -998,8 +993,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { glm::vec3 position = shape->getTranslation() - simulationTranslation; glTranslatef(position.x, position.y, position.z); // draw a grey sphere at shape position - glColor4f(0.75f, 0.75f, 0.75f, alpha); - geometryCache->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(shape->getBoundingRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.75f, 0.75f, 0.75f, alpha)); } else if (shape->getType() == CAPSULE_SHAPE) { CapsuleShape* capsule = static_cast(shape); @@ -1008,8 +1002,7 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { capsule->getEndPoint(endPoint); endPoint = endPoint - simulationTranslation; glTranslatef(endPoint.x, endPoint.y, endPoint.z); - glColor4f(0.6f, 0.6f, 0.8f, alpha); - geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.6f, 0.6f, 0.8f, alpha)); // draw a yellow sphere at the capsule startpoint glm::vec3 startPoint; @@ -1017,13 +1010,11 @@ void SkeletonModel::renderJointCollisionShapes(float alpha) { startPoint = startPoint - simulationTranslation; glm::vec3 axis = endPoint - startPoint; glTranslatef(-axis.x, -axis.y, -axis.z); - glColor4f(0.8f, 0.8f, 0.6f, alpha); - geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS); + geometryCache->renderSphere(capsule->getRadius(), BALL_SUBDIVISIONS, BALL_SUBDIVISIONS, glm::vec4(0.8f, 0.8f, 0.6f, alpha)); // draw a green cylinder between the two points glm::vec3 origin(0.0f); - glColor4f(0.6f, 0.8f, 0.6f, alpha); - Avatar::renderJointConnectingCone( origin, axis, capsule->getRadius(), capsule->getRadius()); + Avatar::renderJointConnectingCone( origin, axis, capsule->getRadius(), capsule->getRadius(), glm::vec4(0.6f, 0.8f, 0.6f, alpha)); } glPopMatrix(); } diff --git a/interface/src/octree/OctreeFade.cpp b/interface/src/octree/OctreeFade.cpp index 2e2e45eb90..917bb67124 100644 --- a/interface/src/octree/OctreeFade.cpp +++ b/interface/src/octree/OctreeFade.cpp @@ -43,12 +43,11 @@ void OctreeFade::render() { glDisable(GL_LIGHTING); glPushMatrix(); glScalef(TREE_SCALE, TREE_SCALE, TREE_SCALE); - glColor4f(red, green, blue, opacity); glTranslatef(voxelDetails.x + voxelDetails.s * 0.5f, voxelDetails.y + voxelDetails.s * 0.5f, voxelDetails.z + voxelDetails.s * 0.5f); glLineWidth(1.0f); - DependencyManager::get()->renderSolidCube(voxelDetails.s); + DependencyManager::get()->renderSolidCube(voxelDetails.s, glm::vec4(red, green, blue, opacity)); glLineWidth(1.0f); glPopMatrix(); glEnable(GL_LIGHTING); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 106c74cdeb..174d45340b 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -245,13 +245,12 @@ void ApplicationOverlay::displayOverlayTexture() { glDisable(GL_LIGHTING); glEnable(GL_BLEND); - glColor4f(1.0f, 1.0f, 1.0f, _alpha); glm::vec2 topLeft(0.0f, 0.0f); glm::vec2 bottomRight(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); } glPopMatrix(); @@ -673,14 +672,13 @@ void ApplicationOverlay::renderControllerPointers() { mouseY += reticleSize / 2.0f; - glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - glm::vec2 topLeft(mouseX, mouseY); glm::vec2 bottomRight(mouseX + reticleSize, mouseY - reticleSize); glm::vec2 texCoordTopLeft(0.0f, 0.0f); glm::vec2 texCoordBottomRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], 1.0f)); } } @@ -756,7 +754,7 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool border << bottomRight; border << topRight; border << topLeft; - geometryCache->updateVertices(_magnifierBorder, border); + geometryCache->updateVertices(_magnifierBorder, border, glm::vec4(1.0f, 0.0f, 0.0f, _alpha)); _previousMagnifierBottomLeft = bottomLeft; _previousMagnifierBottomRight = bottomRight; @@ -769,7 +767,6 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool glDisable(GL_TEXTURE_2D); glLineWidth(1.0f); //Outer Line - glColor4f(1.0f, 0.0f, 0.0f, _alpha); geometryCache->renderVertices(GL_LINE_STRIP, _magnifierBorder); glEnable(GL_TEXTURE_2D); } @@ -810,9 +807,9 @@ void ApplicationOverlay::renderAudioMeter() { audioMeterY = AUDIO_METER_GAP + MUTE_ICON_PADDING; } - const float AUDIO_METER_BLUE[] = { 0.0, 0.0, 1.0 }; - const float AUDIO_METER_GREEN[] = { 0.0, 1.0, 0.0 }; - const float AUDIO_METER_RED[] = { 1.0, 0.0, 0.0 }; + const glm::vec4 AUDIO_METER_BLUE = { 0.0, 0.0, 1.0, 1.0 }; + const glm::vec4 AUDIO_METER_GREEN = { 0.0, 1.0, 0.0, 1.0 }; + const glm::vec4 AUDIO_METER_RED = { 1.0, 0.0, 0.0, 1.0 }; const float AUDIO_GREEN_START = 0.25 * AUDIO_METER_SCALE_WIDTH; const float AUDIO_RED_START = 0.80 * AUDIO_METER_SCALE_WIDTH; const float CLIPPING_INDICATOR_TIME = 1.0f; @@ -855,51 +852,53 @@ void ApplicationOverlay::renderAudioMeter() { audioMeterY += AUDIO_METER_HEIGHT; - glColor3f(0, 0, 0); // Draw audio meter background Quad - DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT); + DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT, glm::vec4(0, 0, 0, 1)); if (audioLevel > AUDIO_RED_START) { + glm::vec4 quadColor; if (!isClipping) { - glColor3fv(AUDIO_METER_RED); + quadColor = AUDIO_METER_RED; } else { - glColor3f(1, 1, 1); + quadColor = glm::vec4(1, 1, 1, 1); } // Draw Red Quad DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_RED_START, - AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor, _audioRedQuad); audioLevel = AUDIO_RED_START; } if (audioLevel > AUDIO_GREEN_START) { + glm::vec4 quadColor; if (!isClipping) { - glColor3fv(AUDIO_METER_GREEN); + quadColor = AUDIO_METER_GREEN; } else { - glColor3f(1, 1, 1); + quadColor = glm::vec4(1, 1, 1, 1); } // Draw Green Quad DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET, audioLevel - AUDIO_GREEN_START, - AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor, _audioGreenQuad); audioLevel = AUDIO_GREEN_START; } // Draw Blue Quad + glm::vec4 quadColor; if (!isClipping) { - glColor3fv(AUDIO_METER_BLUE); + quadColor = AUDIO_METER_BLUE; } else { - glColor3f(1, 1, 1); + quadColor = glm::vec4(1, 1, 1, 1); } // Draw Blue (low level) quad DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET, - audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET, + audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET, quadColor, _audioBlueQuad); } @@ -955,20 +954,21 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { int height = glCanvas->height(); if (width != _previousBorderWidth || height != _previousBorderHeight) { + glm::vec4 color(CONNECTION_STATUS_BORDER_COLOR[0], + CONNECTION_STATUS_BORDER_COLOR[1], + CONNECTION_STATUS_BORDER_COLOR[2], 1.0f); + QVector border; border << glm::vec2(0, 0); border << glm::vec2(0, height); border << glm::vec2(width, height); border << glm::vec2(width, 0); border << glm::vec2(0, 0); - geometryCache->updateVertices(_domainStatusBorder, border); + geometryCache->updateVertices(_domainStatusBorder, border, color); _previousBorderWidth = width; _previousBorderHeight = height; } - glColor3f(CONNECTION_STATUS_BORDER_COLOR[0], - CONNECTION_STATUS_BORDER_COLOR[1], - CONNECTION_STATUS_BORDER_COLOR[2]); glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH); geometryCache->renderVertices(GL_LINE_STRIP, _domainStatusBorder); diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index 69cd20d9a2..a29f16b851 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -94,12 +94,21 @@ void BandwidthMeter::setColorRGBA(unsigned c) { GLubyte( c & 0xff)); } -void BandwidthMeter::renderBox(int x, int y, int w, int h) { - DependencyManager::get()->renderQuad(x, y, w, h); +glm::vec4 BandwidthMeter::getColorRGBA(unsigned c) { + + float r = (c >> 24) / 255.0f; + float g = ((c >> 16) & 0xff) / 255.0f; + float b = ((c >> 8) & 0xff) / 255.0f; + float a = (c & 0xff) / 255.0f; + return glm::vec4(r,g,b,a); } -void BandwidthMeter::renderVerticalLine(int x, int y, int h) { - DependencyManager::get()->renderLine(glm::vec2(x, y), glm::vec2(x, y + h)); +void BandwidthMeter::renderBox(int x, int y, int w, int h, unsigned c) { + DependencyManager::get()->renderQuad(x, y, w, h, getColorRGBA(c)); +} + +void BandwidthMeter::renderVerticalLine(int x, int y, int h, unsigned c) { + DependencyManager::get()->renderLine(glm::vec2(x, y), glm::vec2(x, y + h), getColorRGBA(c)); } inline int BandwidthMeter::centered(int subject, int object) { @@ -161,9 +170,9 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT); // Render vertical lines for the frame - setColorRGBA(COLOR_FRAME); - renderVerticalLine(0, 0, h); - renderVerticalLine(barWidth, 0, h); + //setColorRGBA(COLOR_FRAME); + renderVerticalLine(0, 0, h, COLOR_FRAME); + renderVerticalLine(barWidth, 0, h, COLOR_FRAME); // Adjust scale int steps; @@ -192,9 +201,8 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { } // Render scale indicators - setColorRGBA(COLOR_INDICATOR); for (int j = NUMBER_OF_MARKERS; --j > 0;) { - renderVerticalLine((barWidth * j) / NUMBER_OF_MARKERS, 0, h); + renderVerticalLine((barWidth * j) / NUMBER_OF_MARKERS, 0, h, COLOR_INDICATOR); } // Render bars @@ -205,15 +213,13 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { int wIn = (int)(barWidth * inputStream(chIdx).getValue() * UNIT_SCALE / scaleMax); int wOut = (int)(barWidth * outputStream(chIdx).getValue() * UNIT_SCALE / scaleMax); - setColorRGBA(channelInfo(chIdx).colorRGBA); - if (wIn > 0) { - renderBox(xIn, 0, wIn, barHeight); + renderBox(xIn, 0, wIn, barHeight, channelInfo(chIdx).colorRGBA); } xIn += wIn; if (wOut > 0) { - renderBox(xOut, h - barHeight, wOut, barHeight); + renderBox(xOut, h - barHeight, wOut, barHeight, channelInfo(chIdx).colorRGBA); } xOut += wOut; } diff --git a/interface/src/ui/BandwidthMeter.h b/interface/src/ui/BandwidthMeter.h index 0829cc86e9..4f69a9fb97 100644 --- a/interface/src/ui/BandwidthMeter.h +++ b/interface/src/ui/BandwidthMeter.h @@ -70,8 +70,9 @@ public: private: static void setColorRGBA(unsigned c); - static void renderBox(int x, int y, int w, int h); - static void renderVerticalLine(int x, int y, int h); + static glm::vec4 getColorRGBA(unsigned c); + static void renderBox(int x, int y, int w, int h, unsigned c); + static void renderVerticalLine(int x, int y, int h, unsigned c); static inline int centered(int subject, int object); diff --git a/interface/src/ui/MetavoxelEditor.cpp b/interface/src/ui/MetavoxelEditor.cpp index 23ff960aea..fc5d8773a7 100644 --- a/interface/src/ui/MetavoxelEditor.cpp +++ b/interface/src/ui/MetavoxelEditor.cpp @@ -353,11 +353,9 @@ void MetavoxelEditor::render() { float scale = GRID_DIVISIONS * spacing; glScalef(scale, scale, scale); - glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS); - _gridProgram.bind(); - DependencyManager::get()->renderGrid(GRID_DIVISIONS, GRID_DIVISIONS); + DependencyManager::get()->renderGrid(GRID_DIVISIONS, GRID_DIVISIONS, glm::vec4(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, 1.0f)); _gridProgram.release(); @@ -488,17 +486,17 @@ void BoxTool::render() { if (_state != HOVERING_STATE) { const float BOX_ALPHA = 0.25f; QColor color = getColor(); + glm::vec4 cubeColor; if (color.isValid()) { - glColor4f(color.redF(), color.greenF(), color.blueF(), BOX_ALPHA); + cubeColor = glm::vec4(color.redF(), color.greenF(), color.blueF(), BOX_ALPHA); } else { - glColor4f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, BOX_ALPHA); + cubeColor = glm::vec4(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, BOX_ALPHA); } glEnable(GL_CULL_FACE); - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, cubeColor); glDisable(GL_CULL_FACE); } - glColor3f(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS); - DependencyManager::get()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f, glm::vec4(GRID_BRIGHTNESS, GRID_BRIGHTNESS, GRID_BRIGHTNESS, 1.0f)); glPopMatrix(); } diff --git a/interface/src/ui/NodeBounds.cpp b/interface/src/ui/NodeBounds.cpp index 620efe20fb..704325f98e 100644 --- a/interface/src/ui/NodeBounds.cpp +++ b/interface/src/ui/NodeBounds.cpp @@ -127,8 +127,7 @@ void NodeBounds::draw() { float red, green, blue; getColorForNodeType(selectedNode->getType(), red, green, blue); - glColor4f(red, green, blue, 0.2f); - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(red, green, blue, 0.2f)); glPopMatrix(); @@ -152,8 +151,7 @@ void NodeBounds::drawNodeBorder(const glm::vec3& center, float scale, float red, glTranslatef(center.x, center.y, center.z); glScalef(scale, scale, scale); glLineWidth(2.5); - glColor3f(red, green, blue); - DependencyManager::get()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f, glm::vec4(red, green, blue, 1.0f)); glPopMatrix(); } @@ -179,9 +177,10 @@ void NodeBounds::drawOverlay() { int mouseX = application->getTrueMouseX(), mouseY = application->getTrueMouseY(), textWidth = widthText(TEXT_SCALE, 0, _overlayText); - glColor4f(0.4f, 0.4f, 0.4f, 0.6f); - renderBevelCornersRect(mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, - textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL); + DependencyManager::get()->renderBevelCornersRect( + mouseX + MOUSE_OFFSET, mouseY - TEXT_HEIGHT - PADDING, + textWidth + (2 * PADDING), TEXT_HEIGHT + (2 * PADDING), BACKGROUND_BEVEL, + glm::vec4(0.4f, 0.4f, 0.4f, 0.6f)); drawText(mouseX + MOUSE_OFFSET + PADDING, mouseY, TEXT_SCALE, ROTATION, FONT, _overlayText, TEXT_COLOR); } } diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index 29c8e67f61..c794fc1ecf 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -133,10 +133,11 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glDisable(GL_LIGHTING); glEnable(GL_TEXTURE_2D); + glm::vec4 quadColor; if (selected) { - glColor3f(.5f, .5f, .5f); + quadColor = glm::vec4(.5f, .5f, .5f, 1.0f); } else { - glColor3f(1, 1, 1); + quadColor = glm::vec4(1, 1, 1, 1); } glBindTexture(GL_TEXTURE_2D, textureId); @@ -146,7 +147,7 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); glPopMatrix(); diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index 43565fcca8..cf24615938 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -154,14 +154,12 @@ void Stats::resetWidth(int width, int horizontalOffset) { // translucent background box that makes stats more readable void Stats::drawBackground(unsigned int rgba, int x, int y, int width, int height) { - glColor4f(((rgba >> 24) & 0xff) / 255.0f, - ((rgba >> 16) & 0xff) / 255.0f, - ((rgba >> 8) & 0xff) / 255.0f, - (rgba & 0xff) / 255.0f); + glm::vec4 color(((rgba >> 24) & 0xff) / 255.0f, + ((rgba >> 16) & 0xff) / 255.0f, + ((rgba >> 8) & 0xff) / 255.0f, + (rgba & 0xff) / 255.0f); - DependencyManager::get()->renderQuad(x, y, width, height); - - glColor4f(1, 1, 1, 1); + DependencyManager::get()->renderQuad(x, y, width, height, color); } bool Stats::includeTimingRecord(const QString& name) { diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index b34416f566..03decf046c 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -95,7 +95,6 @@ void BillboardOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec2 topLeft(-x, -y); glm::vec2 bottomRight(x, y); @@ -104,7 +103,8 @@ void BillboardOverlay::render(RenderArgs* args) { glm::vec2 texCoordBottomRight(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(), ((float)_fromImage.y() + (float)_fromImage.height()) / _size.height()); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha)); } } glPopMatrix(); diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 25bc8a0ddc..1805f9c7d8 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -95,10 +95,9 @@ void Circle3DOverlay::render(RenderArgs* args) { const float SLICE_ANGLE = FULL_CIRCLE / SLICES; //const int slices = 15; - xColor color = getColor(); + xColor colorX = getColor(); const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - + glm::vec4 color(colorX.red / MAX_COLOR, colorX.green / MAX_COLOR, colorX.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); @@ -162,7 +161,7 @@ void Circle3DOverlay::render(RenderArgs* args) { points << lastOuterPoint << lastInnerPoint; - geometryCache->updateVertices(_quadVerticesID, points); + geometryCache->updateVertices(_quadVerticesID, points, color); } geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); @@ -200,7 +199,7 @@ void Circle3DOverlay::render(RenderArgs* args) { glm::vec2 lastPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius); points << lastPoint; - geometryCache->updateVertices(_lineVerticesID, points); + geometryCache->updateVertices(_lineVerticesID, points, color); } if (getIsDashedLine()) { @@ -270,16 +269,19 @@ void Circle3DOverlay::render(RenderArgs* args) { } } - geometryCache->updateVertices(_majorTicksVerticesID, majorPoints); - geometryCache->updateVertices(_minorTicksVerticesID, minorPoints); + xColor majorColorX = getMajorTickMarksColor(); + glm::vec4 majorColor(majorColorX.red / MAX_COLOR, majorColorX.green / MAX_COLOR, majorColorX.blue / MAX_COLOR, alpha); + + geometryCache->updateVertices(_majorTicksVerticesID, majorPoints, majorColor); + + xColor minorColorX = getMinorTickMarksColor(); + glm::vec4 minorColor(minorColorX.red / MAX_COLOR, minorColorX.green / MAX_COLOR, minorColorX.blue / MAX_COLOR, alpha); + + geometryCache->updateVertices(_minorTicksVerticesID, minorPoints, minorColor); } - xColor majorColor = getMajorTickMarksColor(); - glColor4f(majorColor.red / MAX_COLOR, majorColor.green / MAX_COLOR, majorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID); - xColor minorColor = getMinorTickMarksColor(); - glColor4f(minorColor.red / MAX_COLOR, minorColor.green / MAX_COLOR, minorColor.blue / MAX_COLOR, alpha); geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID); } diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index 62c2bea128..5d0a8ff037 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -47,7 +47,7 @@ void Cube3DOverlay::render(RenderArgs* args) { float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 cubeColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); //glDisable(GL_LIGHTING); @@ -74,13 +74,12 @@ void Cube3DOverlay::render(RenderArgs* args) { // enough for the use-case. glDepthMask(GL_FALSE); glPushMatrix(); - glColor4f(1.0f, 1.0f, 1.0f, alpha); glScalef(dimensions.x * _borderSize, dimensions.y * _borderSize, dimensions.z * _borderSize); if (_drawOnHUD) { - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha)); } else { - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, glm::vec4(1.0f, 1.0f, 1.0f, alpha)); } glPopMatrix(); @@ -88,12 +87,11 @@ void Cube3DOverlay::render(RenderArgs* args) { } glPushMatrix(); - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glScalef(dimensions.x, dimensions.y, dimensions.z); if (_drawOnHUD) { - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, cubeColor); } else { - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, cubeColor); } glPopMatrix(); } else { @@ -130,7 +128,7 @@ void Cube3DOverlay::render(RenderArgs* args) { } else { glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f, cubeColor); } } glPopMatrix(); diff --git a/interface/src/ui/overlays/Grid3DOverlay.cpp b/interface/src/ui/overlays/Grid3DOverlay.cpp index fbcbf97077..b39b2c3274 100644 --- a/interface/src/ui/overlays/Grid3DOverlay.cpp +++ b/interface/src/ui/overlays/Grid3DOverlay.cpp @@ -79,7 +79,7 @@ void Grid3DOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 gridColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); _gridProgram.bind(); @@ -92,7 +92,7 @@ void Grid3DOverlay::render(RenderArgs* args) { float scale = MINOR_GRID_DIVISIONS * spacing; glScalef(scale, scale, scale); - DependencyManager::get()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS); + DependencyManager::get()->renderGrid(MINOR_GRID_DIVISIONS, MINOR_GRID_DIVISIONS, gridColor); } glPopMatrix(); @@ -107,7 +107,7 @@ void Grid3DOverlay::render(RenderArgs* args) { float scale = MAJOR_GRID_DIVISIONS * spacing; glScalef(scale, scale, scale); - DependencyManager::get()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS); + DependencyManager::get()->renderGrid(MAJOR_GRID_DIVISIONS, MAJOR_GRID_DIVISIONS, gridColor); } glPopMatrix(); diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 1ecfc74e44..169a3eaa3d 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -85,7 +85,7 @@ void ImageOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; xColor color = getColor(); float alpha = getAlpha(); - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 quadColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); float imageWidth = _textureImage.width(); float imageHeight = _textureImage.height(); @@ -115,9 +115,9 @@ void ImageOverlay::render(RenderArgs* args) { glm::vec2 texCoordBottomRight(x + w, 1.0f - (y + h)); if (_renderImage) { - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); } else { - DependencyManager::get()->renderQuad(topLeft, bottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, quadColor); } if (_renderImage) { diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 2776754340..d3f82dd270 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -39,7 +39,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) { float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 rectangleColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); @@ -72,7 +72,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) { if (getIsSolid()) { glm::vec3 topLeft(-halfDimensions.x, 0.0f, -halfDimensions.y); glm::vec3 bottomRight(halfDimensions.x, 0.0f, halfDimensions.y); - DependencyManager::get()->renderQuad(topLeft, bottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, rectangleColor); } else { if (getIsDashedLine()) { @@ -95,7 +95,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) { border << glm::vec3(halfDimensions.x, 0.0f, halfDimensions.y); border << glm::vec3(-halfDimensions.x, 0.0f, halfDimensions.y); border << glm::vec3(-halfDimensions.x, 0.0f, -halfDimensions.y); - geometryCache->updateVertices(_geometryCacheID, border); + geometryCache->updateVertices(_geometryCacheID, border, rectangleColor); _previousHalfDimensions = halfDimensions; diff --git a/interface/src/ui/overlays/Sphere3DOverlay.cpp b/interface/src/ui/overlays/Sphere3DOverlay.cpp index 3e30ec033d..11bd7b97e8 100644 --- a/interface/src/ui/overlays/Sphere3DOverlay.cpp +++ b/interface/src/ui/overlays/Sphere3DOverlay.cpp @@ -39,7 +39,7 @@ void Sphere3DOverlay::render(RenderArgs* args) { float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); + glm::vec4 sphereColor(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glDisable(GL_LIGHTING); @@ -62,7 +62,7 @@ void Sphere3DOverlay::render(RenderArgs* args) { glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderSphere(1.0f, SLICES, SLICES, _isSolid); + DependencyManager::get()->renderSphere(1.0f, SLICES, SLICES, sphereColor, _isSolid); glPopMatrix(); glPopMatrix(); diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 92f6350936..251039db22 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -92,7 +92,7 @@ void Text3DOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; xColor backgroundColor = getBackgroundColor(); - glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, + glm::vec4 quadColor(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, getBackgroundAlpha()); glm::vec2 dimensions = getDimensions(); @@ -102,7 +102,7 @@ void Text3DOverlay::render(RenderArgs* args) { glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - DependencyManager::get()->renderQuad(topLeft, bottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, quadColor); const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index ca83e1c595..1333134907 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -70,7 +70,7 @@ void TextOverlay::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; xColor backgroundColor = getBackgroundColor(); - glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, + glm::vec4 quadColor(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, getBackgroundAlpha()); int left = _bounds.left(); @@ -80,7 +80,7 @@ void TextOverlay::render(RenderArgs* args) { glm::vec2 topLeft(left, top); glm::vec2 bottomRight(right, bottom); - DependencyManager::get()->renderQuad(topLeft, bottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, quadColor); // Same font properties as textSize() TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); diff --git a/libraries/entities-renderer/src/EntityTreeRenderer.cpp b/libraries/entities-renderer/src/EntityTreeRenderer.cpp index 47e9237ddc..adb119cb9b 100644 --- a/libraries/entities-renderer/src/EntityTreeRenderer.cpp +++ b/libraries/entities-renderer/src/EntityTreeRenderer.cpp @@ -394,62 +394,53 @@ const Model* EntityTreeRenderer::getModelForEntityItem(const EntityItem* entityI void EntityTreeRenderer::renderElementProxy(EntityTreeElement* entityTreeElement) { glm::vec3 elementCenter = entityTreeElement->getAACube().calcCenter() * (float) TREE_SCALE; float elementSize = entityTreeElement->getScale() * (float) TREE_SCALE; - glColor3f(1.0f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x, elementCenter.y, elementCenter.z); - DependencyManager::get()->renderWireCube(elementSize); + DependencyManager::get()->renderWireCube(elementSize, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)); glPopMatrix(); if (_displayElementChildProxies) { // draw the children float halfSize = elementSize / 2.0f; float quarterSize = elementSize / 4.0f; - glColor3f(1.0f, 1.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y - quarterSize, elementCenter.z - quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(1.0f, 1.0f, 0.0f, 1.0f)); glPopMatrix(); - glColor3f(1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y - quarterSize, elementCenter.z - quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)); glPopMatrix(); - glColor3f(0.0f, 1.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y + quarterSize, elementCenter.z - quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(0.0f, 1.0f, 0.0f, 1.0f)); glPopMatrix(); - glColor3f(0.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y - quarterSize, elementCenter.z + quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)); glPopMatrix(); - glColor3f(1.0f, 1.0f, 1.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y + quarterSize, elementCenter.z + quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); glPopMatrix(); - glColor3f(0.0f, 0.5f, 0.5f); glPushMatrix(); glTranslatef(elementCenter.x - quarterSize, elementCenter.y + quarterSize, elementCenter.z + quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(0.0f, 0.5f, 0.5f, 1.0f)); glPopMatrix(); - glColor3f(0.5f, 0.0f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y - quarterSize, elementCenter.z + quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(0.5f, 0.0f, 0.0f, 1.0f)); glPopMatrix(); - glColor3f(0.0f, 0.5f, 0.0f); glPushMatrix(); glTranslatef(elementCenter.x + quarterSize, elementCenter.y + quarterSize, elementCenter.z - quarterSize); - DependencyManager::get()->renderWireCube(halfSize); + DependencyManager::get()->renderWireCube(halfSize, glm::vec4(0.0f, 0.5f, 0.0f, 1.0f)); glPopMatrix(); } } @@ -473,25 +464,22 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glm::vec3 entityBoxScale = entityBox.getScale(); // draw the max bounding cube - glColor4f(1.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(maxCenter.x, maxCenter.y, maxCenter.z); - DependencyManager::get()->renderWireCube(maxCube.getScale()); + DependencyManager::get()->renderWireCube(maxCube.getScale(), glm::vec4(1.0f, 1.0f, 0.0f, 1.0f)); glPopMatrix(); // draw the min bounding cube - glColor4f(0.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(minCenter.x, minCenter.y, minCenter.z); - DependencyManager::get()->renderWireCube(minCube.getScale()); + DependencyManager::get()->renderWireCube(minCube.getScale(), glm::vec4(0.0f, 1.0f, 0.0f, 1.0f)); glPopMatrix(); // draw the entityBox bounding box - glColor4f(0.0f, 0.0f, 1.0f, 1.0f); glPushMatrix(); glTranslatef(entityBoxCenter.x, entityBoxCenter.y, entityBoxCenter.z); glScalef(entityBoxScale.x, entityBoxScale.y, entityBoxScale.z); - DependencyManager::get()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)); glPopMatrix(); @@ -500,7 +488,6 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glm::vec3 dimensions = entity->getDimensions() * (float) TREE_SCALE; glm::quat rotation = entity->getRotation(); - glColor4f(1.0f, 0.0f, 1.0f, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); @@ -509,7 +496,7 @@ void EntityTreeRenderer::renderProxies(const EntityItem* entity, RenderArgs* arg glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireCube(1.0f); + DependencyManager::get()->renderWireCube(1.0f, glm::vec4(1.0f, 0.0f, 1.0f, 1.0f)); glPopMatrix(); glPopMatrix(); } diff --git a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp index 276db09477..7f2ba410d8 100644 --- a/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableBoxEntityItem.cpp @@ -32,7 +32,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; - glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, + glm::vec4 cubeColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); glPushMatrix(); @@ -43,7 +43,7 @@ void RenderableBoxEntityItem::render(RenderArgs* args) { glm::vec3 positionToCenter = center - position; glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderSolidCube(1.0f); + DependencyManager::get()->renderSolidCube(1.0f, cubeColor); glPopMatrix(); glPopMatrix(); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 699603cb21..48b30868d0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -176,27 +176,27 @@ void RenderableModelEntityItem::render(RenderArgs* args) { } } else { // if we couldn't get a model, then just draw a cube - glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); + glm::vec4 color(getColor()[RED_INDEX]/255, getColor()[GREEN_INDEX]/255, getColor()[BLUE_INDEX]/255, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - DependencyManager::get()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size, color); glPopMatrix(); } } else { // if we couldn't get a model, then just draw a cube - glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); + glm::vec4 color(getColor()[RED_INDEX]/255, getColor()[GREEN_INDEX]/255, getColor()[BLUE_INDEX]/255, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - DependencyManager::get()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size, color); glPopMatrix(); } } glPopMatrix(); } else { - glColor3ub(getColor()[RED_INDEX],getColor()[GREEN_INDEX],getColor()[BLUE_INDEX]); + glm::vec4 color(getColor()[RED_INDEX]/255, getColor()[GREEN_INDEX]/255, getColor()[BLUE_INDEX]/255, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); - DependencyManager::get()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size, color); glPopMatrix(); } } diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 97e3ee7869..e6ea75dfee 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -32,7 +32,7 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glm::quat rotation = getRotation(); const float MAX_COLOR = 255.0f; - glColor4f(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, + glm::vec4 sphereColor(getColor()[RED_INDEX] / MAX_COLOR, getColor()[GREEN_INDEX] / MAX_COLOR, getColor()[BLUE_INDEX] / MAX_COLOR, getLocalRenderAlpha()); glPushMatrix(); @@ -46,7 +46,7 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderSolidSphere(0.5f, 15, 15); + DependencyManager::get()->renderSolidSphere(0.5f, 15, 15, sphereColor); glPopMatrix(); glPopMatrix(); }; diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 76431b55bc..492543fd62 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -49,13 +49,13 @@ void RenderableTextEntityItem::render(RenderArgs* args) { const float MAX_COLOR = 255.0f; xColor backgroundColor = getBackgroundColorX(); float alpha = 1.0f; //getBackgroundAlpha(); - glColor4f(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha); + glm::vec4 color(backgroundColor.red / MAX_COLOR, backgroundColor.green / MAX_COLOR, backgroundColor.blue / MAX_COLOR, alpha); const float SLIGHTLY_BEHIND = -0.005f; glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - DependencyManager::get()->renderQuad(topLeft, bottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, color); const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index fc84489a2f..59dbfd28b8 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -71,27 +71,27 @@ void DeferredLightingEffect::releaseSimpleProgram() { DependencyManager::get()->setPrimaryDrawBuffers(true, false, false); } -void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks) { +void DeferredLightingEffect::renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSphere(radius, slices, stacks); + DependencyManager::get()->renderSphere(radius, slices, stacks, color); releaseSimpleProgram(); } -void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks) { +void DeferredLightingEffect::renderWireSphere(float radius, int slices, int stacks, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSphere(radius, slices, stacks, false); + DependencyManager::get()->renderSphere(radius, slices, stacks, color, false); releaseSimpleProgram(); } -void DeferredLightingEffect::renderSolidCube(float size) { +void DeferredLightingEffect::renderSolidCube(float size, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderSolidCube(size); + DependencyManager::get()->renderSolidCube(size, color); releaseSimpleProgram(); } -void DeferredLightingEffect::renderWireCube(float size) { +void DeferredLightingEffect::renderWireCube(float size, const glm::vec4& color) { bindSimpleProgram(); - DependencyManager::get()->renderWireCube(size); + DependencyManager::get()->renderWireCube(size, color); releaseSimpleProgram(); } @@ -153,8 +153,6 @@ void DeferredLightingEffect::prepare() { void DeferredLightingEffect::render() { // perform deferred lighting, rendering to free fbo - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - glDisable(GL_BLEND); glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); @@ -295,7 +293,7 @@ void DeferredLightingEffect::render() { } else { glTranslatef(light.position.x, light.position.y, light.position.z); - geometryCache->renderSphere(expandedRadius, 32, 32); + geometryCache->renderSphere(expandedRadius, 32, 32, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); } glPopMatrix(); diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index bf8bb53c92..18e52426c5 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -40,16 +40,16 @@ public: void releaseSimpleProgram(); //// Renders a solid sphere with the simple program. - void renderSolidSphere(float radius, int slices, int stacks); + void renderSolidSphere(float radius, int slices, int stacks, const glm::vec4& color); //// Renders a wireframe sphere with the simple program. - void renderWireSphere(float radius, int slices, int stacks); + void renderWireSphere(float radius, int slices, int stacks, const glm::vec4& color); //// Renders a solid cube with the simple program. - void renderSolidCube(float size); + void renderSolidCube(float size, const glm::vec4& color); //// Renders a wireframe cube with the simple program. - void renderWireCube(float size); + void renderWireCube(float size, const glm::vec4& color); //// Renders a solid cone with the simple program. void renderSolidCone(float base, float height, int slices, int stacks); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 1f4385b04d..d9a89ac4d9 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -134,7 +134,7 @@ const int NUM_COORDS_PER_VERTEX = 3; const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); const int NUM_BYTES_PER_INDEX = sizeof(GLushort); -void GeometryCache::renderSphere(float radius, int slices, int stacks, bool solid) { +void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) { VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)]; int vertices = slices * (stacks - 1) + 2; int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD; @@ -478,7 +478,7 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderGrid(int xDivisions, int yDivisions) { +void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { QOpenGLBuffer& buffer = _gridBuffers[IntPair(xDivisions, yDivisions)]; int vertices = (xDivisions + 1 + yDivisions + 1) * 2; if (!buffer.isCreated()) { @@ -522,7 +522,7 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions) { buffer.release(); } -void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, int id) { +void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, width), glm::vec3(height, rows, cols)); QOpenGLBuffer& buffer = registered ? _registeredAlternateGridBuffers[id] : _alternateGridBuffers[key]; @@ -606,7 +606,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in buffer.release(); } -void GeometryCache::updateVertices(int id, const QVector& points) { +void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { BufferDetails& details = _registeredVertices[id]; if (details.buffer.isCreated()) { @@ -639,7 +639,7 @@ void GeometryCache::updateVertices(int id, const QVector& points) { #endif } -void GeometryCache::updateVertices(int id, const QVector& points) { +void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { BufferDetails& details = _registeredVertices[id]; if (details.buffer.isCreated()) { @@ -685,7 +685,7 @@ void GeometryCache::renderVertices(GLenum mode, int id) { } } -void GeometryCache::renderSolidCube(float size) { +void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { VerticesIndices& vbo = _solidCubeVBOs[size]; const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_FACE = 4; @@ -779,7 +779,7 @@ void GeometryCache::renderSolidCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderWireCube(float size) { +void GeometryCache::renderWireCube(float size, const glm::vec4& color) { VerticesIndices& vbo = _wireCubeVBOs[size]; const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_EDGE = 2; @@ -839,7 +839,7 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, int id) { +void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { bool registeredRect = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); VerticesIndices& vbo = registeredRect ? _registeredRectVBOs[id] : _rectVBOs[key]; @@ -939,7 +939,7 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id) { +void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { bool registeredQuad = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); @@ -1022,7 +1022,8 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, - const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int id) { + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, + const glm::vec4& color, int id) { bool registeredQuad = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); @@ -1120,7 +1121,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int id) { +void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { bool registeredQuad = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); @@ -1537,87 +1538,96 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, glBindBuffer(GL_ARRAY_BUFFER, 0); } -void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, int id) { - bool registeredLine = (id != UNKNOWN_ID); +void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, + const glm::vec4& color1, const glm::vec4& color2, int id) { + + bool registered = (id != UNKNOWN_ID); Vec2Pair key(p1, p2); - VerticesIndices& vbo = registeredLine ? _registeredLine2DVBOs[id] : _line2DVBOs[key]; + + BatchItemDetails& details = registered ? _registeredLine2DVBOs[id] : _line2DVBOs[key]; + + int compactColor1 = ((int(color1.x * 255.0f) & 0xFF)) | + ((int(color1.y * 255.0f) & 0xFF) << 8) | + ((int(color1.z * 255.0f) & 0xFF) << 16) | + ((int(color1.w * 255.0f) & 0xFF) << 24); + + int compactColor2 = ((int(color2.x * 255.0f) & 0xFF)) | + ((int(color2.y * 255.0f) & 0xFF) << 8) | + ((int(color2.z * 255.0f) & 0xFF) << 16) | + ((int(color2.w * 255.0f) & 0xFF) << 24); + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredLine && vbo.first != 0) { + if (registered && details.isCreated) { Vec2Pair& lastKey = _lastRegisteredLine2D[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredLine2D[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderLine() 2D... RELEASING REGISTERED line"; + qDebug() << "renderLine() 2D ... RELEASING REGISTERED line"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderLine() 2D... REUSING PREVIOUSLY REGISTERED line"; + qDebug() << "renderLine() 2D ... REUSING PREVIOUSLY REGISTERED line"; } #endif // def WANT_DEBUG } const int FLOATS_PER_VERTEX = 2; - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 2; - const int indices = 2; - if (vbo.first == 0) { - _lastRegisteredLine2D[id] = key; + if (!details.isCreated) { - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1}; - - int vertexPoint = 0; + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; - // p1 - vertex[vertexPoint++] = p1.x; - vertex[vertexPoint++] = p1.y; + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); - // p2 - vertex[vertexPoint++] = p2.x; - vertex[vertexPoint++] = p2.y; - + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { p1.x, p1.y, p2.x, p2.y }; + + const int NUM_COLOR_SCALARS = 2; + int colors[NUM_COLOR_SCALARS] = { compactColor1, compactColor2 }; + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - #ifdef WANT_DEBUG if (id == UNKNOWN_ID) { - qDebug() << "new renderLine() 2D VBO made -- _line2DVBOs.size():" << _line2DVBOs.size(); + qDebug() << "new renderLine() 2D VBO made -- _line3DVBOs.size():" << _line2DVBOs.size(); } else { qDebug() << "new registered renderLine() 2D VBO made -- _registeredLine2DVBOs.size():" << _registeredLine2DVBOs.size(); } #endif - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + gpu::Batch batch; + + // this is what it takes to render a quad + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::LINES, 2, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 0e216a5bc1..1ea4d11631 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -85,30 +85,36 @@ public: static const int UNKNOWN_ID; void renderHemisphere(int slices, int stacks); - void renderSphere(float radius, int slices, int stacks, bool solid = true); void renderSquare(int xDivisions, int yDivisions); void renderHalfCylinder(int slices, int stacks); void renderCone(float base, float height, int slices, int stacks); - void renderGrid(int xDivisions, int yDivisions); - void renderGrid(int x, int y, int width, int height, int rows, int cols, int id = UNKNOWN_ID); - void renderSolidCube(float size); - void renderWireCube(float size); - void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, int id = UNKNOWN_ID); - void renderQuad(int x, int y, int width, int height, int id = UNKNOWN_ID) - { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), id); } + void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true) + { renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid); } + + void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true); + void renderGrid(int xDivisions, int yDivisions, const glm::vec4& color); + void renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id = UNKNOWN_ID); + void renderSolidCube(float size, const glm::vec4& color); + void renderWireCube(float size, const glm::vec4& color); + void renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id = UNKNOWN_ID); + + void renderQuad(int x, int y, int width, int height, const glm::vec4& color, int id = UNKNOWN_ID) + { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), color, id); } - void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, int id = UNKNOWN_ID); + void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, - const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, int id = UNKNOWN_ID); + const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, + const glm::vec4& color, int id = UNKNOWN_ID); - void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, int id = UNKNOWN_ID); + void renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id = UNKNOWN_ID); + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, + int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) @@ -126,10 +132,23 @@ public: const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); void renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id = UNKNOWN_ID); - void renderLine(const glm::vec2& p1, const glm::vec2& p2, int id = UNKNOWN_ID); - void updateVertices(int id, const QVector& points); - void updateVertices(int id, const QVector& points); + void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID) + { renderLine(p1, p2, glm::vec4(color, 1.0f), id); } + + void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color, int id = UNKNOWN_ID) + { renderLine(p1, p2, color, color, id); } + + + void renderLine(const glm::vec2& p1, const glm::vec2& p2, + const glm::vec3& color1, const glm::vec3& color2, int id = UNKNOWN_ID) + { renderLine(p1, p2, glm::vec4(color1, 1.0f), glm::vec4(color2, 1.0f), id); } + + void renderLine(const glm::vec2& p1, const glm::vec2& p2, + const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); + + void updateVertices(int id, const QVector& points, const glm::vec4& color); + void updateVertices(int id, const QVector& points, const glm::vec4& color); void renderVertices(GLenum mode, int id); /// Loads geometry from the specified URL. @@ -200,8 +219,8 @@ private: QHash _registeredLine3DVBOs; QHash _lastRegisteredLine2D; - QHash _line2DVBOs; - QHash _registeredLine2DVBOs; + QHash _line2DVBOs; + QHash _registeredLine2DVBOs; QHash _registeredVertices; diff --git a/libraries/render-utils/src/GlowEffect.cpp b/libraries/render-utils/src/GlowEffect.cpp index fb7189f61e..30daf8097c 100644 --- a/libraries/render-utils/src/GlowEffect.cpp +++ b/libraries/render-utils/src/GlowEffect.cpp @@ -167,7 +167,6 @@ QOpenGLFramebufferObject* GlowEffect::render(bool toTexture) { } glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); - glColor3f(1.0f, 1.0f, 1.0f); renderFullscreenQuad(); glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); diff --git a/libraries/render-utils/src/RenderUtil.cpp b/libraries/render-utils/src/RenderUtil.cpp index 140ced4c52..c27c56161a 100644 --- a/libraries/render-utils/src/RenderUtil.cpp +++ b/libraries/render-utils/src/RenderUtil.cpp @@ -17,9 +17,10 @@ #include "RenderUtil.h" void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) { + glm::vec4 color(1.0f, 1.0f, 1.0f, 1.0f); glm::vec2 topLeft(-1.0f, -1.0f); glm::vec2 bottomRight(1.0f, 1.0f); glm::vec2 texCoordTopLeft(sMin, tMin); glm::vec2 texCoordBottomRight(sMax, tMax); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, color); } From 72f2e6f3aa8053f96427f33cac008d9a27593082 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 15 Jan 2015 11:37:53 -0800 Subject: [PATCH 04/50] work on colored quads --- libraries/render-utils/src/GeometryCache.cpp | 384 +++++++++---------- libraries/render-utils/src/GeometryCache.h | 21 +- 2 files changed, 199 insertions(+), 206 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 95f91e77d8..3bfff42e38 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -940,276 +940,257 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { - - bool registeredQuad = (id != UNKNOWN_ID); + bool registered = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad2DVBOs[key]; - + BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredQuad && vbo.first != 0) { + if (registered && details.isCreated) { Vec2Pair& lastKey = _lastRegisteredQuad2D[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredQuad2D[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec2... RELEASING REGISTERED QUAD"; + qDebug() << "renderQuad() 2D ... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() vec2... REUSING PREVIOUSLY REGISTERED QUAD"; + qDebug() << "renderQuad() 2D ... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2; - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int FLOATS_PER_VERTEX = 2; // vertices const int vertices = 4; - const int indices = 4; - if (vbo.first == 0) { - _lastRegisteredQuad2D[id] = key; - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - vertex[0] = minCorner.x; - vertex[1] = minCorner.y; - vertex[2] = maxCorner.x; - vertex[3] = minCorner.y; - vertex[4] = maxCorner.x; - vertex[5] = maxCorner.y; - vertex[6] = minCorner.x; - vertex[7] = maxCorner.y; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); - } else { - qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); - } - #endif + if (!details.isCreated) { + + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + minCorner.x, minCorner.y, + maxCorner.x, minCorner.y, + maxCorner.x, maxCorner.y, + minCorner.x, maxCorner.y }; + + const int NUM_COLOR_SCALARS_PER_QUAD = 4; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - glDisableClientState(GL_VERTEX_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} + gpu::Batch batch; + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); +} void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id) { - bool registeredQuad = (id != UNKNOWN_ID); + bool registered = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad2DTextureVBOs[key]; - + BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredQuad && vbo.first != 0) { + if (registered && details.isCreated) { Vec2PairPair& lastKey = _lastRegisteredQuad2DTexture[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredQuad2DTexture[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec2 + texture... RELEASING REGISTERED QUAD"; + qDebug() << "renderQuad() 2D+texture ... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() vec2 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; + qDebug() << "renderQuad() 2D+texture ... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } const int FLOATS_PER_VERTEX = 2 * 2; // text coords & vertices - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; - const int indices = 4; - if (vbo.first == 0) { - _lastRegisteredQuad2DTexture[id] = key; - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - int v = 0; + const int NUM_POS_COORDS = 2; + const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); - vertex[v++] = minCorner.x; - vertex[v++] = minCorner.y; - vertex[v++] = texCoordMinCorner.x; - vertex[v++] = texCoordMinCorner.y; - - vertex[v++] = maxCorner.x; - vertex[v++] = minCorner.y; - vertex[v++] = texCoordMaxCorner.x; - vertex[v++] = texCoordMinCorner.y; - - vertex[v++] = maxCorner.x; - vertex[v++] = maxCorner.y; - vertex[v++] = texCoordMaxCorner.x; - vertex[v++] = texCoordMaxCorner.y; - - vertex[v++] = minCorner.x; - vertex[v++] = maxCorner.y; - vertex[v++] = texCoordMinCorner.x; - vertex[v++] = texCoordMaxCorner.y; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); - } else { - qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); - } - #endif - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + if (!details.isCreated) { + + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + minCorner.x, minCorner.y, texCoordMinCorner.x, texCoordMinCorner.y, + maxCorner.x, minCorner.y, texCoordMaxCorner.x, texCoordMinCorner.y, + maxCorner.x, maxCorner.y, texCoordMaxCorner.x, texCoordMaxCorner.y, + minCorner.x, maxCorner.y, texCoordMinCorner.x, texCoordMaxCorner.y }; + + + const int NUM_COLOR_SCALARS_PER_QUAD = 4; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); - glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(2 * sizeof(float))); + gpu::Batch batch; - glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glEnable(GL_TEXTURE_2D); + //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { - - bool registeredQuad = (id != UNKNOWN_ID); + bool registered = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DVBOs[key]; - + BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredQuad && vbo.first != 0) { + if (registered && details.isCreated) { Vec3Pair& lastKey = _lastRegisteredQuad3D[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredQuad3D[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec3... RELEASING REGISTERED QUAD"; + qDebug() << "renderQuad() 3D ... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() vec3... REUSING PREVIOUSLY REGISTERED QUAD"; + qDebug() << "renderQuad() 3D ... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 3; - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int FLOATS_PER_VERTEX = 3; // vertices const int vertices = 4; - const int indices = 4; - if (vbo.first == 0) { - _lastRegisteredQuad3D[id] = key; - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - int v = 0; - vertex[v++] = minCorner.x; - vertex[v++] = minCorner.y; - vertex[v++] = minCorner.z; + if (!details.isCreated) { - vertex[v++] = maxCorner.x; - vertex[v++] = minCorner.y; - vertex[v++] = minCorner.z; + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; - vertex[v++] = maxCorner.x; - vertex[v++] = maxCorner.y; - vertex[v++] = maxCorner.z; + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); - vertex[v++] = minCorner.x; - vertex[v++] = maxCorner.y; - vertex[v++] = maxCorner.z; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); - } else { - qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); - } - #endif + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + minCorner.x, minCorner.y, minCorner.z, + maxCorner.x, minCorner.y, minCorner.z, + maxCorner.x, maxCorner.y, maxCorner.z, + minCorner.x, maxCorner.y, maxCorner.z }; + + const int NUM_COLOR_SCALARS_PER_QUAD = 4; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - glDisableClientState(GL_VERTEX_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} + gpu::Batch batch; + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); +} void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, @@ -1407,6 +1388,7 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en details.buffer.release(); } + int GeometryCache::BatchItemDetails::population = 0; GeometryCache::BatchItemDetails::BatchItemDetails() : verticesBuffer(NULL), @@ -1435,7 +1417,7 @@ GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItem GeometryCache::BatchItemDetails::~BatchItemDetails() { population--; clear(); - qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; + //qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; } void GeometryCache::BatchItemDetails::clear() { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index ba1c32d51f..d9fb218a03 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -199,17 +199,28 @@ private: QHash _wireCubeVBOs; QHash _solidCubeVBOs; QHash _quad2DVBOs; - QHash _quad2DTextureVBOs; - QHash _quad3DVBOs; + QHash _quad2DTextureVBOs; + //QHash _quad3DVBOs; QHash _quad3DTextureVBOs; QHash _registeredQuadVBOs; int _nextID; - QHash _lastRegisteredQuad2D; - QHash _lastRegisteredQuad2DTexture; - QHash _lastRegisteredQuad3D; QHash _lastRegisteredQuad3DTexture; + + QHash _lastRegisteredQuad2DTexture; + QHash _quad2DTextures; + QHash _registeredQuad2DTextures; + + QHash _lastRegisteredQuad3D; + QHash _quad3D; + QHash _registeredQuad3D; + + QHash _lastRegisteredQuad2D; + QHash _quad2D; + QHash _registeredQuad2D; + + QHash _lastRegisteredRect; QHash _rectVBOs; QHash _registeredRectVBOs; From 149f3654100551650eeed1cb579a18427fdf55f7 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 15 Jan 2015 11:55:45 -0800 Subject: [PATCH 05/50] fix colors for renderBevelCornersRect() --- libraries/render-utils/src/GeometryCache.cpp | 109 ++++++++++--------- libraries/render-utils/src/GeometryCache.h | 7 +- 2 files changed, 61 insertions(+), 55 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 3bfff42e38..0ab2a1a4cc 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -840,40 +840,55 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { - bool registeredRect = (id != UNKNOWN_ID); + bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); - VerticesIndices& vbo = registeredRect ? _registeredRectVBOs[id] : _rectVBOs[key]; - + BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key]; // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredRect && vbo.first != 0) { - Vec3Pair& lastKey = _lastRegisteredRect[id]; + if (registered && details.isCreated) { + Vec3Pair& lastKey = _lastRegisteredBevelRects[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredBevelRects[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderBevelCornersRect()... RELEASING REGISTERED RECT"; + qDebug() << "renderBevelCornersRect()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderBevelCornersRect()... REUSING PREVIOUSLY REGISTERED RECT"; + qDebug() << "renderBevelCornersRect()... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2; - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int FLOATS_PER_VERTEX = 2; // vertices const int vertices = 8; - const int indices = 8; - if (vbo.first == 0) { - _lastRegisteredRect[id] = key; + + if (!details.isCreated) { + + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3, 4, 5, 6, 7}; - + GLfloat* vertexBuffer = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat* vertex = vertexBuffer; int vertexPoint = 0; // left side @@ -902,41 +917,33 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, vertex[vertexPoint++] = x +bevelDistance; vertex[vertexPoint++] = y; - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << "new rect VBO made -- _rectVBOs.size():" << _rectVBOs.size(); - } else { - qDebug() << "new registered rect VBO made -- _registeredRectVBOs.size():" << _registeredRectVBOs.size(); - } - #endif - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + const int NUM_COLOR_SCALARS_PER_QUAD = 8; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); + + delete[] vertexBuffer; } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_POLYGON, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + gpu::Batch batch; + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index d9fb218a03..e42a34813d 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -220,10 +220,9 @@ private: QHash _quad2D; QHash _registeredQuad2D; - - QHash _lastRegisteredRect; - QHash _rectVBOs; - QHash _registeredRectVBOs; + QHash _lastRegisteredBevelRects; + QHash _bevelRects; + QHash _registeredBevelRects; QHash _lastRegisteredLine3D; QHash _line3DVBOs; From daafa20ec62f19938e534c8cb67413cd187ee951 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 15 Jan 2015 17:00:08 -0800 Subject: [PATCH 06/50] first cut at moving wire cube to support gpu streams --- libraries/render-utils/src/GeometryCache.cpp | 88 +++++++++++++------- libraries/render-utils/src/GeometryCache.h | 10 ++- 2 files changed, 67 insertions(+), 31 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 0ab2a1a4cc..8de81aef68 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -780,7 +780,8 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { - VerticesIndices& vbo = _wireCubeVBOs[size]; + + Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_EDGE = 2; const int TOP_EDGES = 4; @@ -788,7 +789,11 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { const int SIDE_EDGES = 4; const int vertices = 8; const int indices = (TOP_EDGES + BOTTOM_EDGES + SIDE_EDGES) * VERTICES_PER_EDGE; - if (vbo.first == 0) { + + if (!_cubeVerticies.contains(size)) { + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + _cubeVerticies[size] = verticesBuffer; + int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a wire cube GLfloat* vertex = vertexData; @@ -799,42 +804,65 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { 1,-1, 1, 1,-1,-1, -1,-1,-1, -1,-1, 1 // v4, v5, v6, v7 (bottom) }; - // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge + for (int i = 0; i < vertexPoints; i++) { + vertex[i] = cannonicalVertices[i] * halfSize; + } + + verticesBuffer->append(sizeof(GLfloat) * vertexPoints, (gpu::Buffer::Byte*) vertexData); // I'm skeptical that this is right + } + + if (!_wireCubeIndexBuffer) { static GLubyte cannonicalIndices[indices] = { 0, 1, 1, 2, 2, 3, 3, 0, // (top) 4, 5, 5, 6, 6, 7, 7, 4, // (bottom) 0, 4, 1, 5, 2, 6, 3, 7, // (side edges) }; - - for (int i = 0; i < vertexPoints; i++) { - vertex[i] = cannonicalVertices[i] * halfSize; - } - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; + + gpu::BufferPointer indexBuffer(new gpu::Buffer()); + _wireCubeIndexBuffer = indexBuffer; - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + _wireCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Buffer::Byte*) cannonicalIndices); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(FLOATS_PER_VERTEX, GL_FLOAT, FLOATS_PER_VERTEX * sizeof(float), 0); - glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - glDisableClientState(GL_VERTEX_ARRAY); + + if (!_cubeColors.contains(colorKey)) { + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + _cubeColors[colorKey] = colorBuffer; + + const int NUM_COLOR_SCALARS_PER_CUBE = 8; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_CUBE] = { compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor }; + + colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); + } + gpu::BufferPointer verticesBuffer = _cubeVerticies[size]; + gpu::BufferPointer colorBuffer = _cubeColors[colorKey]; + + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 1; + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + gpu::BufferView verticesView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); + + gpu::Batch batch; + + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(COLOR_SLOT, colorView); + batch.setIndexBuffer(gpu::UINT8, _wireCubeIndexBuffer, 0); + batch.drawIndexed(gpu::LINES, indices); + + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index e42a34813d..dd743b802d 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -47,6 +47,11 @@ inline uint qHash(const Vec2Pair& v, uint seed) { return qHash(v.first.x + 5009 * v.first.y + 5011 * v.second.x + 5021 * v.second.y, seed); } +inline uint qHash(const glm::vec4& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.x + 5009 * v.y + 5011 * v.z + 5021 * v.w, seed); +} + inline uint qHash(const Vec2PairPair& v, uint seed) { // multiply by prime numbers greater than the possible size return qHash(v.first.first.x + 5009 * v.first.first.y @@ -74,7 +79,6 @@ inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { 5077 * v.second.second.x + 5081 * v.second.second.y, seed); } - /// Stores cached geometry. class GeometryCache : public ResourceCache, public Dependency { Q_OBJECT @@ -173,6 +177,10 @@ private: int vertexSize; }; + QHash _cubeVerticies; + QHash _cubeColors; + gpu::BufferPointer _wireCubeIndexBuffer; + class BatchItemDetails { public: static int population; From 439a1c04957bb49cd8a5350c13669ccfb6719cba Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 15 Jan 2015 18:46:44 -0800 Subject: [PATCH 07/50] solid cube now streamizing --- libraries/gpu/src/gpu/Resource.h | 8 ++ libraries/render-utils/src/GeometryCache.cpp | 131 +++++++++++-------- libraries/render-utils/src/GeometryCache.h | 4 + 3 files changed, 92 insertions(+), 51 deletions(-) diff --git a/libraries/gpu/src/gpu/Resource.h b/libraries/gpu/src/gpu/Resource.h index 2ec616251c..694b4b5592 100644 --- a/libraries/gpu/src/gpu/Resource.h +++ b/libraries/gpu/src/gpu/Resource.h @@ -200,6 +200,14 @@ public: _element(element), _stride(uint16(element.getSize())) {}; + BufferView(const BufferPointer& buffer, Size offset, Size size, uint16 stride, const Element& element = Element(gpu::SCALAR, gpu::UINT8, gpu::RAW)) : + _buffer(buffer), + _offset(offset), + _size(size), + _element(element), + _stride(stride) + {}; + ~BufferView() {} BufferView(const BufferView& view) = default; BufferView& operator=(const BufferView& view) = default; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8de81aef68..75fb2171f7 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -686,20 +686,26 @@ void GeometryCache::renderVertices(GLenum mode, int id) { } void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { - VerticesIndices& vbo = _solidCubeVBOs[size]; + Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_FACE = 4; const int NUMBER_OF_FACES = 6; const int TRIANGLES_PER_FACE = 2; const int VERTICES_PER_TRIANGLE = 3; - const int vertices = NUMBER_OF_FACES * VERTICES_PER_FACE * FLOATS_PER_VERTEX; + const int vertices = NUMBER_OF_FACES * VERTICES_PER_FACE; const int indices = NUMBER_OF_FACES * TRIANGLES_PER_FACE * VERTICES_PER_TRIANGLE; const int vertexPoints = vertices * FLOATS_PER_VERTEX; - if (vbo.first == 0) { + const int VERTEX_STRIDE = sizeof(GLfloat) * FLOATS_PER_VERTEX * 2; // vertices and normals + const int NORMALS_OFFSET = sizeof(GLfloat) * FLOATS_PER_VERTEX; + + if (!_solidCubeVerticies.contains(size)) { + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + _solidCubeVerticies[size] = verticesBuffer; + GLfloat* vertexData = new GLfloat[vertexPoints * 2]; // vertices and normals GLfloat* vertex = vertexData; float halfSize = size / 2.0f; - + static GLfloat cannonicalVertices[vertexPoints] = { 1, 1, 1, -1, 1, 1, -1,-1, 1, 1,-1, 1, // v0,v1,v2,v3 (front) 1, 1, 1, 1,-1, 1, 1,-1,-1, 1, 1,-1, // v0,v3,v4,v5 (right) @@ -717,7 +723,26 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, // v7,v4,v3,v2 (bottom) 0, 0,-1, 0, 0,-1, 0, 0,-1, 0, 0,-1 }; // v4,v7,v6,v5 (back) - // index array of vertex array for glDrawElements() & glDrawRangeElement() + + GLfloat* cannonicalVertex = &cannonicalVertices[0]; + GLfloat* cannonicalNormal = &cannonicalNormals[0]; + + for (int i = 0; i < vertices; i++) { + // vertices + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + *(vertex++) = halfSize * *cannonicalVertex++; + + //normals + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + *(vertex++) = *cannonicalNormal++; + } + + verticesBuffer->append(sizeof(GLfloat) * vertexPoints * 2, (gpu::Buffer::Byte*) vertexData); + } + + if (!_solidCubeIndexBuffer) { static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 2, 3, 0, // front 4, 5, 6, 6, 7, 4, // right @@ -725,62 +750,66 @@ void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { 12,13,14, 14,15,12, // left 16,17,18, 18,19,16, // bottom 20,21,22, 22,23,20 }; // back - - - GLfloat* cannonicalVertex = &cannonicalVertices[0]; - GLfloat* cannonicalNormal = &cannonicalNormals[0]; - - for (int i = 0; i < vertices; i++) { - //normals - *(vertex++) = *cannonicalNormal++; - *(vertex++) = *cannonicalNormal++; - *(vertex++) = *cannonicalNormal++; - - // vertices - *(vertex++) = halfSize * *cannonicalVertex++; - *(vertex++) = halfSize * *cannonicalVertex++; - *(vertex++) = halfSize * *cannonicalVertex++; - - } - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; + gpu::BufferPointer indexBuffer(new gpu::Buffer()); + _solidCubeIndexBuffer = indexBuffer; - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + _solidCubeIndexBuffer->append(sizeof(cannonicalIndices), (gpu::Buffer::Byte*) cannonicalIndices); } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0); - glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float))); - - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); + if (!_solidCubeColors.contains(colorKey)) { + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + _solidCubeColors[colorKey] = colorBuffer; + + const int NUM_COLOR_SCALARS_PER_CUBE = 24; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_CUBE] = { compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor }; + + colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); + } + gpu::BufferPointer verticesBuffer = _solidCubeVerticies[size]; + gpu::BufferPointer colorBuffer = _solidCubeColors[colorKey]; + + const int VERTICES_SLOT = 0; + const int NORMALS_SLOT = 1; + const int COLOR_SLOT = 2; + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::NORMAL, NORMALS_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView normalsView(verticesBuffer, NORMALS_OFFSET, verticesBuffer->getSize(), VERTEX_STRIDE, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element); + gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); + + gpu::Batch batch; + + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(NORMALS_SLOT, normalsView); + batch.setInputBuffer(COLOR_SLOT, colorView); + batch.setIndexBuffer(gpu::UINT8, _solidCubeIndexBuffer, 0); + batch.drawIndexed(gpu::TRIANGLES, indices); + + gpu::GLBackend::renderBatch(batch); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderWireCube(float size, const glm::vec4& color) { - Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_EDGE = 2; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index dd743b802d..1a9230a23a 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -180,6 +180,10 @@ private: QHash _cubeVerticies; QHash _cubeColors; gpu::BufferPointer _wireCubeIndexBuffer; + + QHash _solidCubeVerticies; + QHash _solidCubeColors; + gpu::BufferPointer _solidCubeIndexBuffer; class BatchItemDetails { public: From bddb7856afdeef872a655314ddf97e76734a5e8c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 13:34:09 -0800 Subject: [PATCH 08/50] more work --- interface/src/audio/AudioScope.cpp | 2 +- interface/src/avatar/Avatar.cpp | 3 +- interface/src/avatar/SkeletonModel.cpp | 2 +- interface/src/ui/ApplicationOverlay.cpp | 4 +- interface/src/ui/overlays/Circle3DOverlay.cpp | 10 +- interface/src/ui/overlays/ImageOverlay.cpp | 5 +- .../src/ui/overlays/Rectangle3DOverlay.cpp | 2 +- libraries/gpu/src/gpu/Batch.h | 2 + libraries/gpu/src/gpu/GLBackend.cpp | 2 + libraries/render-utils/src/GeometryCache.cpp | 176 +++++++++++++----- libraries/render-utils/src/GeometryCache.h | 8 +- libraries/render-utils/src/RenderUtil.cpp | 1 + 12 files changed, 150 insertions(+), 67 deletions(-) diff --git a/interface/src/audio/AudioScope.cpp b/interface/src/audio/AudioScope.cpp index 79e52fb5f5..b2e6d35dcf 100644 --- a/interface/src/audio/AudioScope.cpp +++ b/interface/src/audio/AudioScope.cpp @@ -195,7 +195,7 @@ void AudioScope::renderLineStrip(int id, const glm::vec4& color, int x, int y, i geometryCache->updateVertices(id, points, color); - geometryCache->renderVertices(GL_LINE_STRIP, id); + geometryCache->renderVertices(gpu::LINE_STRIP, id); glColor4f(1, 1, 1, 1); } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 690322201b..92f2b72352 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -574,7 +574,6 @@ void Avatar::renderBillboard() { glm::vec2 texCoordBottomRight(1.0f, 1.0f); DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, 1.0f)); - glPopMatrix(); @@ -990,7 +989,7 @@ void Avatar::renderJointConnectingCone(glm::vec3 position1, glm::vec3 position2, // TODO: this is really inefficient constantly recreating these vertices buffers. It would be // better if the avatars cached these buffers for each of the joints they are rendering geometryCache->updateVertices(_jointConesID, points, color); - geometryCache->renderVertices(GL_TRIANGLES, _jointConesID); + geometryCache->renderVertices(gpu::TRIANGLES, _jointConesID); } } diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index 5e179a341c..296ff6fee9 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -367,7 +367,7 @@ void SkeletonModel::renderJointConstraints(int jointIndex) { // TODO: this is really inefficient constantly recreating these vertices buffers. It would be // better if the skeleton model cached these buffers for each of the joints they are rendering geometryCache->updateVertices(_triangleFanID, points, color); - geometryCache->renderVertices(GL_TRIANGLE_FAN, _triangleFanID); + geometryCache->renderVertices(gpu::TRIANGLE_FAN, _triangleFanID); } glPopMatrix(); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 8bf2755509..1a57a16bef 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -767,7 +767,7 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool glDisable(GL_TEXTURE_2D); glLineWidth(1.0f); //Outer Line - geometryCache->renderVertices(GL_LINE_STRIP, _magnifierBorder); + geometryCache->renderVertices(gpu::LINE_STRIP, _magnifierBorder); glEnable(GL_TEXTURE_2D); } glColor4f(1.0f, 1.0f, 1.0f, _alpha); @@ -970,7 +970,7 @@ void ApplicationOverlay::renderDomainConnectionStatusBorder() { glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH); - geometryCache->renderVertices(GL_LINE_STRIP, _domainStatusBorder); + geometryCache->renderVertices(gpu::LINE_STRIP, _domainStatusBorder); } } diff --git a/interface/src/ui/overlays/Circle3DOverlay.cpp b/interface/src/ui/overlays/Circle3DOverlay.cpp index 8244532d5a..f890999174 100644 --- a/interface/src/ui/overlays/Circle3DOverlay.cpp +++ b/interface/src/ui/overlays/Circle3DOverlay.cpp @@ -164,7 +164,7 @@ void Circle3DOverlay::render(RenderArgs* args) { geometryCache->updateVertices(_quadVerticesID, points, color); } - geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID); + geometryCache->renderVertices(gpu::QUAD_STRIP, _quadVerticesID); } else { if (_lineVerticesID == GeometryCache::UNKNOWN_ID) { @@ -203,9 +203,9 @@ void Circle3DOverlay::render(RenderArgs* args) { } if (getIsDashedLine()) { - geometryCache->renderVertices(GL_LINES, _lineVerticesID); + geometryCache->renderVertices(gpu::LINES, _lineVerticesID); } else { - geometryCache->renderVertices(GL_LINE_STRIP, _lineVerticesID); + geometryCache->renderVertices(gpu::LINE_STRIP, _lineVerticesID); } } @@ -280,9 +280,9 @@ void Circle3DOverlay::render(RenderArgs* args) { geometryCache->updateVertices(_minorTicksVerticesID, minorPoints, minorColor); } - geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID); + geometryCache->renderVertices(gpu::LINES, _majorTicksVerticesID); - geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID); + geometryCache->renderVertices(gpu::LINES, _minorTicksVerticesID); } diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 169a3eaa3d..416643a846 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -89,7 +89,7 @@ void ImageOverlay::render(RenderArgs* args) { float imageWidth = _textureImage.width(); float imageHeight = _textureImage.height(); - + QRect fromImage; if (_wantClipFromImage) { fromImage = _fromImage; @@ -114,7 +114,8 @@ void ImageOverlay::render(RenderArgs* args) { glm::vec2 texCoordTopLeft(x, 1.0f - y); glm::vec2 texCoordBottomRight(x + w, 1.0f - (y + h)); - if (_renderImage) { + // if for some reason our image is not over 0 width or height, don't attempt to render the image + if (_renderImage && imageWidth > 0 && imageHeight > 0) { DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, quadColor); } else { DependencyManager::get()->renderQuad(topLeft, bottomRight, quadColor); diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 45873380c4..0c81e932a3 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -100,7 +100,7 @@ void Rectangle3DOverlay::render(RenderArgs* args) { _previousHalfDimensions = halfDimensions; } - geometryCache->renderVertices(GL_LINE_STRIP, _geometryCacheID); + geometryCache->renderVertices(gpu::LINE_STRIP, _geometryCacheID); } } diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index c3a87c8f19..f73ab66d14 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -45,7 +45,9 @@ enum Primitive { LINE_STRIP, TRIANGLES, TRIANGLE_STRIP, + TRIANGLE_FAN, QUADS, + QUAD_STRIP, NUM_PRIMITIVES, }; diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index f5f998d0d9..bd369c0806 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -93,7 +93,9 @@ static const GLenum _primitiveToGLmode[NUM_PRIMITIVES] = { GL_LINE_STRIP, GL_TRIANGLES, GL_TRIANGLE_STRIP, + GL_TRIANGLE_FAN, GL_QUADS, + GL_QUAD_STRIP, }; static const GLenum _elementTypeToGLType[NUM_TYPES]= { diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 75fb2171f7..8d0b7f276a 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -607,81 +607,149 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - BufferDetails& details = _registeredVertices[id]; + qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; + BatchItemDetails& details = _registeredVertices[id]; - if (details.buffer.isCreated()) { - details.buffer.destroy(); + if (details.isCreated) { + details.clear(); #ifdef WANT_DEBUG qDebug() << "updateVertices()... RELEASING REGISTERED"; #endif // def WANT_DEBUG } const int FLOATS_PER_VERTEX = 2; + details.isCreated = true; details.vertices = points.size(); details.vertexSize = FLOATS_PER_VERTEX; + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + details.vertices = points.size(); + details.vertexSize = FLOATS_PER_VERTEX; + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; GLfloat* vertex = vertexData; + int* colorData = new int[details.vertices]; + int* colorDataAt = colorData; + foreach (const glm::vec2& point, points) { *(vertex++) = point.x; *(vertex++) = point.y; + + *(colorDataAt++) = compactColor; } - details.buffer.create(); - details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); - details.buffer.bind(); - details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); - delete[] vertexData; - - #ifdef WANT_DEBUG - qDebug() << "new registered vertices buffer made -- _registeredVertices.size():" << _registeredVertices.size(); - #endif -} - -void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - BufferDetails& details = _registeredVertices[id]; - - if (details.buffer.isCreated()) { - details.buffer.destroy(); - #ifdef WANT_DEBUG - qDebug() << "updateVertices()... RELEASING REGISTERED"; - #endif // def WANT_DEBUG - } - - const int FLOATS_PER_VERTEX = 3; - details.vertices = points.size(); - details.vertexSize = FLOATS_PER_VERTEX; - - GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; - GLfloat* vertex = vertexData; - - foreach (const glm::vec3& point, points) { - *(vertex++) = point.x; - *(vertex++) = point.y; - *(vertex++) = point.z; - } - - details.buffer.create(); - details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); - details.buffer.bind(); - details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); + details.verticesBuffer->append(FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); + details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData); delete[] vertexData; + delete[] colorData; #ifdef WANT_DEBUG qDebug() << "new registered linestrip buffer made -- _registeredVertices.size():" << _registeredVertices.size(); #endif } -void GeometryCache::renderVertices(GLenum mode, int id) { - BufferDetails& details = _registeredVertices[id]; - if (details.buffer.isCreated()) { - details.buffer.bind(); - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); - glDrawArrays(mode, 0, details.vertices); +void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { + qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; + BatchItemDetails& details = _registeredVertices[id]; + + if (details.isCreated) { + details.clear(); + #ifdef WANT_DEBUG + qDebug() << "updateVertices()... RELEASING REGISTERED"; + #endif // def WANT_DEBUG + } + + const int FLOATS_PER_VERTEX = 3; + details.isCreated = true; + details.vertices = points.size(); + details.vertexSize = FLOATS_PER_VERTEX; + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + details.vertices = points.size(); + details.vertexSize = FLOATS_PER_VERTEX; + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + + GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; + GLfloat* vertex = vertexData; + + int* colorData = new int[details.vertices]; + int* colorDataAt = colorData; + + foreach (const glm::vec3& point, points) { + *(vertex++) = point.x; + *(vertex++) = point.y; + *(vertex++) = point.z; + + *(colorDataAt++) = compactColor; + } + + details.verticesBuffer->append(FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); + details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData); + delete[] vertexData; + delete[] colorData; + + #ifdef WANT_DEBUG + qDebug() << "new registered linestrip buffer made -- _registeredVertices.size():" << _registeredVertices.size(); + #endif +} + +void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { + qDebug() << "GeometryCache::renderVertices(id=" << id <<")..."; + + BatchItemDetails& details = _registeredVertices[id]; + if (details.isCreated) { + gpu::Batch batch; + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(primitiveType, details.vertices, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - details.buffer.release(); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } } @@ -897,6 +965,7 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { + qDebug() << "GeometryCache::renderBevelCornersRect(id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key]; @@ -1004,6 +1073,7 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { + qDebug() << "GeometryCache::renderQuad(vec2,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key]; @@ -1087,6 +1157,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id) { + qDebug() << "GeometryCache::renderQuad(vec2/texture,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key]; @@ -1177,6 +1248,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { + qDebug() << "GeometryCache::renderQuad(vec3,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key]; @@ -1464,6 +1536,7 @@ GeometryCache::BatchItemDetails::BatchItemDetails() : isCreated(false) { population++; + qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; } GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) : @@ -1476,12 +1549,13 @@ GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItem isCreated(other.isCreated) { population++; + qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; } GeometryCache::BatchItemDetails::~BatchItemDetails() { population--; clear(); - //qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; + qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; } void GeometryCache::BatchItemDetails::clear() { @@ -1495,6 +1569,7 @@ void GeometryCache::BatchItemDetails::clear() { void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { + qDebug() << "GeometryCache::renderLine(vec3)..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); @@ -1587,6 +1662,7 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { + qDebug() << "GeometryCache::renderLine(vec2)..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(p1, p2); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 1a9230a23a..3aa18efb7e 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -25,7 +25,9 @@ #include -#include "gpu/Stream.h" +#include +#include + class NetworkGeometry; class NetworkMesh; @@ -153,7 +155,7 @@ public: void updateVertices(int id, const QVector& points, const glm::vec4& color); void updateVertices(int id, const QVector& points, const glm::vec4& color); - void renderVertices(GLenum mode, int id); + void renderVertices(gpu::Primitive primitiveType, int id); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable @@ -244,7 +246,7 @@ private: QHash _line2DVBOs; QHash _registeredLine2DVBOs; - QHash _registeredVertices; + QHash _registeredVertices; QHash _lastRegisteredDashedLines; QHash _dashedLines; diff --git a/libraries/render-utils/src/RenderUtil.cpp b/libraries/render-utils/src/RenderUtil.cpp index c27c56161a..7744817625 100644 --- a/libraries/render-utils/src/RenderUtil.cpp +++ b/libraries/render-utils/src/RenderUtil.cpp @@ -22,5 +22,6 @@ void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) { glm::vec2 bottomRight(1.0f, 1.0f); glm::vec2 texCoordTopLeft(sMin, tMin); glm::vec2 texCoordBottomRight(sMax, tMax); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, color); } From ef82aac7a5555410b2b544fddaf3bf44dfea3e81 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 14:48:19 -0800 Subject: [PATCH 09/50] removed some debug, fixed a type mismatch for vec2 vs vec3 --- libraries/render-utils/src/GeometryCache.cpp | 22 ++++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8d0b7f276a..67af878c52 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -607,7 +607,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; + qDebug() << "GeometryCache::updateVertices(vec2.... id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { @@ -632,7 +632,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con details.streamFormat = streamFormat; details.stream = stream; - details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); @@ -652,7 +652,11 @@ void GeometryCache::updateVertices(int id, const QVector& points, con int* colorData = new int[details.vertices]; int* colorDataAt = colorData; + //qDebug() << " details.vertices:" << details.vertices; + //qDebug() << " points.size:" << points.size(); + foreach (const glm::vec2& point, points) { + //qDebug() << " point:" << point; *(vertex++) = point.x; *(vertex++) = point.y; @@ -670,7 +674,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; + //qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { @@ -965,7 +969,7 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { - qDebug() << "GeometryCache::renderBevelCornersRect(id=" << id <<")..."; + //qDebug() << "GeometryCache::renderBevelCornersRect(id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key]; @@ -1073,7 +1077,7 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { - qDebug() << "GeometryCache::renderQuad(vec2,id=" << id <<")..."; + //qDebug() << "GeometryCache::renderQuad(vec2,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key]; @@ -1157,7 +1161,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id) { - qDebug() << "GeometryCache::renderQuad(vec2/texture,id=" << id <<")..."; + //qDebug() << "GeometryCache::renderQuad(vec2/texture,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key]; @@ -1248,7 +1252,7 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { - qDebug() << "GeometryCache::renderQuad(vec3,id=" << id <<")..."; + //qDebug() << "GeometryCache::renderQuad(vec3,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key]; @@ -1569,7 +1573,7 @@ void GeometryCache::BatchItemDetails::clear() { void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { - qDebug() << "GeometryCache::renderLine(vec3)..."; + //qDebug() << "GeometryCache::renderLine(vec3)..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); @@ -1662,7 +1666,7 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { - qDebug() << "GeometryCache::renderLine(vec2)..."; + //qDebug() << "GeometryCache::renderLine(vec2)..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(p1, p2); From 27268a6489bc1ab3f1977e1d7a3b14a2d700baf2 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 15:43:20 -0800 Subject: [PATCH 10/50] fix updateVertices to correctly copy all data --- libraries/render-utils/src/GeometryCache.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 67af878c52..e8a7a1d6cf 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -607,7 +607,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - qDebug() << "GeometryCache::updateVertices(vec2.... id=" << id <<")..."; + //qDebug() << "GeometryCache::updateVertices(vec2.... id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { @@ -652,18 +652,14 @@ void GeometryCache::updateVertices(int id, const QVector& points, con int* colorData = new int[details.vertices]; int* colorDataAt = colorData; - //qDebug() << " details.vertices:" << details.vertices; - //qDebug() << " points.size:" << points.size(); - foreach (const glm::vec2& point, points) { - //qDebug() << " point:" << point; *(vertex++) = point.x; *(vertex++) = point.y; *(colorDataAt++) = compactColor; } - details.verticesBuffer->append(FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); + details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData); delete[] vertexData; delete[] colorData; @@ -727,7 +723,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con *(colorDataAt++) = compactColor; } - details.verticesBuffer->append(FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); + details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData); delete[] vertexData; delete[] colorData; @@ -738,7 +734,7 @@ void GeometryCache::updateVertices(int id, const QVector& points, con } void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { - qDebug() << "GeometryCache::renderVertices(id=" << id <<")..."; + //qDebug() << "GeometryCache::renderVertices(id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { From 0ae695ecf372040714d9b57010920b276b9576de Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 16:54:43 -0800 Subject: [PATCH 11/50] first cut at renderGrid with color --- libraries/render-utils/src/GeometryCache.cpp | 103 ++++++++++++------- libraries/render-utils/src/GeometryCache.h | 14 ++- 2 files changed, 73 insertions(+), 44 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index e8a7a1d6cf..2b197dc078 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -523,31 +523,23 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& } void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { + qDebug() << "GeometryCache::renderGrid(x["<append(sizeof(GLfloat) * vertices * 2, (gpu::Buffer::Byte*) vertexData); delete[] vertexData; - - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << "new grid buffer made -- _alternateGridBuffers.size():" << _alternateGridBuffers.size(); - } else { - qDebug() << "new registered grid buffer made -- _registeredAlternateGridBuffers.size():" << _registeredAlternateGridBuffers.size(); - } - #endif - } else { - buffer.bind(); + if (registered) { + _registeredAlternateGridBuffers[id] = verticesBuffer; + } else { + _alternateGridBuffers[key] = verticesBuffer; + } } - glEnableClientState(GL_VERTEX_ARRAY); + + if (!_gridColors.contains(colorKey)) { + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + _gridColors[colorKey] = colorBuffer; + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + + int* colorData = new int[vertices]; + int* colorDataAt = colorData; + + + for(int v = 0; v < vertices; v++) { + *(colorDataAt++) = compactColor; + } + + colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData); + delete[] colorData; + } + gpu::BufferPointer verticesBuffer = registered ? _registeredAlternateGridBuffers[id] : _alternateGridBuffers[key]; - glVertexPointer(2, GL_FLOAT, 0, 0); + gpu::BufferPointer colorBuffer = _gridColors[colorKey]; + + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 1; + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone - glDrawArrays(GL_LINES, 0, vertices); + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); + gpu::Batch batch; + + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(COLOR_SLOT, colorView); + batch.draw(gpu::LINES, vertices, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - - buffer.release(); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 3aa18efb7e..399c9f9e24 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -178,7 +178,7 @@ private: int vertices; int vertexSize; }; - + QHash _cubeVerticies; QHash _cubeColors; gpu::BufferPointer _wireCubeIndexBuffer; @@ -255,9 +255,15 @@ private: QHash _colors; QHash _gridBuffers; - QHash _registeredAlternateGridBuffers; - QHash _alternateGridBuffers; - QHash _lastRegisteredGrid; + + //QHash _registeredAlternateGridBuffers; + //QHash _alternateGridBuffers; + //QHash _lastRegisteredGrid; + + QHash _registeredAlternateGridBuffers; + QHash _alternateGridBuffers; + QHash _gridColors; + QHash > _networkGeometry; }; From 2b2bd3cb47320387c90551050cd4baa7a5e1493c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 18:08:34 -0800 Subject: [PATCH 12/50] more work on renderGrid with color --- libraries/render-utils/src/GeometryCache.cpp | 74 ++++++++++++++++---- libraries/render-utils/src/GeometryCache.h | 7 +- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2b197dc078..93bfb0a9cd 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -479,11 +479,18 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) } void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { - QOpenGLBuffer& buffer = _gridBuffers[IntPair(xDivisions, yDivisions)]; + qDebug() << "GeometryCache::renderGrid(xDivisions["<append(sizeof(GLfloat) * vertices * 2, (gpu::Buffer::Byte*) vertexData); delete[] vertexData; - } else { - buffer.bind(); + _gridBuffers[key] = verticesBuffer; } - glEnableClientState(GL_VERTEX_ARRAY); + + if (!_gridColors.contains(colorKey)) { + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + _gridColors[colorKey] = colorBuffer; + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + + int* colorData = new int[vertices]; + int* colorDataAt = colorData; + + + for(int v = 0; v < vertices; v++) { + *(colorDataAt++) = compactColor; + } + + colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData); + delete[] colorData; + } + gpu::BufferPointer verticesBuffer = _gridBuffers[key]; + gpu::BufferPointer colorBuffer = _gridColors[colorKey]; + + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 1; + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone - glVertexPointer(2, GL_FLOAT, 0, 0); - - glDrawArrays(GL_LINES, 0, vertices); + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + gpu::BufferView verticesView(verticesBuffer, 0, verticesBuffer->getSize(), streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); + gpu::Batch batch; + + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(COLOR_SLOT, colorView); + batch.draw(gpu::LINES, vertices, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - - buffer.release(); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + } +// TODO: properly handle the x,y,w,h changing for an ID +// TODO: why do we seem to create extra BatchItemDetails when we resize the window?? what's that?? void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id) { qDebug() << "GeometryCache::renderGrid(x["< _colors; - QHash _gridBuffers; - - //QHash _registeredAlternateGridBuffers; - //QHash _alternateGridBuffers; - //QHash _lastRegisteredGrid; - + QHash _gridBuffers; QHash _registeredAlternateGridBuffers; QHash _alternateGridBuffers; QHash _gridColors; From 44b48bab5e8e7e1fad38fb8cbb3cac8e2b1e0cdd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 19 Jan 2015 18:15:47 -0800 Subject: [PATCH 13/50] remove some dead code we don't use --- libraries/render-utils/src/GeometryCache.cpp | 225 +------------------ libraries/render-utils/src/GeometryCache.h | 6 - 2 files changed, 2 insertions(+), 229 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 93bfb0a9cd..48095d615e 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -38,95 +38,12 @@ GeometryCache::GeometryCache() : } GeometryCache::~GeometryCache() { - foreach (const VerticesIndices& vbo, _hemisphereVBOs) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - } qDebug() << "GeometryCache::~GeometryCache()... "; qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size(); qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population; } -void GeometryCache::renderHemisphere(int slices, int stacks) { - VerticesIndices& vbo = _hemisphereVBOs[IntPair(slices, stacks)]; - int vertices = slices * (stacks - 1) + 1; - int indices = slices * 2 * 3 * (stacks - 2) + slices * 3; - if (vbo.first == 0) { - GLfloat* vertexData = new GLfloat[vertices * 3]; - GLfloat* vertex = vertexData; - for (int i = 0; i < stacks - 1; i++) { - float phi = PI_OVER_TWO * (float)i / (float)(stacks - 1); - float z = sinf(phi), radius = cosf(phi); - - for (int j = 0; j < slices; j++) { - float theta = TWO_PI * (float)j / (float)slices; - - *(vertex++) = sinf(theta) * radius; - *(vertex++) = cosf(theta) * radius; - *(vertex++) = z; - } - } - *(vertex++) = 0.0f; - *(vertex++) = 0.0f; - *(vertex++) = 1.0f; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - const int BYTES_PER_VERTEX = 3 * sizeof(GLfloat); - glBufferData(GL_ARRAY_BUFFER, vertices * BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < stacks - 2; i++) { - GLushort bottom = i * slices; - GLushort top = bottom + slices; - for (int j = 0; j < slices; j++) { - int next = (j + 1) % slices; - - *(index++) = bottom + j; - *(index++) = top + next; - *(index++) = top + j; - - *(index++) = bottom + j; - *(index++) = bottom + next; - *(index++) = top + next; - } - } - GLushort bottom = (stacks - 2) * slices; - GLushort top = bottom + slices; - for (int i = 0; i < slices; i++) { - *(index++) = bottom + i; - *(index++) = bottom + (i + 1) % slices; - *(index++) = top; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - const int BYTES_PER_INDEX = sizeof(GLushort); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - glVertexPointer(3, GL_FLOAT, 0, 0); - glNormalPointer(GL_FLOAT, 0, 0); - - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - const int NUM_VERTICES_PER_TRIANGLE = 3; const int NUM_TRIANGLES_PER_QUAD = 2; const int NUM_VERTICES_PER_TRIANGULATED_QUAD = NUM_VERTICES_PER_TRIANGLE * NUM_TRIANGLES_PER_QUAD; @@ -240,146 +157,8 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderSquare(int xDivisions, int yDivisions) { - VerticesIndices& vbo = _squareVBOs[IntPair(xDivisions, yDivisions)]; - int xVertices = xDivisions + 1; - int yVertices = yDivisions + 1; - int vertices = xVertices * yVertices; - int indices = 2 * 3 * xDivisions * yDivisions; - if (vbo.first == 0) { - GLfloat* vertexData = new GLfloat[vertices * 3]; - GLfloat* vertex = vertexData; - for (int i = 0; i <= yDivisions; i++) { - float y = (float)i / yDivisions; - - for (int j = 0; j <= xDivisions; j++) { - *(vertex++) = (float)j / xDivisions; - *(vertex++) = y; - *(vertex++) = 0.0f; - } - } - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < yDivisions; i++) { - GLushort bottom = i * xVertices; - GLushort top = bottom + xVertices; - for (int j = 0; j < xDivisions; j++) { - int next = j + 1; - - *(index++) = bottom + j; - *(index++) = top + next; - *(index++) = top + j; - - *(index++) = bottom + j; - *(index++) = bottom + next; - *(index++) = top + next; - } - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - } - glEnableClientState(GL_VERTEX_ARRAY); - - // all vertices have the same normal - glNormal3f(0.0f, 0.0f, 1.0f); - - glVertexPointer(3, GL_FLOAT, 0, 0); - - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - -void GeometryCache::renderHalfCylinder(int slices, int stacks) { - VerticesIndices& vbo = _halfCylinderVBOs[IntPair(slices, stacks)]; - int vertices = (slices + 1) * stacks; - int indices = 2 * 3 * slices * (stacks - 1); - if (vbo.first == 0) { - GLfloat* vertexData = new GLfloat[vertices * 2 * 3]; - GLfloat* vertex = vertexData; - for (int i = 0; i <= (stacks - 1); i++) { - float y = (float)i / (stacks - 1); - - for (int j = 0; j <= slices; j++) { - float theta = 3.0f * PI_OVER_TWO + PI * (float)j / (float)slices; - - //normals - *(vertex++) = sinf(theta); - *(vertex++) = 0; - *(vertex++) = cosf(theta); - - // vertices - *(vertex++) = sinf(theta); - *(vertex++) = y; - *(vertex++) = cosf(theta); - } - } - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, 2 * vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < stacks - 1; i++) { - GLushort bottom = i * (slices + 1); - GLushort top = bottom + slices + 1; - for (int j = 0; j < slices; j++) { - int next = j + 1; - - *(index++) = bottom + j; - *(index++) = top + next; - *(index++) = top + j; - - *(index++) = bottom + j; - *(index++) = bottom + next; - *(index++) = top + next; - } - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; - - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); - - glNormalPointer(GL_FLOAT, 6 * sizeof(float), 0); - glVertexPointer(3, GL_FLOAT, (6 * sizeof(float)), (const void *)(3 * sizeof(float))); - - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - - glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); -} - void GeometryCache::renderCone(float base, float height, int slices, int stacks) { - VerticesIndices& vbo = _halfCylinderVBOs[IntPair(slices, stacks)]; + VerticesIndices& vbo = _coneVBOs[IntPair(slices, stacks)]; int vertices = (stacks + 2) * slices; int baseTriangles = slices - 2; int indices = NUM_VERTICES_PER_TRIANGULATED_QUAD * slices * stacks + NUM_VERTICES_PER_TRIANGLE * baseTriangles; @@ -479,7 +258,7 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) } void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { - qDebug() << "GeometryCache::renderGrid(xDivisions["< _hemisphereVBOs; QHash _sphereVBOs; - QHash _squareVBOs; - QHash _halfCylinderVBOs; QHash _coneVBOs; QHash _wireCubeVBOs; QHash _solidCubeVBOs; From 4c9b7f46a28ef85bc3ad8f977b7530d7410cfd7f Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 21 Jan 2015 10:03:25 -0800 Subject: [PATCH 14/50] cleanup --- libraries/render-utils/src/GeometryCache.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index ab69528623..ae24fb74f9 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -208,7 +208,6 @@ private: QHash _solidCubeVBOs; QHash _quad2DVBOs; QHash _quad2DTextureVBOs; - //QHash _quad3DVBOs; QHash _quad3DTextureVBOs; QHash _registeredQuadVBOs; int _nextID; From 02a68096c364575d82e7bcad50c5be8f9f9bda83 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 21 Jan 2015 16:56:04 -0800 Subject: [PATCH 15/50] add debug for vec4 --- libraries/shared/src/StreamUtils.cpp | 10 ++++++++++ libraries/shared/src/StreamUtils.h | 1 + 2 files changed, 11 insertions(+) diff --git a/libraries/shared/src/StreamUtils.cpp b/libraries/shared/src/StreamUtils.cpp index 47bb8dd4e4..96967648ed 100644 --- a/libraries/shared/src/StreamUtils.cpp +++ b/libraries/shared/src/StreamUtils.cpp @@ -115,6 +115,16 @@ QDebug& operator<<(QDebug& dbg, const glm::vec3& v) { return dbg; } +QDebug& operator<<(QDebug& dbg, const glm::vec4& v) { + dbg.nospace() << "{type='glm::vec4'" + ", x=" << v.x << + ", y=" << v.y << + ", z=" << v.z << + ", w=" << v.w << + "}"; + return dbg; +} + QDebug& operator<<(QDebug& dbg, const glm::quat& q) { dbg.nospace() << "{type='glm::quat'" ", x=" << q.x << diff --git a/libraries/shared/src/StreamUtils.h b/libraries/shared/src/StreamUtils.h index d176d68e45..b9823a6743 100644 --- a/libraries/shared/src/StreamUtils.h +++ b/libraries/shared/src/StreamUtils.h @@ -51,6 +51,7 @@ class QDebug; // Add support for writing these to qDebug(). QDebug& operator<<(QDebug& s, const glm::vec2& v); QDebug& operator<<(QDebug& s, const glm::vec3& v); +QDebug& operator<<(QDebug& s, const glm::vec4& v); QDebug& operator<<(QDebug& s, const glm::quat& q); QDebug& operator<<(QDebug& s, const glm::mat4& m); #endif // QT_NO_DEBUG_STREAM From 9152865116dec05aaacb0a59dc6c391e8465e621 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 21 Jan 2015 16:56:41 -0800 Subject: [PATCH 16/50] first cut at supporting streamized spheres --- libraries/render-utils/src/GeometryCache.cpp | 113 ++++++++++++++----- libraries/render-utils/src/GeometryCache.h | 11 +- 2 files changed, 92 insertions(+), 32 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 48095d615e..294cd78544 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -52,10 +52,22 @@ const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat); const int NUM_BYTES_PER_INDEX = sizeof(GLushort); void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) { - VerticesIndices& vbo = _sphereVBOs[IntPair(slices, stacks)]; + + //Vec2Pair key(glm::vec2(radius, slices), glm::vec2(stacks, 0)); + IntPair key(slices, stacks); + +//qDebug() << " key:" << key; + + Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks)); + + int vertices = slices * (stacks - 1) + 2; int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD; - if (vbo.first == 0) { + + if (!_sphereVertices.contains(key)) { + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + _sphereVertices[key] = verticesBuffer; + GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX]; GLfloat* vertex = vertexData; @@ -82,12 +94,21 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm *(vertex++) = 0.0f; *(vertex++) = 0.0f; *(vertex++) = 1.0f; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + + verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData); delete[] vertexData; - +qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << " radius:" << radius; +qDebug() << " slices:" << slices; +qDebug() << " stacks:" << stacks; + +qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); + } + + if (!_sphereIndices.contains(key)) { + gpu::BufferPointer indicesBuffer(new gpu::Buffer()); + _sphereIndices[key] = indicesBuffer; + GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; @@ -125,34 +146,73 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm *(index++) = bottom + i; *(index++) = top; } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData); delete[] indexData; +qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << " radius:" << radius; +qDebug() << " slices:" << slices; +qDebug() << " stacks:" << stacks; + +qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); + } + + if (!_sphereColors.contains(colorKey)) { + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + _sphereColors[colorKey] = colorBuffer; + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + + int* colorData = new int[vertices]; + int* colorDataAt = colorData; + + for(int v = 0; v < vertices; v++) { + *(colorDataAt++) = compactColor; + } + + colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData); + delete[] colorData; + +qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << " color:" << color; + +qDebug() << " _sphereColors.size():" << _sphereColors.size(); + + } + gpu::BufferPointer verticesBuffer = _sphereVertices[key]; + gpu::BufferPointer indicesBuffer = _sphereIndices[key]; + gpu::BufferPointer colorBuffer = _sphereColors[colorKey]; + - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_NORMAL_ARRAY); + const int VERTICES_SLOT = 0; + const int COLOR_SLOT = 1; + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone + streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + gpu::BufferView verticesView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); + + gpu::Batch batch; - glVertexPointer(3, GL_FLOAT, 0, 0); - glNormalPointer(GL_FLOAT, 0, 0); + batch.setInputFormat(streamFormat); + batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(COLOR_SLOT, colorView); + batch.setIndexBuffer(gpu::UINT16, indicesBuffer, 0); - glPushMatrix(); - glScalef(radius, radius, radius); if (solid) { - glDrawRangeElementsEXT(GL_TRIANGLES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + batch.drawIndexed(gpu::TRIANGLES, indices); } else { - glDrawRangeElementsEXT(GL_LINES, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + batch.drawIndexed(gpu::LINES, indices); } - glPopMatrix(); + + gpu::GLBackend::renderBatch(batch); glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } @@ -307,7 +367,6 @@ void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& int* colorData = new int[vertices]; int* colorDataAt = colorData; - for(int v = 0; v < vertices; v++) { *(colorDataAt++) = compactColor; } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index ae24fb74f9..d53bd727d8 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -34,6 +34,8 @@ class NetworkMesh; class NetworkTexture; +typedef glm::vec3 Vec3Key; + typedef QPair Vec2Pair; typedef QPair Vec2PairPair; typedef QPair Vec3Pair; @@ -62,11 +64,6 @@ inline uint qHash(const Vec2PairPair& v, uint seed) { + 5051 * v.second.second.x + 5059 * v.second.second.y, seed); } -inline uint qHash(const glm::vec3& v, uint seed) { - // multiply by prime numbers greater than the possible size - return qHash(v.x + 5009 * v.y + 5011 * v.z, seed); -} - inline uint qHash(const Vec3Pair& v, uint seed) { // multiply by prime numbers greater than the possible size return qHash(v.first.x + 5009 * v.first.y + 5011 * v.first.z @@ -251,6 +248,10 @@ private: QHash _registeredAlternateGridBuffers; QHash _alternateGridBuffers; QHash _gridColors; + + QHash _sphereVertices; + QHash _sphereIndices; + QHash _sphereColors; QHash > _networkGeometry; From 5df45c7dce0685e0e1c764dd4fe9da15672e6276 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 16:55:16 -0800 Subject: [PATCH 17/50] build buster and warnings fixes --- interface/src/ui/overlays/ImageOverlay.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 4ff49d1377..2ce00d9c17 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -30,9 +30,9 @@ ImageOverlay::ImageOverlay() : ImageOverlay::ImageOverlay(const ImageOverlay* imageOverlay) : Overlay2D(imageOverlay), - _texture(imageOverlay->_texture), _imageURL(imageOverlay->_imageURL), _textureImage(imageOverlay->_textureImage), + _texture(imageOverlay->_texture), _fromImage(imageOverlay->_fromImage), _renderImage(imageOverlay->_renderImage), _wantClipFromImage(imageOverlay->_wantClipFromImage) @@ -86,10 +86,11 @@ void ImageOverlay::render(RenderArgs* args) { glm::vec2 topLeft(left, top); glm::vec2 bottomRight(right, bottom); + float imageWidth = _texture->getWidth(); + float imageHeight = _texture->getHeight(); + // if for some reason our image is not over 0 width or height, don't attempt to render the image if (_renderImage && imageWidth > 0 && imageHeight > 0) { - float imageWidth = _texture->getWidth(); - float imageHeight = _texture->getHeight(); QRect fromImage; if (_wantClipFromImage) { From e7742351b7f278e07be703a15c0071ab79dff743 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 20:30:58 -0800 Subject: [PATCH 18/50] get sizing for spheres to work properly --- .../src/RenderableSphereEntityItem.cpp | 4 ++- libraries/render-utils/src/GeometryCache.cpp | 36 ++++++++++--------- libraries/render-utils/src/GeometryCache.h | 2 +- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index e6ea75dfee..66536f76d6 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -46,7 +46,9 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderSolidSphere(0.5f, 15, 15, sphereColor); + const int SLICES = 40; + const int STACKS = 40; + DependencyManager::get()->renderSolidSphere(0.5f, SLICES, STACKS, sphereColor); glPopMatrix(); glPopMatrix(); }; diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 294cd78544..1b7fe97ccf 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -53,10 +53,11 @@ const int NUM_BYTES_PER_INDEX = sizeof(GLushort); void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) { - //Vec2Pair key(glm::vec2(radius, slices), glm::vec2(stacks, 0)); - IntPair key(slices, stacks); + Vec2Pair keyRadius(glm::vec2(radius, slices), glm::vec2(stacks, 0)); + IntPair keySlicesStacks(slices, stacks); //qDebug() << " key:" << key; +//qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks; Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks)); @@ -64,9 +65,9 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm int vertices = slices * (stacks - 1) + 2; int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD; - if (!_sphereVertices.contains(key)) { + if (!_sphereVertices.contains(keyRadius)) { gpu::BufferPointer verticesBuffer(new gpu::Buffer()); - _sphereVertices[key] = verticesBuffer; + _sphereVertices[keyRadius] = verticesBuffer; GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX]; GLfloat* vertex = vertexData; @@ -74,18 +75,19 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm // south pole *(vertex++) = 0.0f; *(vertex++) = 0.0f; - *(vertex++) = -1.0f; + *(vertex++) = -1.0f * radius; //add stacks vertices climbing up Y axis for (int i = 1; i < stacks; i++) { float phi = PI * (float)i / (float)(stacks) - PI_OVER_TWO; - float z = sinf(phi), radius = cosf(phi); + float z = sinf(phi) * radius; + float stackRadius = cosf(phi) * radius; for (int j = 0; j < slices; j++) { float theta = TWO_PI * (float)j / (float)slices; - *(vertex++) = sinf(theta) * radius; - *(vertex++) = cosf(theta) * radius; + *(vertex++) = sinf(theta) * stackRadius; + *(vertex++) = cosf(theta) * stackRadius; *(vertex++) = z; } } @@ -93,11 +95,11 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm // north pole *(vertex++) = 0.0f; *(vertex++) = 0.0f; - *(vertex++) = 1.0f; + *(vertex++) = 1.0f * radius; verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData); delete[] vertexData; -qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << "GeometryCache::renderSphere()... --- CREATING VERTICES BUFFER"; qDebug() << " radius:" << radius; qDebug() << " slices:" << slices; qDebug() << " stacks:" << stacks; @@ -105,9 +107,9 @@ qDebug() << " stacks:" << stacks; qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); } - if (!_sphereIndices.contains(key)) { + if (!_sphereIndices.contains(keySlicesStacks)) { gpu::BufferPointer indicesBuffer(new gpu::Buffer()); - _sphereIndices[key] = indicesBuffer; + _sphereIndices[keySlicesStacks] = indicesBuffer; GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; @@ -148,7 +150,7 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); } indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData); delete[] indexData; -qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER"; qDebug() << " radius:" << radius; qDebug() << " slices:" << slices; qDebug() << " stacks:" << stacks; @@ -175,14 +177,16 @@ qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData); delete[] colorData; -qDebug() << "GeometryCache::renderSphere()..."; +qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER"; qDebug() << " color:" << color; +qDebug() << " slices:" << slices; +qDebug() << " stacks:" << stacks; qDebug() << " _sphereColors.size():" << _sphereColors.size(); } - gpu::BufferPointer verticesBuffer = _sphereVertices[key]; - gpu::BufferPointer indicesBuffer = _sphereIndices[key]; + gpu::BufferPointer verticesBuffer = _sphereVertices[keyRadius]; + gpu::BufferPointer indicesBuffer = _sphereIndices[keySlicesStacks]; gpu::BufferPointer colorBuffer = _sphereColors[colorKey]; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index d53bd727d8..b95e92dcd9 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -249,7 +249,7 @@ private: QHash _alternateGridBuffers; QHash _gridColors; - QHash _sphereVertices; + QHash _sphereVertices; QHash _sphereIndices; QHash _sphereColors; From 9631761f70d095ba17720ff398c323011e326928 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 27 Jan 2015 21:39:59 -0800 Subject: [PATCH 19/50] get sphere normals correct --- .../src/RenderableSphereEntityItem.cpp | 4 +-- libraries/render-utils/src/GeometryCache.cpp | 34 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index 66536f76d6..a957bc6196 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -46,8 +46,8 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - const int SLICES = 40; - const int STACKS = 40; + const int SLICES = 10; //40; + const int STACKS = 10; DependencyManager::get()->renderSolidSphere(0.5f, SLICES, STACKS, sphereColor); glPopMatrix(); glPopMatrix(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 1b7fe97ccf..9960c69f63 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -63,7 +63,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm int vertices = slices * (stacks - 1) + 2; - int indices = slices * stacks * NUM_VERTICES_PER_TRIANGULATED_QUAD; + int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD; if (!_sphereVertices.contains(keyRadius)) { gpu::BufferPointer verticesBuffer(new gpu::Buffer()); @@ -113,6 +113,8 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; + + int indexCount = 0; // South cap GLushort bottom = 0; @@ -121,6 +123,8 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); *(index++) = bottom; *(index++) = top + i; *(index++) = top + (i + 1) % slices; + + indexCount += 3; } // (stacks - 2) ribbons @@ -133,10 +137,15 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); *(index++) = top + next; *(index++) = bottom + j; *(index++) = top + j; + + indexCount += 3; *(index++) = bottom + next; *(index++) = bottom + j; *(index++) = top + next; + + indexCount += 3; + } } @@ -147,6 +156,9 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); *(index++) = bottom + (i + 1) % slices; *(index++) = bottom + i; *(index++) = top; + + indexCount += 3; + } indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData); delete[] indexData; @@ -154,6 +166,8 @@ qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER"; qDebug() << " radius:" << radius; qDebug() << " slices:" << slices; qDebug() << " stacks:" << stacks; +qDebug() << "indexCount:" << indexCount; +qDebug() << " indices:" << indices; qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); } @@ -169,7 +183,7 @@ qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); int* colorData = new int[vertices]; int* colorDataAt = colorData; - + for(int v = 0; v < vertices; v++) { *(colorDataAt++) = compactColor; } @@ -178,6 +192,7 @@ qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); delete[] colorData; qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER"; +qDebug() << " vertices:" << vertices; qDebug() << " color:" << color; qDebug() << " slices:" << slices; qDebug() << " stacks:" << stacks; @@ -188,21 +203,32 @@ qDebug() << " _sphereColors.size():" << _sphereColors.size(); gpu::BufferPointer verticesBuffer = _sphereVertices[keyRadius]; gpu::BufferPointer indicesBuffer = _sphereIndices[keySlicesStacks]; gpu::BufferPointer colorBuffer = _sphereColors[colorKey]; + + #ifdef WANT_DEBUG + qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks; + qDebug() << " vertices:" << vertices; + qDebug() << " indices:" << indices; + qDebug() << " colorBuffer->getSize():" << colorBuffer->getSize(); + #endif //def WANT_DEBUG const int VERTICES_SLOT = 0; - const int COLOR_SLOT = 1; + const int NORMALS_SLOT = 1; + const int COLOR_SLOT = 2; gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); // 1 for everyone streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::POS_XYZ), 0); + streamFormat->setAttribute(gpu::Stream::NORMAL, NORMALS_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ)); streamFormat->setAttribute(gpu::Stream::COLOR, COLOR_SLOT, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); - + gpu::BufferView verticesView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::POSITION)._element); + gpu::BufferView normalsView(verticesBuffer, streamFormat->getAttributes().at(gpu::Stream::NORMAL)._element); gpu::BufferView colorView(colorBuffer, streamFormat->getAttributes().at(gpu::Stream::COLOR)._element); gpu::Batch batch; batch.setInputFormat(streamFormat); batch.setInputBuffer(VERTICES_SLOT, verticesView); + batch.setInputBuffer(NORMALS_SLOT, normalsView); batch.setInputBuffer(COLOR_SLOT, colorView); batch.setIndexBuffer(gpu::UINT16, indicesBuffer, 0); From 30f985a6fefa364cc4bdf2c687fed8d1186c6a83 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 10:30:05 -0800 Subject: [PATCH 20/50] some cleanup --- interface/src/ui/BandwidthMeter.cpp | 1 - .../src/RenderableSphereEntityItem.cpp | 9 +- libraries/render-utils/src/GeometryCache.cpp | 113 ++++++++---------- 3 files changed, 59 insertions(+), 64 deletions(-) diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index a29f16b851..d6ec937d1d 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -170,7 +170,6 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT); // Render vertical lines for the frame - //setColorRGBA(COLOR_FRAME); renderVerticalLine(0, 0, h, COLOR_FRAME); renderVerticalLine(barWidth, 0, h, COLOR_FRAME); diff --git a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp index a957bc6196..427ed20a8b 100644 --- a/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableSphereEntityItem.cpp @@ -46,8 +46,13 @@ void RenderableSphereEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - const int SLICES = 10; //40; - const int STACKS = 10; + + // TODO: it would be cool to select different slices/stacks geometry based on the size of the sphere + // and the distance to the viewer. This would allow us to reduce the triangle count for smaller spheres + // that aren't close enough to see the tessellation and use larger triangle count for spheres that would + // expose that effect + const int SLICES = 15; + const int STACKS = 15; DependencyManager::get()->renderSolidSphere(0.5f, SLICES, STACKS, sphereColor); glPopMatrix(); glPopMatrix(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 9960c69f63..e44603cb60 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -38,10 +38,12 @@ GeometryCache::GeometryCache() : } GeometryCache::~GeometryCache() { - qDebug() << "GeometryCache::~GeometryCache()... "; - qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); - qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size(); - qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population; + #ifdef WANT_DEBUG + qDebug() << "GeometryCache::~GeometryCache()... "; + qDebug() << " _registeredLine3DVBOs.size():" << _registeredLine3DVBOs.size(); + qDebug() << " _line3DVBOs.size():" << _line3DVBOs.size(); + qDebug() << " BatchItemDetails... population:" << GeometryCache::BatchItemDetails::population; + #endif //def WANT_DEBUG } const int NUM_VERTICES_PER_TRIANGLE = 3; @@ -53,21 +55,16 @@ const int NUM_BYTES_PER_INDEX = sizeof(GLushort); void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) { - Vec2Pair keyRadius(glm::vec2(radius, slices), glm::vec2(stacks, 0)); - IntPair keySlicesStacks(slices, stacks); - -//qDebug() << " key:" << key; -//qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks; - + Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0)); + IntPair slicesStacksKey(slices, stacks); Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks)); - int vertices = slices * (stacks - 1) + 2; int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD; - if (!_sphereVertices.contains(keyRadius)) { + if (!_sphereVertices.contains(radiusKey)) { gpu::BufferPointer verticesBuffer(new gpu::Buffer()); - _sphereVertices[keyRadius] = verticesBuffer; + _sphereVertices[radiusKey] = verticesBuffer; GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX]; GLfloat* vertex = vertexData; @@ -99,17 +96,20 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm verticesBuffer->append(sizeof(GLfloat) * vertices * NUM_COORDS_PER_VERTEX, (gpu::Buffer::Byte*) vertexData); delete[] vertexData; -qDebug() << "GeometryCache::renderSphere()... --- CREATING VERTICES BUFFER"; -qDebug() << " radius:" << radius; -qDebug() << " slices:" << slices; -qDebug() << " stacks:" << stacks; -qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); + #ifdef WANT_DEBUG + qDebug() << "GeometryCache::renderSphere()... --- CREATING VERTICES BUFFER"; + qDebug() << " radius:" << radius; + qDebug() << " slices:" << slices; + qDebug() << " stacks:" << stacks; + + qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); + #endif } - if (!_sphereIndices.contains(keySlicesStacks)) { + if (!_sphereIndices.contains(slicesStacksKey)) { gpu::BufferPointer indicesBuffer(new gpu::Buffer()); - _sphereIndices[keySlicesStacks] = indicesBuffer; + _sphereIndices[slicesStacksKey] = indicesBuffer; GLushort* indexData = new GLushort[indices]; GLushort* index = indexData; @@ -162,14 +162,16 @@ qDebug() << " _sphereVertices.size():" << _sphereVertices.size(); } indicesBuffer->append(sizeof(GLushort) * indices, (gpu::Buffer::Byte*) indexData); delete[] indexData; -qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER"; -qDebug() << " radius:" << radius; -qDebug() << " slices:" << slices; -qDebug() << " stacks:" << stacks; -qDebug() << "indexCount:" << indexCount; -qDebug() << " indices:" << indices; - -qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); + + #ifdef WANT_DEBUG + qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER"; + qDebug() << " radius:" << radius; + qDebug() << " slices:" << slices; + qDebug() << " stacks:" << stacks; + qDebug() << "indexCount:" << indexCount; + qDebug() << " indices:" << indices; + qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); + #endif } if (!_sphereColors.contains(colorKey)) { @@ -191,27 +193,20 @@ qDebug() << " _sphereIndices.size():" << _sphereIndices.size(); colorBuffer->append(sizeof(int) * vertices, (gpu::Buffer::Byte*) colorData); delete[] colorData; -qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER"; -qDebug() << " vertices:" << vertices; -qDebug() << " color:" << color; -qDebug() << " slices:" << slices; -qDebug() << " stacks:" << stacks; - -qDebug() << " _sphereColors.size():" << _sphereColors.size(); + #ifdef WANT_DEBUG + qDebug() << "GeometryCache::renderSphere()... --- CREATING COLORS BUFFER"; + qDebug() << " vertices:" << vertices; + qDebug() << " color:" << color; + qDebug() << " slices:" << slices; + qDebug() << " stacks:" << stacks; + qDebug() << " _sphereColors.size():" << _sphereColors.size(); + #endif } - gpu::BufferPointer verticesBuffer = _sphereVertices[keyRadius]; - gpu::BufferPointer indicesBuffer = _sphereIndices[keySlicesStacks]; + gpu::BufferPointer verticesBuffer = _sphereVertices[radiusKey]; + gpu::BufferPointer indicesBuffer = _sphereIndices[slicesStacksKey]; gpu::BufferPointer colorBuffer = _sphereColors[colorKey]; - #ifdef WANT_DEBUG - qDebug() << "renderSphere() radius:" << radius << "slices:" << slices << "stacks:" << stacks; - qDebug() << " vertices:" << vertices; - qDebug() << " indices:" << indices; - qDebug() << " colorBuffer->getSize():" << colorBuffer->getSize(); - #endif //def WANT_DEBUG - - const int VERTICES_SLOT = 0; const int NORMALS_SLOT = 1; const int COLOR_SLOT = 2; @@ -348,8 +343,6 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) } void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { - //qDebug() << "GeometryCache::renderGrid(xDivisions["<& points, const glm::vec4& color) { - //qDebug() << "GeometryCache::updateVertices(vec2.... id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { @@ -605,7 +599,6 @@ void GeometryCache::updateVertices(int id, const QVector& points, con } void GeometryCache::updateVertices(int id, const QVector& points, const glm::vec4& color) { - //qDebug() << "GeometryCache::updateVertices(id=" << id <<")..."; BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { @@ -669,8 +662,6 @@ void GeometryCache::updateVertices(int id, const QVector& points, con } void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { - //qDebug() << "GeometryCache::renderVertices(id=" << id <<")..."; - BatchItemDetails& details = _registeredVertices[id]; if (details.isCreated) { gpu::Batch batch; @@ -900,7 +891,6 @@ void GeometryCache::renderWireCube(float size, const glm::vec4& color) { } void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, int bevelDistance, const glm::vec4& color, int id) { - //qDebug() << "GeometryCache::renderBevelCornersRect(id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, 0.0f), glm::vec3(width, height, bevelDistance)); BatchItemDetails& details = registered ? _registeredBevelRects[id] : _bevelRects[key]; @@ -1008,7 +998,6 @@ void GeometryCache::renderBevelCornersRect(int x, int y, int width, int height, } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { - //qDebug() << "GeometryCache::renderQuad(vec2,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad2D[id] : _quad2D[key]; @@ -1092,7 +1081,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC const glm::vec2& texCoordMinCorner, const glm::vec2& texCoordMaxCorner, const glm::vec4& color, int id) { - //qDebug() << "GeometryCache::renderQuad(vec2/texture,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec2PairPair key(Vec2Pair(minCorner, maxCorner), Vec2Pair(texCoordMinCorner, texCoordMaxCorner)); BatchItemDetails& details = registered ? _registeredQuad2DTextures[id] : _quad2DTextures[key]; @@ -1183,7 +1171,6 @@ void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxC } void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxCorner, const glm::vec4& color, int id) { - //qDebug() << "GeometryCache::renderQuad(vec3,id=" << id <<")..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(minCorner, maxCorner); BatchItemDetails& details = registered ? _registeredQuad3D[id] : _quad3D[key]; @@ -1471,7 +1458,9 @@ GeometryCache::BatchItemDetails::BatchItemDetails() : isCreated(false) { population++; - qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; + #ifdef WANT_DEBUG + qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; + #endif } GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItemDetails& other) : @@ -1484,13 +1473,17 @@ GeometryCache::BatchItemDetails::BatchItemDetails(const GeometryCache::BatchItem isCreated(other.isCreated) { population++; - qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; + #ifdef WANT_DEBUG + qDebug() << "BatchItemDetails()... population:" << population << "**********************************"; + #endif } GeometryCache::BatchItemDetails::~BatchItemDetails() { population--; clear(); - qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; + #ifdef WANT_DEBUG + qDebug() << "~BatchItemDetails()... population:" << population << "**********************************"; + #endif } void GeometryCache::BatchItemDetails::clear() { @@ -1504,7 +1497,6 @@ void GeometryCache::BatchItemDetails::clear() { void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { - //qDebug() << "GeometryCache::renderLine(vec3)..."; bool registered = (id != UNKNOWN_ID); Vec3Pair key(p1, p2); @@ -1597,7 +1589,6 @@ void GeometryCache::renderLine(const glm::vec3& p1, const glm::vec3& p2, void GeometryCache::renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec4& color1, const glm::vec4& color2, int id) { - //qDebug() << "GeometryCache::renderLine(vec2)..."; bool registered = (id != UNKNOWN_ID); Vec2Pair key(p1, p2); From 7d9de6d0eb3b72eae3c633b77a53e8ba80d52205 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 11:03:05 -0800 Subject: [PATCH 21/50] added some TODO comments and some cleanup --- interface/src/Application.cpp | 1 - interface/src/Util.cpp | 3 +++ interface/src/audio/AudioIOStatsRenderer.cpp | 3 ++- interface/src/audio/AudioScope.cpp | 2 -- interface/src/avatar/Avatar.cpp | 2 +- interface/src/ui/BandwidthMeter.cpp | 1 + interface/src/ui/overlays/Line3DOverlay.cpp | 3 ++- interface/src/ui/overlays/Text3DOverlay.cpp | 1 + interface/src/ui/overlays/TextOverlay.cpp | 1 + .../entities-renderer/src/RenderableLightEntityItem.cpp | 4 ++-- .../entities-renderer/src/RenderableTextEntityItem.cpp | 1 + libraries/render-utils/src/TextureCache.cpp | 6 ++++-- 12 files changed, 18 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 36d6ded886..33ddad3c2b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2799,7 +2799,6 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs if (!selfAvatarOnly) { // draw a red sphere float originSphereRadius = 0.05f; - glColor3f(1,0,0); DependencyManager::get()->renderSphere(originSphereRadius, 15, 15, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f)); // also, metavoxels diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index ea65475ddc..ab313d03a2 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -106,7 +106,10 @@ void drawText(int x, int y, float scale, float radians, int mono, // glPushMatrix(); glTranslatef(static_cast(x), static_cast(y), 0.0f); + + // TODO: add support for color to rendering text glColor3fv(color); + glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0); glScalef(scale / 0.1f, scale / 0.1f, 1.0f); textRenderer(mono)->draw(0, 0, string); diff --git a/interface/src/audio/AudioIOStatsRenderer.cpp b/interface/src/audio/AudioIOStatsRenderer.cpp index c253794924..2f0c01beaa 100644 --- a/interface/src/audio/AudioIOStatsRenderer.cpp +++ b/interface/src/audio/AudioIOStatsRenderer.cpp @@ -56,7 +56,8 @@ void AudioIOStatsRenderer::render(const float* color, int width, int height) { int w = STATS_WIDTH; int h = statsHeight; DependencyManager::get()->renderQuad(x, y, w, h, backgroundColor); - glColor4f(1, 1, 1, 1); + + glColor4f(1, 1, 1, 1); // TODO: change text rendering to use collor as parameter int horizontalOffset = x + 5; int verticalOffset = y; diff --git a/interface/src/audio/AudioScope.cpp b/interface/src/audio/AudioScope.cpp index b2e6d35dcf..6ad3a60cba 100644 --- a/interface/src/audio/AudioScope.cpp +++ b/interface/src/audio/AudioScope.cpp @@ -196,8 +196,6 @@ void AudioScope::renderLineStrip(int id, const glm::vec4& color, int x, int y, i geometryCache->updateVertices(id, points, color); geometryCache->renderVertices(gpu::LINE_STRIP, id); - - glColor4f(1, 1, 1, 1); } int AudioScope::addBufferToScope(QByteArray* byteArray, int frameOffset, const int16_t* source, int sourceSamplesPerChannel, diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 9762f3fd4a..354ba174f8 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -703,7 +703,7 @@ void Avatar::renderDisplayName() { DependencyManager::get()->renderBevelCornersRect(left, bottom, right - left, top - bottom, 3, glm::vec4(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA)); - glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); + glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); // TODO: change text rendering to use collor as parameter QByteArray ba = _displayName.toLocal8Bit(); const char* text = ba.data(); diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index d6ec937d1d..d0f8b48568 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -88,6 +88,7 @@ void BandwidthMeter::Stream::updateValue(double amount) { void BandwidthMeter::setColorRGBA(unsigned c) { + // TODO: add support for color to rendering text, since that's why this method is used glColor4ub(GLubyte( c >> 24), GLubyte((c >> 16) & 0xff), GLubyte((c >> 8) & 0xff), diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index ab537eea89..f02006c5f8 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -49,7 +49,6 @@ void Line3DOverlay::render(RenderArgs* args) { float alpha = getAlpha(); xColor color = getColor(); const float MAX_COLOR = 255.0f; - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec4 colorv4(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); glm::vec3 position = getPosition(); @@ -60,6 +59,8 @@ void Line3DOverlay::render(RenderArgs* args) { glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); if (getIsDashedLine()) { + // TODO: add support for color to renderDashedLine() + glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); DependencyManager::get()->renderDashedLine(_position, _end, _geometryCacheID); } else { DependencyManager::get()->renderLine(_start, _end, colorv4, _geometryCacheID); diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 623a487bb5..0d0741772c 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -124,6 +124,7 @@ void Text3DOverlay::render(RenderArgs* args) { enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipDimensions.y); enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); + // TODO: add support for color to rendering text glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR); float alpha = getAlpha(); QStringList lines = _text.split("\n"); diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 1333134907..d3893b5b04 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -90,6 +90,7 @@ void TextOverlay::render(RenderArgs* args) { int x = _bounds.left() + _leftMargin + leftAdjust; int y = _bounds.top() + _topMargin + topAdjust; + // TODO: add support for color to rendering text glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR); float alpha = getAlpha(); QStringList lines = _text.split("\n"); diff --git a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp index 9097956c88..7eccaff06b 100644 --- a/libraries/entities-renderer/src/RenderableLightEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableLightEntityItem.cpp @@ -63,7 +63,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) { } #ifdef WANT_DEBUG - glColor4f(diffuseR, diffuseG, diffuseB, 1.0f); + glm::vec4 color(diffuseR, diffuseG, diffuseB, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); glm::vec3 axis = glm::axis(rotation); @@ -73,7 +73,7 @@ void RenderableLightEntityItem::render(RenderArgs* args) { glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); - DependencyManager::get()->renderWireSphere(0.5f, 15, 15); + DependencyManager::get()->renderWireSphere(0.5f, 15, 15, color); glPopMatrix(); glPopMatrix(); #endif diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 492543fd62..d142f76dfe 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -78,6 +78,7 @@ void RenderableTextEntityItem::render(RenderArgs* args) { enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); xColor textColor = getTextColorX(); + // TODO: add support for color to rendering text glColor3f(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR); QStringList lines = _text.split("\n"); int lineOffset = maxHeight; diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 3644ded81c..28bda7689a 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -154,14 +154,16 @@ const gpu::TexturePointer& TextureCache::getPermutationNormalTexture() { } const unsigned char OPAQUE_WHITE[] = { 0xFF, 0xFF, 0xFF, 0xFF }; -const unsigned char TRANSPARENT_WHITE[] = { 0xFF, 0xFF, 0xFF, 0x0 }; -const unsigned char OPAQUE_BLACK[] = { 0x0, 0x0, 0x0, 0xFF }; +//const unsigned char TRANSPARENT_WHITE[] = { 0xFF, 0xFF, 0xFF, 0x0 }; +//const unsigned char OPAQUE_BLACK[] = { 0x0, 0x0, 0x0, 0xFF }; const unsigned char OPAQUE_BLUE[] = { 0x80, 0x80, 0xFF, 0xFF }; +/* static void loadSingleColorTexture(const unsigned char* color) { glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, color); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } +*/ const gpu::TexturePointer& TextureCache::getWhiteTexture() { if (_whiteTexture.isNull()) { From 2f4e98082b00551222b6ebaa3f3afe4a18889e52 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 13:54:48 -0800 Subject: [PATCH 22/50] remove glColor calls related to text rendering --- interface/src/Util.cpp | 6 ++--- interface/src/audio/AudioIOStatsRenderer.cpp | 2 -- interface/src/avatar/Avatar.cpp | 4 ++-- interface/src/ui/BandwidthMeter.cpp | 22 +++++-------------- interface/src/ui/BandwidthMeter.h | 1 - interface/src/ui/overlays/Text3DOverlay.cpp | 6 ++--- interface/src/ui/overlays/TextOverlay.cpp | 5 ++--- .../src/RenderableTextEntityItem.cpp | 6 ++--- libraries/render-utils/src/TextRenderer.cpp | 15 +++++-------- libraries/render-utils/src/TextRenderer.h | 3 ++- 10 files changed, 24 insertions(+), 46 deletions(-) diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index ab313d03a2..e2ec29ecdc 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -107,12 +107,12 @@ void drawText(int x, int y, float scale, float radians, int mono, glPushMatrix(); glTranslatef(static_cast(x), static_cast(y), 0.0f); - // TODO: add support for color to rendering text - glColor3fv(color); glRotated(double(radians * DEGREES_PER_RADIAN), 0.0, 0.0, 1.0); glScalef(scale / 0.1f, scale / 0.1f, 1.0f); - textRenderer(mono)->draw(0, 0, string); + + glm::vec4 colorV4 = {color[0], color[1], color[3], 1.0f }; + textRenderer(mono)->draw(0, 0, string, colorV4); glPopMatrix(); } diff --git a/interface/src/audio/AudioIOStatsRenderer.cpp b/interface/src/audio/AudioIOStatsRenderer.cpp index 2f0c01beaa..782010bd00 100644 --- a/interface/src/audio/AudioIOStatsRenderer.cpp +++ b/interface/src/audio/AudioIOStatsRenderer.cpp @@ -57,8 +57,6 @@ void AudioIOStatsRenderer::render(const float* color, int width, int height) { int h = statsHeight; DependencyManager::get()->renderQuad(x, y, w, h, backgroundColor); - glColor4f(1, 1, 1, 1); // TODO: change text rendering to use collor as parameter - int horizontalOffset = x + 5; int verticalOffset = y; diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 354ba174f8..727f5f5d7c 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -703,12 +703,12 @@ void Avatar::renderDisplayName() { DependencyManager::get()->renderBevelCornersRect(left, bottom, right - left, top - bottom, 3, glm::vec4(0.2f, 0.2f, 0.2f, _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA)); - glColor4f(0.93f, 0.93f, 0.93f, _displayNameAlpha); // TODO: change text rendering to use collor as parameter + glm::vec4 color(0.93f, 0.93f, 0.93f, _displayNameAlpha); QByteArray ba = _displayName.toLocal8Bit(); const char* text = ba.data(); glDisable(GL_POLYGON_OFFSET_FILL); - textRenderer(DISPLAYNAME)->draw(text_x, text_y, text); + textRenderer(DISPLAYNAME)->draw(text_x, text_y, text, color); glPopMatrix(); diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index d0f8b48568..1b73ec9fcd 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -86,15 +86,6 @@ void BandwidthMeter::Stream::updateValue(double amount) { glm::clamp(dt / _msToAverage, 0.0, 1.0)); } -void BandwidthMeter::setColorRGBA(unsigned c) { - - // TODO: add support for color to rendering text, since that's why this method is used - glColor4ub(GLubyte( c >> 24), - GLubyte((c >> 16) & 0xff), - GLubyte((c >> 8) & 0xff), - GLubyte( c & 0xff)); -} - glm::vec4 BandwidthMeter::getColorRGBA(unsigned c) { float r = (c >> 24) / 255.0f; @@ -165,10 +156,10 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { glTranslatef((float)barX, (float)y, 0.0f); // Render captions - setColorRGBA(COLOR_TEXT); - _textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT); - _textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN); - _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT); + glm::vec4 textColor = getColorRGBA(COLOR_TEXT); + _textRenderer->draw(barWidth + SPACING_LEFT_CAPTION_UNIT, textYcenteredLine, CAPTION_UNIT, textColor); + _textRenderer->draw(-labelWidthIn - SPACING_RIGHT_CAPTION_IN_OUT, textYupperLine, CAPTION_IN, textColor); + _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT, textColor); // Render vertical lines for the frame renderVerticalLine(0, 0, h, COLOR_FRAME); @@ -226,15 +217,14 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { // Render numbers char fmtBuf[8]; - setColorRGBA(COLOR_TEXT); sprintf(fmtBuf, "%0.1f", totalIn); _textRenderer->draw(glm::max(xIn - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, PADDING_HORIZ_VALUE), - textYupperLine, fmtBuf); + textYupperLine, fmtBuf, textColor); sprintf(fmtBuf, "%0.1f", totalOut); _textRenderer->draw(glm::max(xOut - fontMetrics.width(fmtBuf) - PADDING_HORIZ_VALUE, PADDING_HORIZ_VALUE), - textYlowerLine, fmtBuf); + textYlowerLine, fmtBuf, textColor); glPopMatrix(); diff --git a/interface/src/ui/BandwidthMeter.h b/interface/src/ui/BandwidthMeter.h index 4f69a9fb97..bca4745cee 100644 --- a/interface/src/ui/BandwidthMeter.h +++ b/interface/src/ui/BandwidthMeter.h @@ -69,7 +69,6 @@ public: ChannelInfo const& channelInfo(ChannelIndex i) const { return _channels[i]; } private: - static void setColorRGBA(unsigned c); static glm::vec4 getColorRGBA(unsigned c); static void renderBox(int x, int y, int w, int h, unsigned c); static void renderVerticalLine(int x, int y, int h, unsigned c); diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 0d0741772c..00fd655f69 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -124,13 +124,11 @@ void Text3DOverlay::render(RenderArgs* args) { enableClipPlane(GL_CLIP_PLANE2, 0.0f, -1.0f, 0.0f, clipMinimum.y + clipDimensions.y); enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); - // TODO: add support for color to rendering text - glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR); - float alpha = getAlpha(); + glm::vec4 textColor = {_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, getAlpha() }; QStringList lines = _text.split("\n"); int lineOffset = maxHeight; foreach(QString thisLine, lines) { - textRenderer->draw(0, lineOffset, qPrintable(thisLine), alpha); + textRenderer->draw(0, lineOffset, qPrintable(thisLine), textColor); lineOffset += maxHeight; } diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index d3893b5b04..0e8ca29320 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -90,16 +90,15 @@ void TextOverlay::render(RenderArgs* args) { int x = _bounds.left() + _leftMargin + leftAdjust; int y = _bounds.top() + _topMargin + topAdjust; - // TODO: add support for color to rendering text - glColor3f(_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR); float alpha = getAlpha(); + glm::vec4 textColor = {_color.red / MAX_COLOR, _color.green / MAX_COLOR, _color.blue / MAX_COLOR, alpha }; QStringList lines = _text.split("\n"); int lineOffset = 0; foreach(QString thisLine, lines) { if (lineOffset == 0) { lineOffset = textRenderer->calculateHeight(qPrintable(thisLine)); } - lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine), alpha); + lineOffset += textRenderer->draw(x, y + lineOffset, qPrintable(thisLine), textColor); const int lineGap = 2; lineOffset += lineGap; diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index d142f76dfe..54b6691eed 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -78,13 +78,11 @@ void RenderableTextEntityItem::render(RenderArgs* args) { enableClipPlane(GL_CLIP_PLANE3, 0.0f, 1.0f, 0.0f, -clipMinimum.y); xColor textColor = getTextColorX(); - // TODO: add support for color to rendering text - glColor3f(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR); + glm::vec4 textColorV4(textColor.red / MAX_COLOR, textColor.green / MAX_COLOR, textColor.blue / MAX_COLOR, 1.0f); QStringList lines = _text.split("\n"); int lineOffset = maxHeight; - float textAlpha = 1.0f; // getTextAlpha() foreach(QString thisLine, lines) { - textRenderer->draw(0, lineOffset, qPrintable(thisLine), textAlpha); + textRenderer->draw(0, lineOffset, qPrintable(thisLine), textColorV4); lineOffset += maxHeight; } diff --git a/libraries/render-utils/src/TextRenderer.cpp b/libraries/render-utils/src/TextRenderer.cpp index ae7523a817..bf718b468e 100644 --- a/libraries/render-utils/src/TextRenderer.cpp +++ b/libraries/render-utils/src/TextRenderer.cpp @@ -70,16 +70,11 @@ int TextRenderer::calculateHeight(const char* str) { return maxHeight; } -int TextRenderer::draw(int x, int y, const char* str, float alpha) { - // Grab the current color - float currentColor[4]; - glGetFloatv(GL_CURRENT_COLOR, currentColor); - alpha = std::max(0.0f, std::min(alpha, 1.0f)); - currentColor[3] *= alpha; - int compactColor = ((int(currentColor[0] * 255.0f) & 0xFF)) | - ((int(currentColor[1] * 255.0f) & 0xFF) << 8) | - ((int(currentColor[2] * 255.0f) & 0xFF) << 16) | - ((int(currentColor[3] * 255.0f) & 0xFF) << 24); +int TextRenderer::draw(int x, int y, const char* str, const glm::vec4& color) { + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); int maxHeight = 0; for (const char* ch = str; *ch != 0; ch++) { diff --git a/libraries/render-utils/src/TextRenderer.h b/libraries/render-utils/src/TextRenderer.h index 078efb0463..671258e335 100644 --- a/libraries/render-utils/src/TextRenderer.h +++ b/libraries/render-utils/src/TextRenderer.h @@ -13,6 +13,7 @@ #define hifi_TextRenderer_h #include +#include #include #include @@ -70,7 +71,7 @@ public: int calculateHeight(const char* str); // also returns the height of the tallest character - int draw(int x, int y, const char* str, float alpha = 1.0f); + int draw(int x, int y, const char* str, const glm::vec4& color); int computeWidth(char ch); int computeWidth(const char* str); From 7bd45ba0cab313585b7e95223e20d35afceb0c21 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 14:52:33 -0800 Subject: [PATCH 23/50] change removing more glColor calls --- libraries/render-utils/src/GeometryCache.cpp | 3 ++- libraries/render-utils/src/GeometryCache.h | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index ab8b30f427..27019a2dd3 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1253,7 +1253,8 @@ void GeometryCache::renderQuad(const glm::vec3& minCorner, const glm::vec3& maxC void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomLeft, const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, - const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, int id) { + const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, + const glm::vec4& quadColor, int id) { #ifdef WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index b95e92dcd9..038dcb352d 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -102,6 +102,9 @@ public: void renderQuad(int x, int y, int width, int height, const glm::vec4& color, int id = UNKNOWN_ID) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height), color, id); } + // TODO: I think there's a bug in this version of the renderQuad() that's not correctly rebuilding the vbos + // if the color changes by the corners are the same, as evidenced by the audio meter which should turn white + // when it's clipping void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id = UNKNOWN_ID); void renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, @@ -114,7 +117,7 @@ public: const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - int id = UNKNOWN_ID); + const glm::vec4& quadColor, int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) From f9bcb65467e02173b11a837e36330d4b457fc997 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 14:52:40 -0800 Subject: [PATCH 24/50] change removing more glColor calls --- interface/src/ui/ApplicationOverlay.cpp | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 508c01e06f..1ad7676578 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -118,10 +118,16 @@ void ApplicationOverlay::renderReticle(glm::quat orientation, float alpha) { glm::vec3 topRight = getPoint(-reticleSize / 2.0f, -reticleSize / 2.0f); glm::vec3 bottomLeft = getPoint(reticleSize / 2.0f, reticleSize / 2.0f); glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f); - glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha); + + // TODO: this version of renderQuad() needs to take a color + glm::vec4 reticleColor = { RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha }; + + + DependencyManager::get()->renderQuad(topLeft, bottomLeft, bottomRight, topRight, glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), - glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), _reticleQuad); + glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), + reticleColor, _reticleQuad); } glPopMatrix(); } @@ -374,7 +380,7 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glTranslatef(pos.x, pos.y, pos.z); glRotatef(glm::degrees(glm::angle(rot)), axis.x, axis.y, axis.z); - glColor4f(1.0f, 1.0f, 1.0f, _alpha); + glm::vec4 overlayColor = {1.0f, 1.0f, 1.0f, _alpha}; //Render const GLfloat distance = 1.0f; @@ -393,7 +399,8 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glm::vec3(x + quadWidth, y, -distance), glm::vec3(x, y, -distance), glm::vec2(0.0f, 1.0f), glm::vec2(1.0f, 1.0f), - glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 0.0f)); + glm::vec2(1.0f, 0.0f), glm::vec2(0.0f, 0.0f), + overlayColor); auto glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { @@ -409,7 +416,7 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as const float mouseX = (application->getMouseX() / (float)glCanvas->width()) * quadWidth; const float mouseY = (1.0 - (application->getMouseY() / (float)glCanvas->height())) * quadHeight; - glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); + glm::vec4 reticleColor = { RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], 1.0f }; DependencyManager::get()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance), glm::vec3(x + mouseX + reticleSize, y + mouseY, -distance), @@ -417,7 +424,7 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glm::vec3(x + mouseX, y + mouseY - reticleSize, -distance), glm::vec2(0.0f, 0.0f), glm::vec2(1.0f, 0.0f), glm::vec2(1.0f, 1.0f), glm::vec2(0.0f, 1.0f), - _reticleQuad); + reticleColor, _reticleQuad); glEnable(GL_DEPTH_TEST); @@ -771,14 +778,14 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool geometryCache->renderVertices(gpu::LINE_STRIP, _magnifierBorder); glEnable(GL_TEXTURE_2D); } - glColor4f(1.0f, 1.0f, 1.0f, _alpha); + glm::vec4 magnifierColor = { 1.0f, 1.0f, 1.0f, _alpha }; DependencyManager::get()->renderQuad(bottomLeft, bottomRight, topRight, topLeft, glm::vec2(magnifyULeft, magnifyVBottom), glm::vec2(magnifyURight, magnifyVBottom), glm::vec2(magnifyURight, magnifyVTop), glm::vec2(magnifyULeft, magnifyVTop), - _magnifierQuad); + magnifierColor, _magnifierQuad); } glPopMatrix(); } @@ -844,16 +851,11 @@ void ApplicationOverlay::renderAudioMeter() { DependencyManager::get()->render(glCanvas->width(), glCanvas->height()); DependencyManager::get()->render(WHITE_TEXT, glCanvas->width(), glCanvas->height()); - if (isClipping) { - glColor3f(1, 0, 0); - } else { - glColor3f(0.475f, 0.475f, 0.475f); - } - audioMeterY += AUDIO_METER_HEIGHT; // Draw audio meter background Quad - DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT, glm::vec4(0, 0, 0, 1)); + DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT, + glm::vec4(0, 0, 0, 1)); if (audioLevel > AUDIO_RED_START) { glm::vec4 quadColor; From efb044ea5e1dc7b91e3a4cec32583ec03755683c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 15:08:59 -0800 Subject: [PATCH 25/50] change renderDashedLine() to take a color paramter --- interface/src/ui/ApplicationOverlay.cpp | 4 ---- interface/src/ui/BandwidthMeter.cpp | 2 ++ interface/src/ui/overlays/Cube3DOverlay.cpp | 24 +++++++++---------- interface/src/ui/overlays/Line3DOverlay.cpp | 3 +-- .../src/ui/overlays/Rectangle3DOverlay.cpp | 8 +++---- libraries/render-utils/src/GeometryCache.cpp | 9 ++++++- libraries/render-utils/src/GeometryCache.h | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 1ad7676578..2e6e1a1df4 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -320,8 +320,6 @@ void ApplicationOverlay::displayOverlayTextureOculus(Camera& whichCamera) { glDepthMask(GL_FALSE); glDisable(GL_ALPHA_TEST); - glColor4f(1.0f, 1.0f, 1.0f, _alpha); - static float textureFOV = 0.0f, textureAspectRatio = 1.0f; if (textureFOV != _textureFov || textureAspectRatio != _textureAspectRatio) { @@ -436,8 +434,6 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE); glEnable(GL_LIGHTING); - - glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } void ApplicationOverlay::computeOculusPickRay(float x, float y, glm::vec3& origin, glm::vec3& direction) const { diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index 1b73ec9fcd..f1bcb2f0c9 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -162,6 +162,8 @@ void BandwidthMeter::render(int screenWidth, int screenHeight) { _textRenderer->draw(-labelWidthOut - SPACING_RIGHT_CAPTION_IN_OUT, textYlowerLine, CAPTION_OUT, textColor); // Render vertical lines for the frame + // TODO: I think there may be a bug in this newest code and/or the GeometryCache code, because it seems like + // sometimes the bandwidth meter doesn't render the vertical lines renderVerticalLine(0, 0, h, COLOR_FRAME); renderVerticalLine(barWidth, 0, h, COLOR_FRAME); diff --git a/interface/src/ui/overlays/Cube3DOverlay.cpp b/interface/src/ui/overlays/Cube3DOverlay.cpp index a2a1755acd..53d7d4e70b 100644 --- a/interface/src/ui/overlays/Cube3DOverlay.cpp +++ b/interface/src/ui/overlays/Cube3DOverlay.cpp @@ -111,20 +111,20 @@ void Cube3DOverlay::render(RenderArgs* args) { auto geometryCache = DependencyManager::get(); - geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear); - geometryCache->renderDashedLine(bottomRightNear, bottomRightFar); - geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar); - geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear); + geometryCache->renderDashedLine(bottomLeftNear, bottomRightNear, cubeColor); + geometryCache->renderDashedLine(bottomRightNear, bottomRightFar, cubeColor); + geometryCache->renderDashedLine(bottomRightFar, bottomLeftFar, cubeColor); + geometryCache->renderDashedLine(bottomLeftFar, bottomLeftNear, cubeColor); - geometryCache->renderDashedLine(topLeftNear, topRightNear); - geometryCache->renderDashedLine(topRightNear, topRightFar); - geometryCache->renderDashedLine(topRightFar, topLeftFar); - geometryCache->renderDashedLine(topLeftFar, topLeftNear); + geometryCache->renderDashedLine(topLeftNear, topRightNear, cubeColor); + geometryCache->renderDashedLine(topRightNear, topRightFar, cubeColor); + geometryCache->renderDashedLine(topRightFar, topLeftFar, cubeColor); + geometryCache->renderDashedLine(topLeftFar, topLeftNear, cubeColor); - geometryCache->renderDashedLine(bottomLeftNear, topLeftNear); - geometryCache->renderDashedLine(bottomRightNear, topRightNear); - geometryCache->renderDashedLine(bottomLeftFar, topLeftFar); - geometryCache->renderDashedLine(bottomRightFar, topRightFar); + geometryCache->renderDashedLine(bottomLeftNear, topLeftNear, cubeColor); + geometryCache->renderDashedLine(bottomRightNear, topRightNear, cubeColor); + geometryCache->renderDashedLine(bottomLeftFar, topLeftFar, cubeColor); + geometryCache->renderDashedLine(bottomRightFar, topRightFar, cubeColor); } else { glScalef(dimensions.x, dimensions.y, dimensions.z); diff --git a/interface/src/ui/overlays/Line3DOverlay.cpp b/interface/src/ui/overlays/Line3DOverlay.cpp index f02006c5f8..d2bfa1955b 100644 --- a/interface/src/ui/overlays/Line3DOverlay.cpp +++ b/interface/src/ui/overlays/Line3DOverlay.cpp @@ -60,8 +60,7 @@ void Line3DOverlay::render(RenderArgs* args) { if (getIsDashedLine()) { // TODO: add support for color to renderDashedLine() - glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - DependencyManager::get()->renderDashedLine(_position, _end, _geometryCacheID); + DependencyManager::get()->renderDashedLine(_position, _end, colorv4, _geometryCacheID); } else { DependencyManager::get()->renderLine(_start, _end, colorv4, _geometryCacheID); } diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 0c81e932a3..82a5383036 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -81,10 +81,10 @@ void Rectangle3DOverlay::render(RenderArgs* args) { glm::vec3 point3(halfDimensions.x, 0.0f, halfDimensions.y); glm::vec3 point4(-halfDimensions.x, 0.0f, halfDimensions.y); - geometryCache->renderDashedLine(point1, point2); - geometryCache->renderDashedLine(point2, point3); - geometryCache->renderDashedLine(point3, point4); - geometryCache->renderDashedLine(point4, point1); + geometryCache->renderDashedLine(point1, point2, rectangleColor); + geometryCache->renderDashedLine(point2, point3, rectangleColor); + geometryCache->renderDashedLine(point3, point4, rectangleColor); + geometryCache->renderDashedLine(point4, point1, rectangleColor); } else { diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 27019a2dd3..745b248bdd 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1366,7 +1366,8 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id) { +// TODO: switch this over to use BatchItemDetails like the other line and vertices functions +void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3Pair key(start, end); BufferDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key]; @@ -1383,6 +1384,12 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en } if (!details.buffer.isCreated()) { + + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + // draw each line segment with appropriate gaps const float DASH_LENGTH = 0.05f; diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 038dcb352d..9316048981 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -134,7 +134,7 @@ public: void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec4& color1, const glm::vec4& color2, int id = UNKNOWN_ID); - void renderDashedLine(const glm::vec3& start, const glm::vec3& end, int id = UNKNOWN_ID); + void renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id = UNKNOWN_ID); void renderLine(const glm::vec2& p1, const glm::vec2& p2, const glm::vec3& color, int id = UNKNOWN_ID) { renderLine(p1, p2, glm::vec4(color, 1.0f), id); } From 3447fea1dbcd0df43e4b9fabd66e894d84279b46 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 28 Jan 2015 16:01:04 -0800 Subject: [PATCH 26/50] Revert "Update grid tool to be an overlay" This reverts commit 552a421f24ed8b856e8868ce3e2368c8135b552a. Conflicts: examples/libraries/gridTool.js --- examples/libraries/gridTool.js | 277 ++++----------------------------- 1 file changed, 27 insertions(+), 250 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 87b7f907e2..7eff1da5d0 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -224,273 +224,50 @@ Grid = function(opts) { GridTool = function(opts) { var that = {}; - var UI_URL = HIFI_PUBLIC_BUCKET + "images/tools/grid-toolbar.svg"; - var UI_WIDTH = 854; - var UI_HEIGHT = 37; - var horizontalGrid = opts.horizontalGrid; + var verticalGrid = opts.verticalGrid; + var listeners = []; - var uiOverlays = {}; - var allOverlays = []; + var url = Script.resolvePath('html/gridControls.html'); + var webView = new WebWindow('Grid', url, 200, 280); - function addUIOverlay(key, overlay, x, y, width, height) { - uiOverlays[key] = { - overlay: overlay, - x: x, - y: y, - width: width, - height: height, - }; - allOverlays.push(overlay); - } + horizontalGrid.addListener(function(data) { + webView.eventBridge.emitScriptEvent(JSON.stringify(data)); + selectionDisplay.updateHandles(); + }); - var lastKnownWindowWidth = null; - function repositionUI() { - if (lastKnownWindowWidth == Window.innerWidth) { - return; - } - - lastKnownWindowWidth = Window.innerWidth; - var x = Window.innerWidth / 2 - UI_WIDTH / 2; - var y = 10; - - for (var key in uiOverlays) { - info = uiOverlays[key]; - Overlays.editOverlay(info.overlay, { - x: x + info.x, - y: y + info.y, - }); - } - } - - // "Spritesheet" is laid out horizontally in this order - var UI_SPRITE_LIST = [ - { name: "gridText", width: 54 }, - { name: "visibleCheckbox", width: 60 }, - { name: "snapToGridCheckbox", width: 105 }, - - { name: "color0", width: 27 }, - { name: "color1", width: 27 }, - { name: "color2", width: 27 }, - { name: "color3", width: 27 }, - { name: "color4", width: 27 }, - - { name: "minorGridIcon", width: 34 }, - { name: "minorGridDecrease", width: 25 }, - { name: "minorGridInput", width: 26 }, - { name: "minorGridIncrease", width: 25 }, - - { name: "majorGridIcon", width: 40 }, - { name: "majorGridDecrease", width: 25 }, - { name: "majorGridInput", width: 26 }, - { name: "majorGridIncrease", width: 25 }, - - { name: "yPositionLabel", width: 160 }, - { name: "moveToLabel", width: 54 }, - { name: "moveToAvatar", width: 26 }, - { name: "moveToSelection", width: 34 }, - ]; - - // Add all overlays from spritesheet - var baseOverlay = null; - var x = 0; - for (var i = 0; i < UI_SPRITE_LIST.length; i++) { - var info = UI_SPRITE_LIST[i]; - - var props = { - imageURL: UI_URL, - subImage: { x: x, y: 0, width: info.width, height: UI_HEIGHT }, - width: info.width, - height: UI_HEIGHT, - alpha: 1.0, - visible: false, - }; - - var overlay; - if (baseOverlay == null) { - overlay = Overlays.addOverlay("image", { - imageURL: UI_URL, - }); - baseOverlay = overlay; - } else { - overlay = Overlays.cloneOverlay(baseOverlay); - } - - Overlays.editOverlay(overlay, props); - - addUIOverlay(info.name, overlay, x, 0, info.width, UI_HEIGHT); - - x += info.width; - } - - // Add Text overlays - var textProperties = { - color: { red: 255, green: 255, blue: 255 }, - topMargin: 6, - leftMargin: 4, - alpha: 1, - backgroundAlpha: 0, - text: "", - font: { size: 12 }, - visible: false, - }; - var minorGridWidthText = Overlays.addOverlay("text", textProperties); - var majorGridEveryText = Overlays.addOverlay("text", textProperties); - var yPositionText = Overlays.addOverlay("text", textProperties); - - addUIOverlay('minorGridWidthText', minorGridWidthText, 414, 8, 24, 24); - addUIOverlay('majorGridEveryText', majorGridEveryText, 530, 8, 24, 24); - addUIOverlay('yPositionText', yPositionText, 660, 8, 24, 24); - - var NUM_COLORS = 5; - function updateColorIndex(index) { - if (index < 0 || index >= NUM_COLORS) { - return; - } - - for (var i = 0 ; i < NUM_COLORS; i++) { - var info = uiOverlays['color' + i]; - Overlays.editOverlay(info.overlay, { - subImage: { - x: info.x, - y: i == index ? UI_HEIGHT : 0, - width: info.width, - height: info.height, - } - }); - } - } - - function updateGridVisible(value) { - var info = uiOverlays.visibleCheckbox; - Overlays.editOverlay(info.overlay, { - subImage: { - x: info.x, - y: value ? UI_HEIGHT : 0, - width: info.width, - height: info.height, + webView.eventBridge.webEventReceived.connect(function(data) { + data = JSON.parse(data); + if (data.type == "init") { + horizontalGrid.emitUpdate(); + } else if (data.type == "update") { + horizontalGrid.update(data); + for (var i = 0; i < listeners.length; i++) { + listeners[i](data); } - }); - } - - function updateSnapToGrid(value) { - var info = uiOverlays.snapToGridCheckbox; - Overlays.editOverlay(info.overlay, { - subImage: { - x: info.x, - y: value ? UI_HEIGHT : 0, - width: info.width, - height: info.height, - } - }); - } - - function updateMinorGridWidth(value) { - Overlays.editOverlay(minorGridWidthText, { - text: value.toFixed(1), - }); - } - - function updateMajorGridEvery(value) { - Overlays.editOverlay(majorGridEveryText, { - text: value, - }); - } - - function updateYPosition(value) { - Overlays.editOverlay(yPositionText, { - text: value.toFixed(2), - }); - } - - function updateOverlays() { - updateGridVisible(horizontalGrid.getVisible()); - updateSnapToGrid(horizontalGrid.getSnapToGrid()); - updateColorIndex(horizontalGrid.getColorIndex()); - - updateMinorGridWidth(horizontalGrid.getMinorGridWidth()); - updateMajorGridEvery(horizontalGrid.getMajorGridEvery()); - - updateYPosition(horizontalGrid.getOrigin().y); - } - - that.setVisible = function(visible) { - for (var i = 0; i < allOverlays.length; i++) { - Overlays.editOverlay(allOverlays[i], { visible: visible }); - } - } - - that.mousePressEvent = function(event) { - var overlay = Overlays.getOverlayAtPoint({ x: event.x, y: event.y }); - - if (allOverlays.indexOf(overlay) >= 0) { - if (overlay == uiOverlays.color0.overlay) { - horizontalGrid.setColorIndex(0); - } else if (overlay == uiOverlays.color1.overlay) { - horizontalGrid.setColorIndex(1); - } else if (overlay == uiOverlays.color2.overlay) { - horizontalGrid.setColorIndex(2); - } else if (overlay == uiOverlays.color3.overlay) { - horizontalGrid.setColorIndex(3); - } else if (overlay == uiOverlays.color4.overlay) { - horizontalGrid.setColorIndex(4); - } else if (overlay == uiOverlays.visibleCheckbox.overlay) { - horizontalGrid.setVisible(!horizontalGrid.getVisible()); - } else if (overlay == uiOverlays.snapToGridCheckbox.overlay) { - horizontalGrid.setSnapToGrid(!horizontalGrid.getSnapToGrid()); - } else if (overlay == uiOverlays.moveToAvatar.overlay) { + } else if (data.type == "action") { + var action = data.action; + if (action == "moveToAvatar") { var position = MyAvatar.getJointPosition("LeftFoot"); if (position.x == 0 && position.y == 0 && position.z == 0) { position = MyAvatar.position; } horizontalGrid.setPosition(position); - } else if (overlay == uiOverlays.moveToSelection.overlay) { + } else if (action == "moveToSelection") { var newPosition = selectionManager.worldPosition; newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 }); - horizontalGrid.setPosition(newPosition); - } else if (overlay == uiOverlays.minorGridDecrease.overlay) { - var newValue = Math.max(0.1, horizontalGrid.getMinorGridWidth() - 0.1); - horizontalGrid.setMinorGridWidth(newValue); - } else if (overlay == uiOverlays.minorGridIncrease.overlay) { - horizontalGrid.setMinorGridWidth(horizontalGrid.getMinorGridWidth() + 0.1); - } else if (overlay == uiOverlays.majorGridDecrease.overlay) { - var newValue = Math.max(2, horizontalGrid.getMajorGridEvery() - 1); - horizontalGrid.setMajorGridEvery(newValue); - } else if (overlay == uiOverlays.majorGridIncrease.overlay) { - horizontalGrid.setMajorGridEvery(horizontalGrid.getMajorGridEvery() + 1); - } else if (overlay == uiOverlays.yPositionLabel.overlay) { - var newValue = Window.prompt("Y Position:", horizontalGrid.getOrigin().y.toFixed(4)); - if (newValue !== null) { - var y = parseFloat(newValue) - if (isNaN(y)) { - Window.alert("Invalid position"); - } else { - horizontalGrid.setPosition({ x: 0, y: y, z: 0 }); - } - } + grid.setPosition(newPosition); } - - // Clicking anywhere within the toolbar will "consume" this press event - return true; - } - - return false; - }; - - Script.scriptEnding.connect(function() { - for (var i = 0; i < allOverlays.length; i++) { - Overlays.deleteOverlay(allOverlays[i]); } }); - Script.update.connect(repositionUI); - horizontalGrid.addListener(function() { - selectionDisplay.updateHandles(); - updateOverlays(); - }); + that.addListener = function(callback) { + listeners.push(callback); + } - updateOverlays(); - repositionUI(); + that.setVisible = function(visible) { + webView.setVisible(visible); + } return that; }; From 018b38e56d23986624ba6c033023f288e6debed8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 18:51:10 -0800 Subject: [PATCH 27/50] fix warning --- interface/src/avatar/Hand.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interface/src/avatar/Hand.cpp b/interface/src/avatar/Hand.cpp index 7b885d85c3..55ba1701e0 100644 --- a/interface/src/avatar/Hand.cpp +++ b/interface/src/avatar/Hand.cpp @@ -131,7 +131,6 @@ void Hand::render(bool isMine, Model::RenderMode renderMode) { void Hand::renderHandTargets(bool isMine) { glPushMatrix(); - MyAvatar* myAvatar = Application::getInstance()->getAvatar(); const float avatarScale = Application::getInstance()->getAvatar()->getScale(); const float alpha = 1.0f; From 5d2df7b03f32095162b29f9da8c69d94c12a466c Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 28 Jan 2015 18:51:23 -0800 Subject: [PATCH 28/50] implement color for dashed lines --- libraries/render-utils/src/GeometryCache.cpp | 61 ++++++++++++++------ libraries/render-utils/src/GeometryCache.h | 15 ++--- 2 files changed, 48 insertions(+), 28 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 745b248bdd..eb4926c27f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1369,13 +1369,13 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom // TODO: switch this over to use BatchItemDetails like the other line and vertices functions void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); - Vec3Pair key(start, end); - BufferDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key]; + Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w))); + BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key]; // if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registered && details.buffer.isCreated()) { + if (registered && details.isCreated) { if (_lastRegisteredDashedLines[id] != key) { - details.buffer.destroy(); + details.clear(); _lastRegisteredDashedLines[id] = key; #ifdef WANT_DEBUG qDebug() << "renderDashedLine()... RELEASING REGISTERED"; @@ -1383,14 +1383,13 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en } } - if (!details.buffer.isCreated()) { + if (!details.isCreated) { int compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | ((int(color.z * 255.0f) & 0xFF) << 16) | ((int(color.w * 255.0f) & 0xFF) << 24); - - + // draw each line segment with appropriate gaps const float DASH_LENGTH = 0.05f; const float GAP_LENGTH = 0.025f; @@ -1406,6 +1405,26 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en const int FLOATS_PER_VERTEX = 3; details.vertices = (segmentCountFloor + 1) * 2; details.vertexSize = FLOATS_PER_VERTEX; + details.isCreated = true; + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + int* colorData = new int[details.vertices]; + int* colorDataAt = colorData; GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX]; GLfloat* vertex = vertexData; @@ -1414,27 +1433,30 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(colorDataAt++) = compactColor; for (int i = 0; i < segmentCountFloor; i++) { point += dashVector; *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(colorDataAt++) = compactColor; point += gapVector; *(vertex++) = point.x; *(vertex++) = point.y; *(vertex++) = point.z; + *(colorDataAt++) = compactColor; } *(vertex++) = end.x; *(vertex++) = end.y; *(vertex++) = end.z; + *(colorDataAt++) = compactColor; - details.buffer.create(); - details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw); - details.buffer.bind(); - details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat)); + details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData); + details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData); delete[] vertexData; + delete[] colorData; #ifdef WANT_DEBUG if (registered) { @@ -1443,15 +1465,20 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en qDebug() << "new dashed lines buffer made -- _dashedLines:" << _dashedLines.size(); } #endif - } else { - details.buffer.bind(); } - glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0); - glDrawArrays(GL_LINES, 0, details.vertices); + gpu::Batch batch; + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::LINES, details.vertices, 0); + + gpu::GLBackend::renderBatch(batch); + glDisableClientState(GL_VERTEX_ARRAY); - details.buffer.release(); + glDisableClientState(GL_COLOR_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 9316048981..6a018a6ab3 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -202,12 +202,7 @@ private: void clear(); }; - QHash _sphereVBOs; QHash _coneVBOs; - QHash _wireCubeVBOs; - QHash _solidCubeVBOs; - QHash _quad2DVBOs; - QHash _quad2DTextureVBOs; QHash _quad3DTextureVBOs; QHash _registeredQuadVBOs; int _nextID; @@ -241,11 +236,9 @@ private: QHash _registeredVertices; - QHash _lastRegisteredDashedLines; - QHash _dashedLines; - QHash _registeredDashedLines; - - QHash _colors; + QHash _lastRegisteredDashedLines; + QHash _dashedLines; + QHash _registeredDashedLines; QHash _gridBuffers; QHash _registeredAlternateGridBuffers; @@ -281,7 +274,7 @@ public: const FBXGeometry& getFBXGeometry() const { return _geometry; } const QVector& getMeshes() const { return _meshes; } - +// QVector getJointMappings(const AnimationPointer& animation); virtual void setLoadPriority(const QPointer& owner, float priority); From 4abb2481d6382c33cba8d0420f0706c21be33c58 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 10:10:53 -0800 Subject: [PATCH 29/50] removed old comment --- libraries/render-utils/src/GeometryCache.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index eb4926c27f..a493b815a8 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1366,7 +1366,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } -// TODO: switch this over to use BatchItemDetails like the other line and vertices functions void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { bool registered = (id != UNKNOWN_ID); Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w))); From 0f390a98b8add9b4c18f7b09d46ac0d998aec480 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 10:50:13 -0800 Subject: [PATCH 30/50] attempt to get color working for 3d textured quads --- interface/src/ui/ApplicationOverlay.cpp | 3 +- libraries/render-utils/src/GeometryCache.cpp | 153 +++++++++---------- libraries/render-utils/src/GeometryCache.h | 36 ++++- 3 files changed, 106 insertions(+), 86 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2e6e1a1df4..9f5f6e21e5 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -257,7 +257,8 @@ void ApplicationOverlay::displayOverlayTexture() { glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); } glPopMatrix(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a493b815a8..2ddb46d196 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1254,9 +1254,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& quadColor, int id) { + const glm::vec4& color, int id) { - #ifdef WANT_DEBUG + #if 1 // def WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; qDebug() << " topLeft:" << topLeft; qDebug() << " bottomLeft:" << bottomLeft; @@ -1264,106 +1264,99 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom qDebug() << " topRight:" << topRight; qDebug() << " texCoordTopLeft:" << texCoordTopLeft; qDebug() << " texCoordBottomRight:" << texCoordBottomRight; + qDebug() << " color:" << color; #endif //def WANT_DEBUG - bool registeredQuad = (id != UNKNOWN_ID); - Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DTextureVBOs[key]; - + bool registered = (id != UNKNOWN_ID); + Vec3PairVec4Pair key(Vec3Pair(topLeft, bottomRight), + Vec4Pair(glm::vec4(texCoordTopLeft.x,texCoordTopLeft.y,texCoordBottomRight.x,texCoordBottomRight.y), + color)); + + BatchItemDetails& details = registered ? _registeredQuad3DTextures[id] : _quad3DTextures[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredQuad && vbo.first != 0) { - Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[id]; + if (registered && details.isCreated) { + Vec3PairVec4Pair& lastKey = _lastRegisteredQuad3DTexture[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredQuad3DTexture[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; + qDebug() << "renderQuad() 3D+texture ... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; + qDebug() << "renderQuad() 3D+texture ... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } - - const int FLOATS_PER_VERTEX = 5; // text coords & vertices - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + + const int FLOATS_PER_VERTEX = 3 + 2; // 3d vertices + text coords const int vertices = 4; - const int indices = 4; - if (vbo.first == 0) { - _lastRegisteredQuad3DTexture[id] = key; - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - int v = 0; + const int NUM_POS_COORDS = 3; + const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); - vertex[v++] = topLeft.x; - vertex[v++] = topLeft.y; - vertex[v++] = topLeft.z; - vertex[v++] = texCoordTopLeft.x; - vertex[v++] = texCoordTopLeft.y; - - vertex[v++] = bottomLeft.x; - vertex[v++] = bottomLeft.y; - vertex[v++] = bottomLeft.z; - vertex[v++] = texCoordBottomLeft.x; - vertex[v++] = texCoordBottomLeft.y; - - vertex[v++] = bottomRight.x; - vertex[v++] = bottomRight.y; - vertex[v++] = bottomRight.z; - vertex[v++] = texCoordBottomRight.x; - vertex[v++] = texCoordBottomRight.y; - - vertex[v++] = topRight.x; - vertex[v++] = topRight.y; - vertex[v++] = topRight.z; - vertex[v++] = texCoordTopRight.x; - vertex[v++] = texCoordTopRight.y; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; + if (!details.isCreated) { - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); - } else { - qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); - } - #endif - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; // NOTE: this isn't used for BatchItemDetails maybe we can get rid of it + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + topLeft.x, topLeft.y, topLeft.z, texCoordTopLeft.x, texCoordTopLeft.y, + bottomLeft.x, bottomLeft.y, bottomLeft.z, texCoordBottomLeft.x, texCoordBottomLeft.y, + bottomRight.x, bottomRight.y, bottomRight.z, texCoordBottomRight.x, texCoordBottomRight.y, + topRight.x, topRight.y, topRight.z, texCoordTopRight.x, texCoordTopRight.y, + }; + + const int NUM_COLOR_SCALARS_PER_QUAD = 4; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); - glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float))); + gpu::Batch batch; - glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glEnable(GL_TEXTURE_2D); + //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 6a018a6ab3..300e68aadd 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -39,7 +39,10 @@ typedef glm::vec3 Vec3Key; typedef QPair Vec2Pair; typedef QPair Vec2PairPair; typedef QPair Vec3Pair; +typedef QPair Vec4Pair; typedef QPair Vec3PairVec2Pair; +typedef QPair Vec3PairVec4Pair; +typedef QPair Vec4PairVec4Pair; inline uint qHash(const glm::vec2& v, uint seed) { // multiply by prime numbers greater than the possible size @@ -70,6 +73,12 @@ inline uint qHash(const Vec3Pair& v, uint seed) { + 5021 * v.second.x + 5023 * v.second.y + 5039 * v.second.z, seed); } +inline uint qHash(const Vec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.x + 5009 * v.first.y + 5011 * v.first.z + 5021 * v.first.w + + 5023 * v.second.x + 5039 * v.second.y + 5051 * v.second.z + 5059 * v.second.w , seed); +} + inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { // multiply by prime numbers greater than the possible size return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + @@ -78,6 +87,24 @@ inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { 5077 * v.second.second.x + 5081 * v.second.second.y, seed); } +inline uint qHash(const Vec3PairVec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z + + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w + + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, + seed); +} + +inline uint qHash(const Vec4PairVec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + 5021 * v.first.first.w + + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z + 5059 * v.first.second.w + + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w + + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, + seed); +} + /// Stores cached geometry. class GeometryCache : public ResourceCache, public Dependency { Q_OBJECT @@ -117,7 +144,7 @@ public: const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& quadColor, int id = UNKNOWN_ID); + const glm::vec4& color, int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) @@ -203,12 +230,11 @@ private: }; QHash _coneVBOs; - QHash _quad3DTextureVBOs; - QHash _registeredQuadVBOs; int _nextID; - QHash _lastRegisteredQuad3DTexture; - + QHash _lastRegisteredQuad3DTexture; + QHash _quad3DTextures; + QHash _registeredQuad3DTextures; QHash _lastRegisteredQuad2DTexture; QHash _quad2DTextures; From 87e91a5a94db0bc392dab38e975cb921279e37f8 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 11:44:36 -0800 Subject: [PATCH 31/50] Revert "attempt to get color working for 3d textured quads" This reverts commit 0f390a98b8add9b4c18f7b09d46ac0d998aec480. --- interface/src/ui/ApplicationOverlay.cpp | 3 +- libraries/render-utils/src/GeometryCache.cpp | 153 ++++++++++--------- libraries/render-utils/src/GeometryCache.h | 36 +---- 3 files changed, 86 insertions(+), 106 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 9f5f6e21e5..2e6e1a1df4 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -257,8 +257,7 @@ void ApplicationOverlay::displayOverlayTexture() { glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, - glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); } glPopMatrix(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2ddb46d196..a493b815a8 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1254,9 +1254,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& color, int id) { + const glm::vec4& quadColor, int id) { - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; qDebug() << " topLeft:" << topLeft; qDebug() << " bottomLeft:" << bottomLeft; @@ -1264,99 +1264,106 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom qDebug() << " topRight:" << topRight; qDebug() << " texCoordTopLeft:" << texCoordTopLeft; qDebug() << " texCoordBottomRight:" << texCoordBottomRight; - qDebug() << " color:" << color; #endif //def WANT_DEBUG - bool registered = (id != UNKNOWN_ID); - Vec3PairVec4Pair key(Vec3Pair(topLeft, bottomRight), - Vec4Pair(glm::vec4(texCoordTopLeft.x,texCoordTopLeft.y,texCoordBottomRight.x,texCoordBottomRight.y), - color)); - - BatchItemDetails& details = registered ? _registeredQuad3DTextures[id] : _quad3DTextures[key]; - + bool registeredQuad = (id != UNKNOWN_ID); + Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DTextureVBOs[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registered && details.isCreated) { - Vec3PairVec4Pair& lastKey = _lastRegisteredQuad3DTexture[id]; + if (registeredQuad && vbo.first != 0) { + Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[id]; if (lastKey != key) { - details.clear(); - _lastRegisteredQuad3DTexture[id] = key; + glDeleteBuffers(1, &vbo.first); + glDeleteBuffers(1, &vbo.second); + vbo.first = vbo.second = 0; #ifdef WANT_DEBUG - qDebug() << "renderQuad() 3D+texture ... RELEASING REGISTERED"; + qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() 3D+texture ... REUSING PREVIOUSLY REGISTERED"; + qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; } #endif // def WANT_DEBUG } - - const int FLOATS_PER_VERTEX = 3 + 2; // 3d vertices + text coords - const int vertices = 4; - const int NUM_POS_COORDS = 3; - const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); - - if (!details.isCreated) { - - details.isCreated = true; - details.vertices = vertices; - details.vertexSize = FLOATS_PER_VERTEX; // NOTE: this isn't used for BatchItemDetails maybe we can get rid of it - - gpu::BufferPointer verticesBuffer(new gpu::Buffer()); - gpu::BufferPointer colorBuffer(new gpu::Buffer()); - gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); - gpu::BufferStreamPointer stream(new gpu::BufferStream()); - - details.verticesBuffer = verticesBuffer; - details.colorBuffer = colorBuffer; - details.streamFormat = streamFormat; - details.stream = stream; - details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); - details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); - details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + const int FLOATS_PER_VERTEX = 5; // text coords & vertices + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int vertices = 4; + const int indices = 4; + if (vbo.first == 0) { + _lastRegisteredQuad3DTexture[id] = key; + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices + GLfloat* vertex = vertexData; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; + int v = 0; - details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); - details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + vertex[v++] = topLeft.x; + vertex[v++] = topLeft.y; + vertex[v++] = topLeft.z; + vertex[v++] = texCoordTopLeft.x; + vertex[v++] = texCoordTopLeft.y; + + vertex[v++] = bottomLeft.x; + vertex[v++] = bottomLeft.y; + vertex[v++] = bottomLeft.z; + vertex[v++] = texCoordBottomLeft.x; + vertex[v++] = texCoordBottomLeft.y; + + vertex[v++] = bottomRight.x; + vertex[v++] = bottomRight.y; + vertex[v++] = bottomRight.z; + vertex[v++] = texCoordBottomRight.x; + vertex[v++] = texCoordBottomRight.y; + + vertex[v++] = topRight.x; + vertex[v++] = topRight.y; + vertex[v++] = topRight.z; + vertex[v++] = texCoordTopRight.x; + vertex[v++] = texCoordTopRight.y; + + glGenBuffers(1, &vbo.first); + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); + delete[] vertexData; + + GLushort* indexData = new GLushort[indices]; + GLushort* index = indexData; + for (int i = 0; i < indices; i++) { + index[i] = cannonicalIndices[i]; + } + + glGenBuffers(1, &vbo.second); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); + delete[] indexData; - - float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { - topLeft.x, topLeft.y, topLeft.z, texCoordTopLeft.x, texCoordTopLeft.y, - bottomLeft.x, bottomLeft.y, bottomLeft.z, texCoordBottomLeft.x, texCoordBottomLeft.y, - bottomRight.x, bottomRight.y, bottomRight.z, texCoordBottomRight.x, texCoordBottomRight.y, - topRight.x, topRight.y, topRight.z, texCoordTopRight.x, texCoordTopRight.y, - }; - - const int NUM_COLOR_SCALARS_PER_QUAD = 4; - int compactColor = ((int(color.x * 255.0f) & 0xFF)) | - ((int(color.y * 255.0f) & 0xFF) << 8) | - ((int(color.z * 255.0f) & 0xFF) << 16) | - ((int(color.w * 255.0f) & 0xFF) << 24); - int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; - - - details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); - details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); + #ifdef WANT_DEBUG + if (id == UNKNOWN_ID) { + qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + } else { + qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); + } + #endif + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); } - gpu::Batch batch; + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); + glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float))); - glEnable(GL_TEXTURE_2D); - //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... - - batch.setInputFormat(details.streamFormat); - batch.setInputStream(0, *details.stream); - batch.draw(gpu::QUADS, 4, 0); - - gpu::GLBackend::renderBatch(batch); + glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - + glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 300e68aadd..6a018a6ab3 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -39,10 +39,7 @@ typedef glm::vec3 Vec3Key; typedef QPair Vec2Pair; typedef QPair Vec2PairPair; typedef QPair Vec3Pair; -typedef QPair Vec4Pair; typedef QPair Vec3PairVec2Pair; -typedef QPair Vec3PairVec4Pair; -typedef QPair Vec4PairVec4Pair; inline uint qHash(const glm::vec2& v, uint seed) { // multiply by prime numbers greater than the possible size @@ -73,12 +70,6 @@ inline uint qHash(const Vec3Pair& v, uint seed) { + 5021 * v.second.x + 5023 * v.second.y + 5039 * v.second.z, seed); } -inline uint qHash(const Vec4Pair& v, uint seed) { - // multiply by prime numbers greater than the possible size - return qHash(v.first.x + 5009 * v.first.y + 5011 * v.first.z + 5021 * v.first.w - + 5023 * v.second.x + 5039 * v.second.y + 5051 * v.second.z + 5059 * v.second.w , seed); -} - inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { // multiply by prime numbers greater than the possible size return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + @@ -87,24 +78,6 @@ inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { 5077 * v.second.second.x + 5081 * v.second.second.y, seed); } -inline uint qHash(const Vec3PairVec4Pair& v, uint seed) { - // multiply by prime numbers greater than the possible size - return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z - + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z - + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w - + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, - seed); -} - -inline uint qHash(const Vec4PairVec4Pair& v, uint seed) { - // multiply by prime numbers greater than the possible size - return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + 5021 * v.first.first.w - + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z + 5059 * v.first.second.w - + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w - + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, - seed); -} - /// Stores cached geometry. class GeometryCache : public ResourceCache, public Dependency { Q_OBJECT @@ -144,7 +117,7 @@ public: const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& color, int id = UNKNOWN_ID); + const glm::vec4& quadColor, int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) @@ -230,11 +203,12 @@ private: }; QHash _coneVBOs; + QHash _quad3DTextureVBOs; + QHash _registeredQuadVBOs; int _nextID; - QHash _lastRegisteredQuad3DTexture; - QHash _quad3DTextures; - QHash _registeredQuad3DTextures; + QHash _lastRegisteredQuad3DTexture; + QHash _lastRegisteredQuad2DTexture; QHash _quad2DTextures; From 418b97a6485b84a0c17286b0630e5c5d47e223d0 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 10:50:13 -0800 Subject: [PATCH 32/50] attempt to get color working for 3d textured quads --- interface/src/ui/ApplicationOverlay.cpp | 3 +- libraries/render-utils/src/GeometryCache.cpp | 153 +++++++++---------- libraries/render-utils/src/GeometryCache.h | 36 ++++- 3 files changed, 106 insertions(+), 86 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 2e6e1a1df4..9f5f6e21e5 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -257,7 +257,8 @@ void ApplicationOverlay::displayOverlayTexture() { glm::vec2 texCoordTopLeft(0.0f, 1.0f); glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight, + glm::vec4(1.0f, 1.0f, 1.0f, _alpha)); } glPopMatrix(); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a493b815a8..2ddb46d196 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1254,9 +1254,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& quadColor, int id) { + const glm::vec4& color, int id) { - #ifdef WANT_DEBUG + #if 1 // def WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; qDebug() << " topLeft:" << topLeft; qDebug() << " bottomLeft:" << bottomLeft; @@ -1264,106 +1264,99 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom qDebug() << " topRight:" << topRight; qDebug() << " texCoordTopLeft:" << texCoordTopLeft; qDebug() << " texCoordBottomRight:" << texCoordBottomRight; + qDebug() << " color:" << color; #endif //def WANT_DEBUG - bool registeredQuad = (id != UNKNOWN_ID); - Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); - VerticesIndices& vbo = registeredQuad ? _registeredQuadVBOs[id] : _quad3DTextureVBOs[key]; - + bool registered = (id != UNKNOWN_ID); + Vec3PairVec4Pair key(Vec3Pair(topLeft, bottomRight), + Vec4Pair(glm::vec4(texCoordTopLeft.x,texCoordTopLeft.y,texCoordBottomRight.x,texCoordBottomRight.y), + color)); + + BatchItemDetails& details = registered ? _registeredQuad3DTextures[id] : _quad3DTextures[key]; + // if this is a registered quad, and we have buffers, then check to see if the geometry changed and rebuild if needed - if (registeredQuad && vbo.first != 0) { - Vec3PairVec2Pair& lastKey = _lastRegisteredQuad3DTexture[id]; + if (registered && details.isCreated) { + Vec3PairVec4Pair& lastKey = _lastRegisteredQuad3DTexture[id]; if (lastKey != key) { - glDeleteBuffers(1, &vbo.first); - glDeleteBuffers(1, &vbo.second); - vbo.first = vbo.second = 0; + details.clear(); + _lastRegisteredQuad3DTexture[id] = key; #ifdef WANT_DEBUG - qDebug() << "renderQuad() vec3 + texture VBO... RELEASING REGISTERED QUAD"; + qDebug() << "renderQuad() 3D+texture ... RELEASING REGISTERED"; #endif // def WANT_DEBUG } #ifdef WANT_DEBUG else { - qDebug() << "renderQuad() vec3 + texture... REUSING PREVIOUSLY REGISTERED QUAD"; + qDebug() << "renderQuad() 3D+texture ... REUSING PREVIOUSLY REGISTERED"; } #endif // def WANT_DEBUG } - - const int FLOATS_PER_VERTEX = 5; // text coords & vertices - const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + + const int FLOATS_PER_VERTEX = 3 + 2; // 3d vertices + text coords const int vertices = 4; - const int indices = 4; - if (vbo.first == 0) { - _lastRegisteredQuad3DTexture[id] = key; - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexData = new GLfloat[vertexPoints]; // text coords & vertices - GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; - int v = 0; + const int NUM_POS_COORDS = 3; + const int VERTEX_TEXCOORD_OFFSET = NUM_POS_COORDS * sizeof(float); - vertex[v++] = topLeft.x; - vertex[v++] = topLeft.y; - vertex[v++] = topLeft.z; - vertex[v++] = texCoordTopLeft.x; - vertex[v++] = texCoordTopLeft.y; - - vertex[v++] = bottomLeft.x; - vertex[v++] = bottomLeft.y; - vertex[v++] = bottomLeft.z; - vertex[v++] = texCoordBottomLeft.x; - vertex[v++] = texCoordBottomLeft.y; - - vertex[v++] = bottomRight.x; - vertex[v++] = bottomRight.y; - vertex[v++] = bottomRight.z; - vertex[v++] = texCoordBottomRight.x; - vertex[v++] = texCoordBottomRight.y; - - vertex[v++] = topRight.x; - vertex[v++] = topRight.y; - vertex[v++] = topRight.z; - vertex[v++] = texCoordTopRight.x; - vertex[v++] = texCoordTopRight.y; - - glGenBuffers(1, &vbo.first); - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBufferData(GL_ARRAY_BUFFER, vertices * NUM_BYTES_PER_VERTEX, vertexData, GL_STATIC_DRAW); - delete[] vertexData; - - GLushort* indexData = new GLushort[indices]; - GLushort* index = indexData; - for (int i = 0; i < indices; i++) { - index[i] = cannonicalIndices[i]; - } - - glGenBuffers(1, &vbo.second); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); - delete[] indexData; + if (!details.isCreated) { - #ifdef WANT_DEBUG - if (id == UNKNOWN_ID) { - qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); - } else { - qDebug() << "new registered quad VBO made -- _registeredQuadVBOs.size():" << _registeredQuadVBOs.size(); - } - #endif - } else { - glBindBuffer(GL_ARRAY_BUFFER, vbo.first); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + details.isCreated = true; + details.vertices = vertices; + details.vertexSize = FLOATS_PER_VERTEX; // NOTE: this isn't used for BatchItemDetails maybe we can get rid of it + + gpu::BufferPointer verticesBuffer(new gpu::Buffer()); + gpu::BufferPointer colorBuffer(new gpu::Buffer()); + gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format()); + gpu::BufferStreamPointer stream(new gpu::BufferStream()); + + details.verticesBuffer = verticesBuffer; + details.colorBuffer = colorBuffer; + details.streamFormat = streamFormat; + details.stream = stream; + + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); + details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); + + details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); + details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); + + + float vertexBuffer[vertices * FLOATS_PER_VERTEX] = { + topLeft.x, topLeft.y, topLeft.z, texCoordTopLeft.x, texCoordTopLeft.y, + bottomLeft.x, bottomLeft.y, bottomLeft.z, texCoordBottomLeft.x, texCoordBottomLeft.y, + bottomRight.x, bottomRight.y, bottomRight.z, texCoordBottomRight.x, texCoordBottomRight.y, + topRight.x, topRight.y, topRight.z, texCoordTopRight.x, texCoordTopRight.y, + }; + + const int NUM_COLOR_SCALARS_PER_QUAD = 4; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | + ((int(color.y * 255.0f) & 0xFF) << 8) | + ((int(color.z * 255.0f) & 0xFF) << 16) | + ((int(color.w * 255.0f) & 0xFF) << 24); + int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; + + + details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); + details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); - glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float))); + gpu::Batch batch; - glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + glEnable(GL_TEXTURE_2D); + //glBindTexture(GL_TEXTURE_2D, _currentTextureID); // this is quad specific... + + batch.setInputFormat(details.streamFormat); + batch.setInputStream(0, *details.stream); + batch.draw(gpu::QUADS, 4, 0); + + gpu::GLBackend::renderBatch(batch); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - + glDisableClientState(GL_COLOR_ARRAY); + glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 6a018a6ab3..300e68aadd 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -39,7 +39,10 @@ typedef glm::vec3 Vec3Key; typedef QPair Vec2Pair; typedef QPair Vec2PairPair; typedef QPair Vec3Pair; +typedef QPair Vec4Pair; typedef QPair Vec3PairVec2Pair; +typedef QPair Vec3PairVec4Pair; +typedef QPair Vec4PairVec4Pair; inline uint qHash(const glm::vec2& v, uint seed) { // multiply by prime numbers greater than the possible size @@ -70,6 +73,12 @@ inline uint qHash(const Vec3Pair& v, uint seed) { + 5021 * v.second.x + 5023 * v.second.y + 5039 * v.second.z, seed); } +inline uint qHash(const Vec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.x + 5009 * v.first.y + 5011 * v.first.z + 5021 * v.first.w + + 5023 * v.second.x + 5039 * v.second.y + 5051 * v.second.z + 5059 * v.second.w , seed); +} + inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { // multiply by prime numbers greater than the possible size return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + @@ -78,6 +87,24 @@ inline uint qHash(const Vec3PairVec2Pair& v, uint seed) { 5077 * v.second.second.x + 5081 * v.second.second.y, seed); } +inline uint qHash(const Vec3PairVec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z + + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w + + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, + seed); +} + +inline uint qHash(const Vec4PairVec4Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.first.x + 5009 * v.first.first.y + 5011 * v.first.first.z + 5021 * v.first.first.w + + 5023 * v.first.second.x + 5039 * v.first.second.y + 5051 * v.first.second.z + 5059 * v.first.second.w + + 5077 * v.second.first.x + 5081 * v.second.first.y + 5087 * v.second.first.z + 5099 * v.second.first.w + + 5101 * v.second.second.x + 5107 * v.second.second.y + 5113 * v.second.second.z + 5119 * v.second.second.w, + seed); +} + /// Stores cached geometry. class GeometryCache : public ResourceCache, public Dependency { Q_OBJECT @@ -117,7 +144,7 @@ public: const glm::vec3& bottomRight, const glm::vec3& topRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomLeft, const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, - const glm::vec4& quadColor, int id = UNKNOWN_ID); + const glm::vec4& color, int id = UNKNOWN_ID); void renderLine(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& color, int id = UNKNOWN_ID) @@ -203,12 +230,11 @@ private: }; QHash _coneVBOs; - QHash _quad3DTextureVBOs; - QHash _registeredQuadVBOs; int _nextID; - QHash _lastRegisteredQuad3DTexture; - + QHash _lastRegisteredQuad3DTexture; + QHash _quad3DTextures; + QHash _registeredQuad3DTextures; QHash _lastRegisteredQuad2DTexture; QHash _quad2DTextures; From 534575fd102c5bb599812ca5f5877c5f78b2bcf6 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 13:16:14 -0800 Subject: [PATCH 33/50] fix a couple bugs in 3d textured version of renderQuad --- libraries/render-utils/src/GeometryCache.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2ddb46d196..89be78e74f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1256,7 +1256,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom const glm::vec2& texCoordBottomRight, const glm::vec2& texCoordTopRight, const glm::vec4& color, int id) { - #if 1 // def WANT_DEBUG + #ifdef WANT_DEBUG qDebug() << "renderQuad() vec3 + texture VBO..."; qDebug() << " topLeft:" << topLeft; qDebug() << " bottomLeft:" << bottomLeft; @@ -1312,7 +1312,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom details.streamFormat = streamFormat; details.stream = stream; - details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); details.streamFormat->setAttribute(gpu::Stream::TEXCOORD, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV), VERTEX_TEXCOORD_OFFSET); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); @@ -1334,7 +1334,6 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom ((int(color.w * 255.0f) & 0xFF) << 24); int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor }; - details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Buffer::Byte*) vertexBuffer); details.colorBuffer->append(sizeof(colors), (gpu::Buffer::Byte*) colors); } @@ -1355,8 +1354,12 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glDisableClientState(GL_COLOR_ARRAY); glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindTexture(GL_TEXTURE_2D, 0); - glDisable(GL_TEXTURE_2D); + + // TODO: The callers of this method (renderMagnifier and renderReticle) assume that we won't disable an unbind + // the texture after rendering. I'm not sure if this is correct in general but it's currently required for the + // oculus overlay to work. + //glBindTexture(GL_TEXTURE_2D, 0); + //glDisable(GL_TEXTURE_2D); } void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) { From 8c0db268e639ec1a12ad1da7ae64692e44bb1460 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 13:41:39 -0800 Subject: [PATCH 34/50] fix build buster --- interface/src/devices/PrioVR.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/devices/PrioVR.cpp b/interface/src/devices/PrioVR.cpp index 78b802ac9c..56b2587b0d 100644 --- a/interface/src/devices/PrioVR.cpp +++ b/interface/src/devices/PrioVR.cpp @@ -218,6 +218,6 @@ void PrioVR::renderCalibrationCountdown() { auto glCanvas = DependencyManager::get(); textRenderer->draw((glCanvas->width() - textRenderer->computeWidth(text.constData())) / 2, glCanvas->height() / 2, - text); + text, glm::vec4(1,1,1,1)); #endif } From b2f16be92a19bc16869d4d4f53081b8bca25c911 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 29 Jan 2015 15:17:55 -0800 Subject: [PATCH 35/50] Fixing the non loading of some texture because the QImage bit size is not exactly what's expected --- interface/src/ui/overlays/ImageOverlay.cpp | 14 ++++++++++++-- libraries/gpu/src/gpu/Texture.cpp | 11 ++++++++++- libraries/render-utils/src/TextureCache.cpp | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 0c5d9a7737..73da8cc9c0 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -45,7 +45,6 @@ ImageOverlay::~ImageOverlay() { // TODO: handle setting image multiple times, how do we manage releasing the bound texture? void ImageOverlay::setImageURL(const QUrl& url) { _imageURL = url; - if (url.isEmpty()) { _isLoaded = true; _renderImage = false; @@ -57,6 +56,8 @@ void ImageOverlay::setImageURL(const QUrl& url) { } void ImageOverlay::render(RenderArgs* args) { + QString problem("http://s3.amazonaws.com/hifi-public/images/tools/grid-toolbar.svg"); + bool theONE = (_imageURL == problem); if (!_isLoaded && _renderImage) { _isLoaded = true; _texture = DependencyManager::get()->getTexture(_imageURL); @@ -69,8 +70,17 @@ void ImageOverlay::render(RenderArgs* args) { } if (_renderImage) { + glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, _texture->getID()); + if (theONE) { + std::string name = _imageURL.toString().toStdString(); + } + GLuint texID = _texture->getID(); + if (texID == 27) { + std::string name = _imageURL.toString().toStdString(); + glBindTexture(GL_TEXTURE_2D, texID); + } else + glBindTexture(GL_TEXTURE_2D, _texture->getID()); } const float MAX_COLOR = 255.0f; diff --git a/libraries/gpu/src/gpu/Texture.cpp b/libraries/gpu/src/gpu/Texture.cpp index d0779afb42..f9fbcb72df 100755 --- a/libraries/gpu/src/gpu/Texture.cpp +++ b/libraries/gpu/src/gpu/Texture.cpp @@ -254,7 +254,16 @@ bool Texture::assignStoredMip(uint16 level, const Element& format, Size size, co } // THen check that the mem buffer passed make sense with its format - if (size == evalStoredMipSize(level, format)) { + Size expectedSize = evalStoredMipSize(level, format); + if (size == expectedSize) { + _storage->assignMipData(level, format, size, bytes); + _stamp++; + return true; + } else if (size > expectedSize) { + // NOTE: We are facing this case sometime because apparently QImage (from where we get the bits) is generating images + // and alligning the line of pixels to 32 bits. + // We should probably consider something a bit more smart to get the correct result but for now (UI elements) + // it seems to work... _storage->assignMipData(level, format, size, bytes); _stamp++; return true; diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 3644ded81c..aac2ec1b8c 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -387,7 +387,7 @@ NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArr if (!url.isValid()) { _loaded = true; } - + // default to white/blue/black /* glBindTexture(GL_TEXTURE_2D, getID()); switch (type) { From ec54ac7401a5186e882bbeaa5f4acea6a100af4f Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Thu, 29 Jan 2015 15:24:36 -0800 Subject: [PATCH 36/50] Fixing the non loading of some texture because the QImage bit size is not exactly what's expected --- interface/src/ui/overlays/ImageOverlay.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index 73da8cc9c0..e354ea539e 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -56,8 +56,6 @@ void ImageOverlay::setImageURL(const QUrl& url) { } void ImageOverlay::render(RenderArgs* args) { - QString problem("http://s3.amazonaws.com/hifi-public/images/tools/grid-toolbar.svg"); - bool theONE = (_imageURL == problem); if (!_isLoaded && _renderImage) { _isLoaded = true; _texture = DependencyManager::get()->getTexture(_imageURL); @@ -70,17 +68,8 @@ void ImageOverlay::render(RenderArgs* args) { } if (_renderImage) { - glEnable(GL_TEXTURE_2D); - if (theONE) { - std::string name = _imageURL.toString().toStdString(); - } - GLuint texID = _texture->getID(); - if (texID == 27) { - std::string name = _imageURL.toString().toStdString(); - glBindTexture(GL_TEXTURE_2D, texID); - } else - glBindTexture(GL_TEXTURE_2D, _texture->getID()); + glBindTexture(GL_TEXTURE_2D, _texture->getID()); } const float MAX_COLOR = 255.0f; From c00346e8cb42fd72c36f646e10fdc09603a15aee Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 29 Jan 2015 16:45:19 -0800 Subject: [PATCH 37/50] Revert "Remove gridControls.html" This reverts commit a0cb40597b416eba0294141e3cb4834e7ef9afd6. --- examples/html/gridControls.html | 167 ++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 examples/html/gridControls.html diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html new file mode 100644 index 0000000000..06090da423 --- /dev/null +++ b/examples/html/gridControls.html @@ -0,0 +1,167 @@ + + + + + + +
+ +
+ +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + +
+ +
+ + + +
+
+ + + +
+
+ + From eb69720af4565916ed6359b0c30750f64c4890be Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 29 Jan 2015 16:58:44 -0800 Subject: [PATCH 38/50] Update when grid tool window is shown --- examples/editEntities.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index e2c7a6d435..43c36a0846 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -38,6 +38,7 @@ var cameraManager = new CameraManager(); Script.include("libraries/gridTool.js"); var grid = Grid(); gridTool = GridTool({ horizontalGrid: grid }); +gridTool.setVisible(false); Script.include("libraries/entityList.js"); var entityListTool = EntityListTool(); @@ -52,8 +53,10 @@ selectionManager.addEventListener(function() { // Open properties and model list, but force selection of model list tab propertiesTool.setVisible(false); entityListTool.setVisible(false); + gridTool.setVisible(false); propertiesTool.setVisible(true); entityListTool.setVisible(true); + gridTool.setVisible(true); hasShownPropertiesTool = true; } }); @@ -239,7 +242,6 @@ var toolBar = (function () { } else { hasShownPropertiesTool = false; cameraManager.enable(); - gridTool.setVisible(true); grid.setEnabled(true); } } From 0307448ec323ce282797d9b3323a635fa6b89b08 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 29 Jan 2015 16:59:37 -0800 Subject: [PATCH 39/50] Fix color index for entity grid tool --- examples/html/gridControls.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html index 06090da423..ef4c6aa8c5 100644 --- a/examples/html/gridControls.html +++ b/examples/html/gridControls.html @@ -11,6 +11,7 @@ { red: 0, green: 255, blue: 0}, { red: 0, green: 0, blue: 255 }, ]; + var gridColorIndex = 0; elPosY = document.getElementById("horiz-y"); elMinorSpacing = document.getElementById("minor-spacing"); @@ -59,6 +60,7 @@ minorGridSpacing: elMinorSpacing.value, majorGridEvery: elMajorSpacing.value, gridColor: gridColor, + colorIndex: gridColorIndex, snapToGrid: elSnapToGrid.checked, visible: elHorizontalGridVisible.checked, })); @@ -93,12 +95,13 @@ box.setAttribute('class', 'color-box'); box.style.background = 'rgb(' + colors.red + ', ' + colors.green + ', ' + colors.blue + ')'; document.getElementById("grid-colors").appendChild(box); - box.addEventListener("click", function(color) { + box.addEventListener("click", function(color, index) { return function() { gridColor = color; + gridColorIndex = index; emitUpdate(); } - }({ red: colors.red, green: colors.green, blue: colors.blue })); + }({ red: colors.red, green: colors.green, blue: colors.blue }, i)); } EventBridge.emitWebEvent(JSON.stringify({ type: 'init' })); From 7017fdbac08fbe302055f724df987783f2152d5a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Thu, 29 Jan 2015 16:59:58 -0800 Subject: [PATCH 40/50] Update style of grid tools --- examples/html/gridControls.html | 4 ---- examples/html/style.css | 4 +--- examples/libraries/gridTool.js | 6 +++--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html index ef4c6aa8c5..7e354c5bec 100644 --- a/examples/html/gridControls.html +++ b/examples/html/gridControls.html @@ -109,10 +109,6 @@ -
- -
-
diff --git a/examples/html/style.css b/examples/html/style.css index 08ca32aba5..8b52447ea2 100644 --- a/examples/html/style.css +++ b/examples/html/style.css @@ -73,8 +73,6 @@ body { } .grid-section { - border-top: 0.75pt solid #DDD; - background-color: #efefef; } input[type=button] { @@ -169,7 +167,7 @@ input { color: rgb(150, 150, 150); } -#properties-list input, #properties-list textarea { +input, textarea { background-color: rgb(102, 102, 102); color: rgb(204, 204, 204); border: none; diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 7eff1da5d0..6e16186abc 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -2,11 +2,11 @@ Grid = function(opts) { var that = {}; var colors = [ - { red: 0, green: 255, blue: 0 }, - { red: 255, green: 255, blue: 255 }, { red: 0, green: 0, blue: 0 }, - { red: 0, green: 0, blue: 255 }, + { red: 255, green: 255, blue: 255 }, { red: 255, green: 0, blue: 0 }, + { red: 0, green: 255, blue: 0 }, + { red: 0, green: 0, blue: 255 }, ]; var colorIndex = 0; var gridAlpha = 0.6; From a4c82072a2f4b8247491c42c9dc2b8c93c4d5244 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 30 Jan 2015 02:00:35 +0100 Subject: [PATCH 41/50] changing texture size limit from 1024*1024 to 2M i.e. (1024 * 2048). It's dynamic and resizes the texture to the best fit within the 2M area. --- libraries/render-utils/src/TextureCache.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index 3644ded81c..a0c47585c7 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -458,13 +458,18 @@ void ImageReader::run() { int originalWidth = image.width(); int originalHeight = image.height(); - // enforce a fixed maximum - const int MAXIMUM_SIZE = 1024; - if (image.width() > MAXIMUM_SIZE || image.height() > MAXIMUM_SIZE) { - qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height(); - image = image.scaled(MAXIMUM_SIZE, MAXIMUM_SIZE, Qt::KeepAspectRatio); - } + // enforce a fixed maximum area (1024 * 2048) + const float MAXIMUM_AREA_SIZE = 2097152.0f; int imageArea = image.width() * image.height(); + if (imageArea > MAXIMUM_AREA_SIZE) { + float scaleRatio = sqrtf(MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); + int resizeWidth = static_cast(std::floor(scaleRatio * static_cast(image.width()))); + int resizeHeight = static_cast(std::floor(scaleRatio * static_cast(image.height()))); + qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height() << + " scaled to :" << resizeWidth << resizeHeight; + image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio); + imageArea = image.width() * image.height(); + } const int EIGHT_BIT_MAXIMUM = 255; if (!image.hasAlphaChannel()) { From ff29b1c8cc3954108edc7085a2afba3c9b74c420 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 30 Jan 2015 02:18:51 +0100 Subject: [PATCH 42/50] style/conversion fixes --- libraries/render-utils/src/TextureCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/TextureCache.cpp b/libraries/render-utils/src/TextureCache.cpp index a0c47585c7..a97b3f599a 100644 --- a/libraries/render-utils/src/TextureCache.cpp +++ b/libraries/render-utils/src/TextureCache.cpp @@ -459,14 +459,14 @@ void ImageReader::run() { int originalHeight = image.height(); // enforce a fixed maximum area (1024 * 2048) - const float MAXIMUM_AREA_SIZE = 2097152.0f; + const int MAXIMUM_AREA_SIZE = 2097152; int imageArea = image.width() * image.height(); if (imageArea > MAXIMUM_AREA_SIZE) { - float scaleRatio = sqrtf(MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); + float scaleRatio = sqrtf((float)MAXIMUM_AREA_SIZE) / sqrtf((float)imageArea); int resizeWidth = static_cast(std::floor(scaleRatio * static_cast(image.width()))); int resizeHeight = static_cast(std::floor(scaleRatio * static_cast(image.height()))); qDebug() << "Image greater than maximum size:" << _url << image.width() << image.height() << - " scaled to :" << resizeWidth << resizeHeight; + " scaled to:" << resizeWidth << resizeHeight; image = image.scaled(resizeWidth, resizeHeight, Qt::IgnoreAspectRatio); imageArea = image.width() * image.height(); } From c1bb03e9a861dc616230df352a108ed41c8aa19a Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 17:23:48 -0800 Subject: [PATCH 43/50] CR feedback --- libraries/render-utils/src/GeometryCache.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 89be78e74f..351ee19930 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -57,7 +57,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0)); IntPair slicesStacksKey(slices, stacks); - Vec3Pair colorKey(glm::vec3(color.x, color.y, slices),glm::vec3(color.z, color.y, stacks)); + Vec3Pair colorKey(glm::vec3(color.x, color.y, slices), glm::vec3(color.z, color.y, stacks)); int vertices = slices * (stacks - 1) + 2; int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD; @@ -1478,6 +1478,7 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en int GeometryCache::BatchItemDetails::population = 0; + GeometryCache::BatchItemDetails::BatchItemDetails() : verticesBuffer(NULL), colorBuffer(NULL), From 66567fd89d20069e9d0670528251435f850ef209 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 29 Jan 2015 17:24:56 -0800 Subject: [PATCH 44/50] CR feedback --- libraries/render-utils/src/GeometryCache.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 351ee19930..c32b8ff757 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -344,7 +344,7 @@ void GeometryCache::renderCone(float base, float height, int slices, int stacks) void GeometryCache::renderGrid(int xDivisions, int yDivisions, const glm::vec4& color) { IntPair key(xDivisions, yDivisions); - Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions),glm::vec3(color.z, color.y, xDivisions)); + Vec3Pair colorKey(glm::vec3(color.x, color.y, yDivisions), glm::vec3(color.z, color.y, xDivisions)); int vertices = (xDivisions + 1 + yDivisions + 1) * 2; if (!_gridBuffers.contains(key)) { @@ -441,7 +441,7 @@ void GeometryCache::renderGrid(int x, int y, int width, int height, int rows, in bool registered = (id != UNKNOWN_ID); Vec3Pair key(glm::vec3(x, y, width), glm::vec3(height, rows, cols)); - Vec3Pair colorKey(glm::vec3(color.x, color.y, rows),glm::vec3(color.z, color.y, cols)); + Vec3Pair colorKey(glm::vec3(color.x, color.y, rows), glm::vec3(color.z, color.y, cols)); int vertices = (cols + 1 + rows + 1) * 2; if ((registered && !_registeredAlternateGridBuffers.contains(id)) || (!registered && !_alternateGridBuffers.contains(key))) { @@ -680,7 +680,7 @@ void GeometryCache::renderVertices(gpu::Primitive primitiveType, int id) { } void GeometryCache::renderSolidCube(float size, const glm::vec4& color) { - Vec2Pair colorKey(glm::vec2(color.x, color.y),glm::vec2(color.z, color.y)); + Vec2Pair colorKey(glm::vec2(color.x, color.y), glm::vec2(color.z, color.y)); const int FLOATS_PER_VERTEX = 3; const int VERTICES_PER_FACE = 4; const int NUMBER_OF_FACES = 6; From f26ad6c95c610d3990eab0d0f0146adebb17a902 Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Fri, 30 Jan 2015 02:52:24 +0100 Subject: [PATCH 45/50] ignore multiple build directories ignore /build-test/, /build-vs2013/, /build-osx/, /build-ubuntu/ , /build-cygwin/ --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8365108df9..34f11c273a 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ CMakeCache.txt CMakeFiles/ CMakeScripts/ cmake_install.cmake -build/ +build*/ Makefile *.user From 5d8825f5eb65597e7339965d2079aeb08e1e3a2a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 08:56:37 -0800 Subject: [PATCH 46/50] Remove call to gridTool.mousePressEvent --- examples/editEntities.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index 1b551ab2e9..2d0fb3dc8a 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -512,7 +512,7 @@ function mousePressEvent(event) { mouseHasMovedSincePress = false; mouseCapturedByTool = false; - if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || gridTool.mousePressEvent(event)) { + if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) { mouseCapturedByTool = true; return; } From cddce8f7956951e1763a4bb8ac101b08f0668bb6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 09:21:27 -0800 Subject: [PATCH 47/50] Update editEntities to always be on + use right click for select --- examples/editEntities.js | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index e2c7a6d435..4605e040fd 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -56,6 +56,11 @@ selectionManager.addEventListener(function() { entityListTool.setVisible(true); hasShownPropertiesTool = true; } + if (!selectionManager.hasSelection()) { + toolBar.setActive(false); + } else { + toolBar.setActive(true); + } }); var windowDimensions = Controller.getViewportDimensions(); @@ -123,11 +128,13 @@ var toolBar = (function () { function initialize() { toolBar = new ToolBar(0, 0, ToolBar.VERTICAL); + // Hide active button for now - this may come back, so not deleting yet. activeButton = toolBar.addTool({ imageURL: toolIconUrl + "models-tool.svg", - subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, - width: toolWidth, - height: toolHeight, + // subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: Tool.IMAGE_WIDTH, height: Tool.IMAGE_HEIGHT }, + subImage: { x: 0, y: Tool.IMAGE_WIDTH, width: 0, height: 0 }, + width: 0,//toolWidth, + height: 0,//toolHeight, alpha: 0.9, visible: true }, true, false); @@ -543,19 +550,16 @@ function mouseMoveEvent(event) { } mouseHasMovedSincePress = true; - if (isActive) { - // allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing - if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) { - return; - } - lastMousePosition = { x: event.x, y: event.y }; - - highlightEntityUnderCursor(lastMousePosition, false); - idleMouseTimerId = Script.setTimeout(handleIdleMouse, IDLE_MOUSE_TIMEOUT); - } else { - cameraManager.mouseMoveEvent(event); + // allow the selectionDisplay and cameraManager to handle the event first, if it doesn't handle it, then do our own thing + if (selectionDisplay.mouseMoveEvent(event) || cameraManager.mouseMoveEvent(event)) { + return; } + + lastMousePosition = { x: event.x, y: event.y }; + + highlightEntityUnderCursor(lastMousePosition, false); + idleMouseTimerId = Script.setTimeout(handleIdleMouse, IDLE_MOUSE_TIMEOUT); } function handleIdleMouse() { @@ -608,7 +612,7 @@ function mouseReleaseEvent(event) { } function mouseClickEvent(event) { - if (!isActive) { + if (!event.isRightButton) { return; } @@ -619,6 +623,7 @@ function mouseClickEvent(event) { } return; } + toolBar.setActive(true); var pickRay = result.pickRay; var foundEntity = result.entityID; @@ -830,6 +835,8 @@ Controller.keyReleaseEvent.connect(function (event) { // since sometimes our menu shortcut keys don't work, trap our menu items here also and fire the appropriate menu items if (event.text == "BACKSPACE" || event.text == "DELETE") { deleteSelectedEntities(); + } else if (event.text == "ESC") { + selectionManager.clearSelections(); } else if (event.text == "TAB") { selectionDisplay.toggleSpaceMode(); } else if (event.text == "f") { @@ -1082,4 +1089,4 @@ PropertiesTool = function(opts) { }; propertiesTool = PropertiesTool(); - +toolBar.setActive(true); From 018a4af9d613fe023b6f98014a346e890df5c398 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 09:22:39 -0800 Subject: [PATCH 48/50] Update camera tool to wrap cursor to window bounds rather than keep at center --- examples/libraries/entityCameraTool.js | 41 ++++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/examples/libraries/entityCameraTool.js b/examples/libraries/entityCameraTool.js index f5095bb149..9f53d585d2 100644 --- a/examples/libraries/entityCameraTool.js +++ b/examples/libraries/entityCameraTool.js @@ -208,6 +208,11 @@ CameraManager = function() { if (that.enabled && that.mode != MODE_INACTIVE) { var x = Window.getCursorPositionX(); var y = Window.getCursorPositionY(); + if (!hasDragged) { + that.lastMousePosition.x = x; + that.lastMousePosition.y = y; + hasDragged = true; + } if (that.mode == MODE_ORBIT) { var diffX = x - that.lastMousePosition.x; var diffY = y - that.lastMousePosition.y; @@ -235,9 +240,31 @@ CameraManager = function() { that.moveFocalPoint(dPosition); } - var newX = Window.x + Window.innerWidth / 2; - var newY = Window.y + Window.innerHeight / 2; - Window.setCursorPosition(newX, newY); + + var newX = x; + var newY = y; + var updatePosition = false; + + if (x <= Window.x) { + newX = Window.x + Window.innerWidth; + updatePosition = true; + } else if (x >= (Window.x + Window.innerWidth)) { + newX = Window.x; + updatePosition = true; + } + + if (y <= Window.y) { + newY = Window.y + Window.innerHeight; + updatePosition = true; + } else if (y >= (Window.y + Window.innerHeight)) { + newY = Window.y; + updatePosition = true; + } + + if (updatePosition) { + Window.setCursorPosition(newX, newY); + } + that.lastMousePosition.x = newX; that.lastMousePosition.y = newY; @@ -246,6 +273,7 @@ CameraManager = function() { return false; } + var hasDragged = false; that.mousePressEvent = function(event) { if (cameraTool.mousePressEvent(event)) { return true; @@ -260,12 +288,7 @@ CameraManager = function() { } if (that.mode != MODE_INACTIVE) { - var newX = Window.x + Window.innerWidth / 2; - var newY = Window.y + Window.innerHeight / 2; - Window.setCursorPosition(newX, newY); - that.lastMousePosition.x = newX; - that.lastMousePosition.y = newY; - Window.setCursorVisible(false); + hasDragged = false; return true; } From 0d1488e44f90bf42235345cffbf493356df51f07 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Fri, 30 Jan 2015 10:03:37 -0800 Subject: [PATCH 49/50] Fix editEntities.js includes --- examples/editEntities.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index df8605f9df..92223827b9 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -14,23 +14,23 @@ HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; Script.include([ - "http://public.highfidelity.io/scripts/libraries/stringHelpers.js", - "http://public.highfidelity.io/scripts/libraries/dataviewHelpers.js", - "http://public.highfidelity.io/scripts/libraries/httpMultiPart.js", - "http://public.highfidelity.io/scripts/libraries/modelUploader.js", - "http://public.highfidelity.io/scripts/libraries/toolBars.js", - "http://public.highfidelity.io/scripts/libraries/progressDialog.js", + "libraries/stringHelpers.js", + "libraries/dataviewHelpers.js", + "libraries/httpMultiPart.js", + "libraries/modelUploader.js", + "libraries/toolBars.js", + "libraries/progressDialog.js", - "http://public.highfidelity.io/scripts/libraries/entitySelectionTool.js", - "http://public.highfidelity.io/scripts/libraries/ModelImporter.js", + "libraries/entitySelectionTool.js", + "libraries/ModelImporter.js", - "http://public.highfidelity.io/scripts/libraries/ExportMenu.js", - "http://public.highfidelity.io/scripts/libraries/ToolTip.js", + "libraries/ExportMenu.js", + "libraries/ToolTip.js", - "http://public.highfidelity.io/scripts/libraries/entityPropertyDialogBox.js", - "http://public.highfidelity.io/scripts/libraries/entityCameraTool.js", - "http://public.highfidelity.io/scripts/libraries/gridTool.js", - "http://public.highfidelity.io/scripts/libraries/entityList.js", + "libraries/entityPropertyDialogBox.js", + "libraries/entityCameraTool.js", + "libraries/gridTool.js", + "libraries/entityList.js", ]); var selectionDisplay = SelectionDisplay; From 18c77e1cca522d8858629b209b0af85fbce11e93 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Fri, 30 Jan 2015 11:27:45 -0800 Subject: [PATCH 50/50] Fix not saving stopped scripts --- interface/src/Application.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 5a60be39a1..a3c67b516b 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -3407,8 +3407,10 @@ void Application::loadScripts() { } void Application::clearScriptsBeforeRunning() { - // clears all scripts from the settings - SettingHandles::SettingHandle(SETTINGS_KEY).remove(); + // clears all scripts from the settingsSettings settings; + Settings settings; + settings.beginWriteArray(SETTINGS_KEY); + settings.remove(""); } void Application::saveScripts() { @@ -3420,6 +3422,7 @@ void Application::saveScripts() { // Saves all currently running user-loaded scripts Settings settings; settings.beginWriteArray(SETTINGS_KEY); + settings.remove(""); int i = 0; for (auto it = runningScripts.begin(); it != runningScripts.end(); ++it) { if (getScriptEngine(*it)->isUserLoaded()) {