From 663b9c393ed0fea62e2280793ad147cfd03c5deb Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 9 Dec 2014 12:43:34 -0800 Subject: [PATCH 01/23] add debugging --- libraries/entities/src/ModelEntityItem.cpp | 9 +++++++++ libraries/entities/src/ModelEntityItem.h | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index b9bf75178f..ab5a1ee2a9 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,6 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { _animationURL = url; } +void ModelEntityItem::setAnimationFrameIndex(float value) { + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; + qDebug() << " value:" << value; + qDebug() << " was:" << _animationLoop.getFrameIndex(); + } + _animationLoop.setFrameIndex(value); +} + void ModelEntityItem::setAnimationSettings(const QString& value) { // the animations setting is a JSON string that may contain various animation settings. // if it includes fps, frameIndex, or running, those values will be parsed out and diff --git a/libraries/entities/src/ModelEntityItem.h b/libraries/entities/src/ModelEntityItem.h index 6b4ca2416a..3cf2df899d 100644 --- a/libraries/entities/src/ModelEntityItem.h +++ b/libraries/entities/src/ModelEntityItem.h @@ -75,7 +75,7 @@ public: void setModelURL(const QString& url) { _modelURL = url; } void setAnimationURL(const QString& url); static const float DEFAULT_ANIMATION_FRAME_INDEX; - void setAnimationFrameIndex(float value) { _animationLoop.setFrameIndex(value); } + void setAnimationFrameIndex(float value); void setAnimationSettings(const QString& value); static const bool DEFAULT_ANIMATION_IS_PLAYING; From 14458ac8fd4cc7035726a86c75b9dd2bedb8a8e5 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 22 Dec 2014 13:47:18 -0800 Subject: [PATCH 02/23] first pass at removing immediate mode GL_QUADS --- interface/src/Audio.cpp | 9 +-- interface/src/Util.cpp | 30 +-------- interface/src/ui/ApplicationOverlay.cpp | 35 +++++----- interface/src/ui/BandwidthMeter.cpp | 11 ++-- interface/src/ui/Stats.cpp | 9 +-- interface/src/ui/overlays/TextOverlay.cpp | 12 ++-- libraries/render-utils/src/GeometryCache.cpp | 67 ++++++++++++++++++++ libraries/render-utils/src/GeometryCache.h | 36 +++++++++++ libraries/render-utils/src/TextRenderer.cpp | 21 ------ 9 files changed, 135 insertions(+), 95 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index 2511fb4480..a43bda34fa 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -1702,14 +1702,7 @@ void Audio::renderScope(int width, int height) { void Audio::renderBackground(const float* color, int x, int y, int width, int height) { glColor4fv(color); - glBegin(GL_QUADS); - - glVertex2i(x, y); - glVertex2i(x + width, y); - glVertex2i(x + width, y + height); - glVertex2i(x , y + height); - - glEnd(); + DependencyManager::get()->renderQuad(x, y, width, height); glColor4f(1, 1, 1, 1); } diff --git a/interface/src/Util.cpp b/interface/src/Util.cpp index d795964c5c..45a7dabb40 100644 --- a/interface/src/Util.cpp +++ b/interface/src/Util.cpp @@ -130,38 +130,10 @@ void renderCollisionOverlay(int width, int height, float magnitude, float red, f const float MIN_VISIBLE_COLLISION = 0.01f; if (magnitude > MIN_VISIBLE_COLLISION) { glColor4f(red, blue, green, magnitude); - glBegin(GL_QUADS); - glVertex2f(0, 0); - glVertex2d(width, 0); - glVertex2d(width, height); - glVertex2d(0, height); - glEnd(); + DependencyManager::get()->renderQuad(0, 0, width, height); } } - - -void renderCircle(glm::vec3 position, float radius, glm::vec3 surfaceNormal, int numSides) { - glm::vec3 perp1 = glm::vec3(surfaceNormal.y, surfaceNormal.z, surfaceNormal.x); - glm::vec3 perp2 = glm::vec3(surfaceNormal.z, surfaceNormal.x, surfaceNormal.y); - - glBegin(GL_LINE_STRIP); - - for (int i=0; irenderStats(WHITE_TEXT, glCanvas->width(), glCanvas->height()); - glBegin(GL_QUADS); if (isClipping) { glColor3f(1, 0, 0); } else { @@ -846,10 +845,7 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(0, 0, 0); // Draw audio meter background Quad - glVertex2i(AUDIO_METER_X, audioMeterY); - glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY); - glVertex2i(AUDIO_METER_X + AUDIO_METER_WIDTH, audioMeterY + AUDIO_METER_HEIGHT); - glVertex2i(AUDIO_METER_X, audioMeterY + AUDIO_METER_HEIGHT); + DependencyManager::get()->renderQuad(AUDIO_METER_X, audioMeterY, AUDIO_METER_WIDTH, AUDIO_METER_HEIGHT); if (audioLevel > AUDIO_RED_START) { if (!isClipping) { @@ -858,12 +854,16 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Red Quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_RED_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + 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); + audioLevel = AUDIO_RED_START; } + + //glBegin(GL_QUADS); + if (audioLevel > AUDIO_GREEN_START) { if (!isClipping) { glColor3fv(AUDIO_METER_GREEN); @@ -871,10 +871,11 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Green Quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + AUDIO_GREEN_START, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); + 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); + audioLevel = AUDIO_GREEN_START; } // Draw Blue Quad @@ -884,11 +885,9 @@ void ApplicationOverlay::renderAudioMeter() { glColor3f(1, 1, 1); } // Draw Blue (low level) quad - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET + audioLevel, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glVertex2i(AUDIO_METER_X + AUDIO_METER_INSET, audioMeterY + AUDIO_METER_HEIGHT - AUDIO_METER_INSET); - glEnd(); + DependencyManager::get()->renderQuad(AUDIO_METER_X + AUDIO_METER_INSET, + audioMeterY + AUDIO_METER_INSET, + audioLevel, AUDIO_METER_HEIGHT - AUDIO_METER_INSET); } void ApplicationOverlay::renderStatsAndLogs() { diff --git a/interface/src/ui/BandwidthMeter.cpp b/interface/src/ui/BandwidthMeter.cpp index a0a8129229..d28d85428d 100644 --- a/interface/src/ui/BandwidthMeter.cpp +++ b/interface/src/ui/BandwidthMeter.cpp @@ -11,6 +11,9 @@ #include +#include +#include + #include "BandwidthMeter.h" #include "InterfaceConfig.h" @@ -92,13 +95,7 @@ void BandwidthMeter::setColorRGBA(unsigned c) { } void BandwidthMeter::renderBox(int x, int y, int w, int h) { - - glBegin(GL_QUADS); - glVertex2i(x, y); - glVertex2i(x + w, y); - glVertex2i(x + w, y + h); - glVertex2i(x, y + h); - glEnd(); + DependencyManager::get()->renderQuad(x, y, w, h); } void BandwidthMeter::renderVerticalLine(int x, int y, int h) { diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp index ab3927a3ab..eced2d87fd 100644 --- a/interface/src/ui/Stats.cpp +++ b/interface/src/ui/Stats.cpp @@ -154,16 +154,13 @@ 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) { - glBegin(GL_QUADS); glColor4f(((rgba >> 24) & 0xff) / 255.0f, ((rgba >> 16) & 0xff) / 255.0f, ((rgba >> 8) & 0xff) / 255.0f, (rgba & 0xff) / 255.0f); - glVertex3f(x, y, 0); - glVertex3f(x + width, y, 0); - glVertex3f(x + width, y + height, 0); - glVertex3f(x , y + height, 0); - glEnd(); + + DependencyManager::get()->renderQuad(x, y, width, height); + glColor4f(1, 1, 1, 1); } diff --git a/interface/src/ui/overlays/TextOverlay.cpp b/interface/src/ui/overlays/TextOverlay.cpp index 03a5c3d846..ca83e1c595 100644 --- a/interface/src/ui/overlays/TextOverlay.cpp +++ b/interface/src/ui/overlays/TextOverlay.cpp @@ -12,6 +12,9 @@ #include "InterfaceConfig.h" #include + +#include +#include #include #include @@ -75,12 +78,9 @@ void TextOverlay::render(RenderArgs* args) { int top = _bounds.top(); int bottom = _bounds.bottom() + 1; - glBegin(GL_QUADS); - glVertex2f(left, top); - glVertex2f(right, top); - glVertex2f(right, bottom); - glVertex2f(left, bottom); - glEnd(); + glm::vec2 topLeft(left, top); + glm::vec2 bottomRight(right, bottom); + DependencyManager::get()->renderQuad(topLeft, bottomRight); // Same font properties as textSize() TextRenderer* textRenderer = TextRenderer::getInstance(SANS_FONT_FAMILY, _fontSize, DEFAULT_FONT_WEIGHT); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 2837568ef5..65069b773f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -661,6 +661,73 @@ void GeometryCache::renderWireCube(float size) { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } +void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight) { + Vec2Pair key(topLeft, bottomRight); + VerticesIndices& vbo = _quad2DVBOs[key]; + const int FLOATS_PER_VERTEX = 2; + const int vertices = 4; + const int indices = 4; + if (vbo.first == 0) { + int vertexPoints = vertices * FLOATS_PER_VERTEX; + GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat* vertex = vertexData; + // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge + static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 }; + + //glBegin(GL_QUADS); + // glVertex2f(left, top); + // glVertex2f(right, top); + // glVertex2f(right, bottom); + // glVertex2f(left, bottom); + //glEnd(); + + vertex[0] = topLeft.x; + vertex[1] = topLeft.y; + vertex[2] = bottomRight.x; + vertex[3] = topLeft.y; + vertex[4] = bottomRight.x; + vertex[5] = bottomRight.y; + vertex[6] = topLeft.x; + vertex[7] = bottomRight.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; + + qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); + + } 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_QUADS, 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::renderQuad(cont glm::vec2& topLeft, cont glm::vec2& bottomRight, + cont glm::vec2& texCoordTopLeft, cont glm::vec2& texCoordBottomRight) { +} +*/ + QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { return getResource(url, fallback, delayLoad).staticCast(); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 514ee03c79..1c3f2114d6 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -31,6 +31,29 @@ class NetworkGeometry; class NetworkMesh; class NetworkTexture; + +typedef QPair Vec2Pair; +typedef QPair Vec2PairPair; + +inline uint qHash(const glm::vec2& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.x + 5009 * v.y, seed); +} + +inline uint qHash(const Vec2Pair& v, uint seed) { + // multiply by prime numbers greater than the possible size + return qHash(v.first.x + 5009 * v.first.y + 5011 * v.second.x + 5021 * v.second.y, 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 + + 5011 * v.first.second.x + 5021 * v.first.second.y + + 5023 * v.second.first.x + 5039 * v.second.first.y + + 5051 * v.second.second.x + 5059 * v.second.second.y, seed); +} + + /// Stores cached geometry. class GeometryCache : public ResourceCache { Q_OBJECT @@ -46,6 +69,16 @@ public: void renderSolidCube(float size); void renderWireCube(float size); + + void renderQuad(int x, int y, int width, int height) { + renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height)); + }; + + void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight); + void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + + /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param delayLoad if true, don't load the geometry immediately; wait until load is first requested @@ -70,6 +103,9 @@ private: QHash _coneVBOs; QHash _wireCubeVBOs; QHash _solidCubeVBOs; + QHash _quad2DVBOs; + //QHash _quad2DTextureVBOs; + QHash _gridBuffers; QHash > _networkGeometry; diff --git a/libraries/render-utils/src/TextRenderer.cpp b/libraries/render-utils/src/TextRenderer.cpp index 34098c6862..2c677a330a 100644 --- a/libraries/render-utils/src/TextRenderer.cpp +++ b/libraries/render-utils/src/TextRenderer.cpp @@ -81,9 +81,6 @@ int TextRenderer::draw(int x, int y, const char* str, float alpha) { ((int(currentColor[2] * 255.0f) & 0xFF) << 16) | ((int(currentColor[3] * 255.0f) & 0xFF) << 24); -// TODO: Remove that code once we test for performance improvments - //glEnable(GL_TEXTURE_2D); - int maxHeight = 0; for (const char* ch = str; *ch != 0; ch++) { const Glyph& glyph = getGlyph(*ch); @@ -111,20 +108,6 @@ int TextRenderer::draw(int x, int y, const char* str, float alpha) { float bt = glyph.location().y() * scale; float tt = (glyph.location().y() + glyph.bounds().height()) * scale; -// TODO: Remove that code once we test for performance improvments -/* - glBegin(GL_QUADS); - glTexCoord2f(ls, bt); - glVertex2f(left, bottom); - glTexCoord2f(rs, bt); - glVertex2f(right, bottom); - glTexCoord2f(rs, tt); - glVertex2f(right, top); - glTexCoord2f(ls, tt); - glVertex2f(left, top); - glEnd(); -*/ - const int NUM_COORDS_SCALARS_PER_GLYPH = 16; float vertexBuffer[NUM_COORDS_SCALARS_PER_GLYPH] = { leftBottom.x, leftBottom.y, ls, bt, rightTop.x, leftBottom.y, rs, bt, @@ -152,10 +135,6 @@ int TextRenderer::draw(int x, int y, const char* str, float alpha) { drawBatch(); clearBatch(); -// TODO: Remove that code once we test for performance improvments - // glBindTexture(GL_TEXTURE_2D, 0); - // glDisable(GL_TEXTURE_2D); - return maxHeight; } From 3d42d532e4ab2db7915826f85637d835bbeaa4dd Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 22 Dec 2014 17:43:02 -0800 Subject: [PATCH 03/23] more work on removing immediate mode GL_QUADS --- interface/src/Audio.cpp | 41 +++------ interface/src/avatar/Avatar.cpp | 19 ++--- interface/src/ui/ApplicationOverlay.cpp | 29 ++++--- interface/src/ui/RearMirrorTools.cpp | 24 ++---- .../src/ui/overlays/BillboardOverlay.cpp | 23 ++--- interface/src/ui/overlays/ImageOverlay.cpp | 32 +++---- libraries/render-utils/src/GeometryCache.cpp | 84 ++++++++++++++++--- libraries/render-utils/src/GeometryCache.h | 8 +- libraries/render-utils/src/RenderUtil.cpp | 19 ++--- 9 files changed, 147 insertions(+), 132 deletions(-) diff --git a/interface/src/Audio.cpp b/interface/src/Audio.cpp index a43bda34fa..5bcd9bb647 100644 --- a/interface/src/Audio.cpp +++ b/interface/src/Audio.cpp @@ -1306,21 +1306,13 @@ void Audio::renderToolBox(int x, int y, bool boxed) { } else { glColor3f(0.41f, 0.41f, 0.41f); } - glBegin(GL_QUADS); - - glTexCoord2f(1, 1); - glVertex2f(boxBounds.left(), boxBounds.top()); - - glTexCoord2f(0, 1); - glVertex2f(boxBounds.right(), boxBounds.top()); - - glTexCoord2f(0, 0); - glVertex2f(boxBounds.right(), boxBounds.bottom()); - glTexCoord2f(1, 0); - glVertex2f(boxBounds.left(), boxBounds.bottom()); - - glEnd(); + 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); } _iconBounds = QRect(x, y, MUTE_ICON_SIZE, MUTE_ICON_SIZE); @@ -1345,21 +1337,14 @@ void Audio::renderToolBox(int x, int y, bool boxed) { } glColor3f(_iconColor, _iconColor, _iconColor); - glBegin(GL_QUADS); + + glm::vec2 topLeft(_iconBounds.left(), _iconBounds.top()); + glm::vec2 bottomRight(_iconBounds.right(), _iconBounds.bottom()); + glm::vec2 texCoordTopLeft(1,1); + glm::vec2 texCoordBottomRight(0,0); - glTexCoord2f(1.0f, 1.0f); - glVertex2f(_iconBounds.left(), _iconBounds.top()); - - glTexCoord2f(0.0f, 1.0f); - glVertex2f(_iconBounds.right(), _iconBounds.top()); - - glTexCoord2f(0.0f, 0.0f); - glVertex2f(_iconBounds.right(), _iconBounds.bottom()); - - glTexCoord2f(1.0f, 0.0f); - glVertex2f(_iconBounds.left(), _iconBounds.bottom()); - - glEnd(); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + glDisable(GL_TEXTURE_2D); } diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4c309b2c8c..25c5010b7b 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -633,17 +633,14 @@ void Avatar::renderBillboard() { glScalef(size, size, size); glColor3f(1.0f, 1.0f, 1.0f); - - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); - glVertex2f(-1.0f, -1.0f); - glTexCoord2f(1.0f, 0.0f); - glVertex2f(1.0f, -1.0f); - glTexCoord2f(1.0f, 1.0f); - glVertex2f(1.0f, 1.0f); - glTexCoord2f(0.0f, 1.0f); - glVertex2f(-1.0f, 1.0f); - glEnd(); + + 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); + glPopMatrix(); diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 5267659ec2..a34584b24c 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -229,13 +229,14 @@ void ApplicationOverlay::displayOverlayTexture() { glDisable(GL_LIGHTING); glEnable(GL_BLEND); - glBegin(GL_QUADS); { - glColor4f(1.0f, 1.0f, 1.0f, _alpha); - glTexCoord2f(0, 0); glVertex2i(0, glCanvas->getDeviceHeight()); - glTexCoord2f(1, 0); glVertex2i(glCanvas->getDeviceWidth(), glCanvas->getDeviceHeight()); - glTexCoord2f(1, 1); glVertex2i(glCanvas->getDeviceWidth(), 0); - glTexCoord2f(0, 1); glVertex2i(0, 0); - } glEnd(); + 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); + } glPopMatrix(); glDisable(GL_TEXTURE_2D); @@ -658,16 +659,16 @@ void ApplicationOverlay::renderControllerPointers() { mouseX -= reticleSize / 2.0f; mouseY += reticleSize / 2.0f; - glBegin(GL_QUADS); glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - glTexCoord2d(0.0f, 0.0f); glVertex2i(mouseX, mouseY); - glTexCoord2d(1.0f, 0.0f); glVertex2i(mouseX + reticleSize, mouseY); - glTexCoord2d(1.0f, 1.0f); glVertex2i(mouseX + reticleSize, mouseY - reticleSize); - glTexCoord2d(0.0f, 1.0f); glVertex2i(mouseX, mouseY - reticleSize); + 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); - glEnd(); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + } } @@ -862,8 +863,6 @@ void ApplicationOverlay::renderAudioMeter() { audioLevel = AUDIO_RED_START; } - //glBegin(GL_QUADS); - if (audioLevel > AUDIO_GREEN_START) { if (!isClipping) { glColor3fv(AUDIO_METER_GREEN); diff --git a/interface/src/ui/RearMirrorTools.cpp b/interface/src/ui/RearMirrorTools.cpp index 37f7c6ae23..29c8e67f61 100644 --- a/interface/src/ui/RearMirrorTools.cpp +++ b/interface/src/ui/RearMirrorTools.cpp @@ -140,22 +140,14 @@ void RearMirrorTools::displayIcon(QRect bounds, QRect iconBounds, GLuint texture } glBindTexture(GL_TEXTURE_2D, textureId); - glBegin(GL_QUADS); - { - glTexCoord2f(0, 0); - glVertex2f(iconBounds.left(), iconBounds.bottom()); - - glTexCoord2f(0, 1); - glVertex2f(iconBounds.left(), iconBounds.top()); - - glTexCoord2f(1, 1); - glVertex2f(iconBounds.right(), iconBounds.top()); - - glTexCoord2f(1, 0); - glVertex2f(iconBounds.right(), iconBounds.bottom()); - - } - glEnd(); + + glm::vec2 topLeft(iconBounds.left(), iconBounds.top()); + glm::vec2 bottomRight(iconBounds.right(), iconBounds.bottom()); + glm::vec2 texCoordTopLeft(0.0f, 1.0f); + glm::vec2 texCoordBottomRight(1.0f, 0.0f); + + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + glPopMatrix(); glMatrixMode(GL_MODELVIEW); diff --git a/interface/src/ui/overlays/BillboardOverlay.cpp b/interface/src/ui/overlays/BillboardOverlay.cpp index f9ad7fdb38..bcb69bdce3 100644 --- a/interface/src/ui/overlays/BillboardOverlay.cpp +++ b/interface/src/ui/overlays/BillboardOverlay.cpp @@ -96,21 +96,16 @@ void BillboardOverlay::render(RenderArgs* args) { xColor color = getColor(); float alpha = getAlpha(); glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha); - glBegin(GL_QUADS); { - glTexCoord2f((float)_fromImage.x() / (float)_size.width(), - (float)_fromImage.y() / (float)_size.height()); + + glm::vec2 topLeft(-x, -y); + glm::vec2 bottomRight(x, y); + glm::vec2 texCoordTopLeft((float)_fromImage.x() / (float)_size.width(), + (float)_fromImage.y() / (float)_size.height()); + glm::vec2 texCoordBottomRight(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(), + ((float)_fromImage.y() + (float)_fromImage.height()) / _size.height()); - glVertex2f(-x, -y); - glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(), - (float)_fromImage.y() / (float)_size.height()); - glVertex2f(x, -y); - glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(), - ((float)_fromImage.y() + (float)_fromImage.height()) / _size.height()); - glVertex2f(x, y); - glTexCoord2f((float)_fromImage.x() / (float)_size.width(), - ((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height()); - glVertex2f(-x, y); - } glEnd(); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + } } glPopMatrix(); diff --git a/interface/src/ui/overlays/ImageOverlay.cpp b/interface/src/ui/overlays/ImageOverlay.cpp index b14f49737f..d7a6889c05 100644 --- a/interface/src/ui/overlays/ImageOverlay.cpp +++ b/interface/src/ui/overlays/ImageOverlay.cpp @@ -14,6 +14,9 @@ #include #include #include + +#include +#include #include #include "ImageOverlay.h" @@ -105,27 +108,16 @@ void ImageOverlay::render(RenderArgs* args) { int top = _bounds.top(); int bottom = _bounds.bottom() + 1; - glBegin(GL_QUADS); - if (_renderImage) { - glTexCoord2f(x, 1.0f - y); - } - glVertex2f(left, top); + glm::vec2 topLeft(left, top); + glm::vec2 bottomRight(right, bottom); + glm::vec2 texCoordTopLeft(x, 1.0f - y); + glm::vec2 texCoordBottomRight(x + w, 1.0f - (y + h)); - if (_renderImage) { - glTexCoord2f(x + w, 1.0f - y); - } - glVertex2f(right, top); - - if (_renderImage) { - glTexCoord2f(x + w, 1.0f - (y + h)); - } - glVertex2f(right, bottom); - - if (_renderImage) { - glTexCoord2f(x, 1.0f - (y + h)); - } - glVertex2f(left, bottom); - glEnd(); + if (_renderImage) { + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + } else { + DependencyManager::get()->renderQuad(topLeft, bottomRight); + } if (_renderImage) { glDisable(GL_TEXTURE_2D); diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 65069b773f..f6ea9247ce 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -665,22 +665,15 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom Vec2Pair key(topLeft, bottomRight); VerticesIndices& vbo = _quad2DVBOs[key]; const int FLOATS_PER_VERTEX = 2; + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); const int vertices = 4; const int indices = 4; if (vbo.first == 0) { int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad GLfloat* vertex = vertexData; - // index array of vertex array for glDrawRangeElement() as a GL_LINES for each edge static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 }; - //glBegin(GL_QUADS); - // glVertex2f(left, top); - // glVertex2f(right, top); - // glVertex2f(right, bottom); - // glVertex2f(left, bottom); - //glEnd(); - vertex[0] = topLeft.x; vertex[1] = topLeft.y; vertex[2] = bottomRight.x; @@ -722,12 +715,77 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom } -/* -void GeometryCache::renderQuad(cont glm::vec2& topLeft, cont glm::vec2& bottomRight, - cont glm::vec2& texCoordTopLeft, cont glm::vec2& texCoordBottomRight) { -} -*/ +void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) { + Vec2PairPair key(Vec2Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + + VerticesIndices& vbo = _quad2DTextureVBOs[key]; + 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) { + 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; + vertex[v++] = topLeft.x; + vertex[v++] = topLeft.y; + vertex[v++] = texCoordTopLeft.x; + vertex[v++] = texCoordTopLeft.y; + + vertex[v++] = bottomRight.x; + vertex[v++] = topLeft.y; + vertex[v++] = texCoordBottomRight.x; + vertex[v++] = texCoordTopLeft.y; + + vertex[v++] = bottomRight.x; + vertex[v++] = bottomRight.y; + vertex[v++] = texCoordBottomRight.x; + vertex[v++] = texCoordBottomRight.y; + + vertex[v++] = topLeft.x; + vertex[v++] = bottomRight.y; + vertex[v++] = texCoordTopLeft.x; + vertex[v++] = texCoordBottomRight.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; + + qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + + 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))); + + glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { return getResource(url, fallback, delayLoad).staticCast(); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 1c3f2114d6..f7971e78d6 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -70,11 +70,9 @@ public: void renderWireCube(float size); - void renderQuad(int x, int y, int width, int height) { - renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height)); - }; - + void renderQuad(int x, int y, int width, int height) { renderQuad(glm::vec2(x,y), glm::vec2(x + width, y + height)); } void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight); + void renderQuad(const glm::vec2& topLeft, const glm::vec2& bottomRight, const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); @@ -104,7 +102,7 @@ private: QHash _wireCubeVBOs; QHash _solidCubeVBOs; QHash _quad2DVBOs; - //QHash _quad2DTextureVBOs; + QHash _quad2DTextureVBOs; QHash _gridBuffers; diff --git a/libraries/render-utils/src/RenderUtil.cpp b/libraries/render-utils/src/RenderUtil.cpp index d70c972c87..140ced4c52 100644 --- a/libraries/render-utils/src/RenderUtil.cpp +++ b/libraries/render-utils/src/RenderUtil.cpp @@ -10,17 +10,16 @@ // #include + +#include +#include "GeometryCache.h" + #include "RenderUtil.h" void renderFullscreenQuad(float sMin, float sMax, float tMin, float tMax) { - glBegin(GL_QUADS); - glTexCoord2f(sMin, tMin); - glVertex2f(-1.0f, -1.0f); - glTexCoord2f(sMax, tMin); - glVertex2f(1.0f, -1.0f); - glTexCoord2f(sMax, tMax); - glVertex2f(1.0f, 1.0f); - glTexCoord2f(sMin, tMax); - glVertex2f(-1.0f, 1.0f); - glEnd(); + 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); } From 1f307e9667ae8c033e4d2dcec9605bc248d14c77 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 23 Dec 2014 09:50:38 -0800 Subject: [PATCH 04/23] more work on removing immediate mode GL_QUADS --- interface/src/ui/ApplicationOverlay.cpp | 49 +++---- .../src/ui/overlays/Rectangle3DOverlay.cpp | 12 +- interface/src/ui/overlays/Text3DOverlay.cpp | 9 +- .../src/RenderableTextEntityItem.cpp | 11 +- libraries/render-utils/src/GeometryCache.cpp | 138 ++++++++++++++++++ libraries/render-utils/src/GeometryCache.h | 28 ++++ 6 files changed, 195 insertions(+), 52 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index a34584b24c..079cb8c803 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -106,23 +106,14 @@ bool raySphereIntersect(const glm::vec3 &dir, const glm::vec3 &origin, float r, } void renderReticle(glm::quat orientation, float alpha) { - glm::vec3 topLeft = getPoint(reticleSize / 2.0f, -reticleSize / 2.0f); - 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); - glPushMatrix(); { glm::vec3 axis = glm::axis(orientation); glRotatef(glm::degrees(glm::angle(orientation)), axis.x, axis.y, axis.z); - - glBegin(GL_QUADS); { - glColor4f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2], alpha); - - glTexCoord2f(0.0f, 0.0f); glVertex3f(topLeft.x, topLeft.y, topLeft.z); - glTexCoord2f(1.0f, 0.0f); glVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z); - glTexCoord2f(1.0f, 1.0f); glVertex3f(bottomRight.x, bottomRight.y, bottomRight.z); - glTexCoord2f(0.0f, 1.0f); glVertex3f(topRight.x, topRight.y, topRight.z); - } glEnd(); + glm::vec3 topLeft = getPoint(reticleSize / 2.0f, -reticleSize / 2.0f); + glm::vec3 bottomRight = getPoint(-reticleSize / 2.0f, reticleSize / 2.0f); + glm::vec2 texCoordTopLeft(0.0f, 0.0f); + glm::vec2 texCoordBottomRight(1.0f, 1.0f); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); } glPopMatrix(); } @@ -371,15 +362,12 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as GLfloat x = -halfQuadWidth; GLfloat y = -halfQuadHeight; glDisable(GL_DEPTH_TEST); - - glBegin(GL_QUADS); - - glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + quadHeight, -distance); - glTexCoord2f(1.0f, 1.0f); glVertex3f(x + quadWidth, y + quadHeight, -distance); - glTexCoord2f(1.0f, 0.0f); glVertex3f(x + quadWidth, y, -distance); - glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, -distance); - - glEnd(); + + glm::vec3 topLeft(x, y + quadHeight, -distance); + glm::vec3 bottomRight(x + quadWidth, y, -distance); + glm::vec2 texCoordTopLeft(0.0f, 1.0f); + glm::vec2 texCoordBottomRight(1.0f, 0.0f); + DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { @@ -395,16 +383,13 @@ 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; - glBegin(GL_QUADS); - glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - - glTexCoord2d(0.0f, 0.0f); glVertex3f(x + mouseX, y + mouseY, -distance); - glTexCoord2d(1.0f, 0.0f); glVertex3f(x + mouseX + reticleSize, y + mouseY, -distance); - glTexCoord2d(1.0f, 1.0f); glVertex3f(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance); - glTexCoord2d(0.0f, 1.0f); glVertex3f(x + mouseX, y + mouseY - reticleSize, -distance); - - glEnd(); + + glm::vec3 reticleTopLeft(x + mouseX, y + mouseY, -distance); + glm::vec3 reticleBottomRight(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance); + glm::vec2 reticleTexCoordTopLeft(0.0f, 0.0f); + glm::vec2 reticleTexCoordBottomRight(1.0f, 1.0f); + DependencyManager::get()->renderQuad(reticleTopLeft, reticleBottomRight, reticleTexCoordTopLeft, reticleTexCoordBottomRight); glEnable(GL_DEPTH_TEST); diff --git a/interface/src/ui/overlays/Rectangle3DOverlay.cpp b/interface/src/ui/overlays/Rectangle3DOverlay.cpp index 8e8c17743d..c315723798 100644 --- a/interface/src/ui/overlays/Rectangle3DOverlay.cpp +++ b/interface/src/ui/overlays/Rectangle3DOverlay.cpp @@ -13,6 +13,7 @@ #include +#include #include #include @@ -66,14 +67,9 @@ void Rectangle3DOverlay::render(RenderArgs* args) { // for our overlay, is solid means we draw a solid "filled" rectangle otherwise we just draw a border line... if (getIsSolid()) { - glBegin(GL_QUADS); - - glVertex3f(-halfDimensions.x, 0.0f, -halfDimensions.y); - glVertex3f(halfDimensions.x, 0.0f, -halfDimensions.y); - glVertex3f(halfDimensions.x, 0.0f, halfDimensions.y); - glVertex3f(-halfDimensions.x, 0.0f, halfDimensions.y); - - glEnd(); + glm::vec3 topLeft(-halfDimensions.x, 0.0f, -halfDimensions.y); + glm::vec3 bottomRight(halfDimensions.x, 0.0f, halfDimensions.y); + DependencyManager::get()->renderQuad(topLeft, bottomRight); } else { if (getIsDashedLine()) { diff --git a/interface/src/ui/overlays/Text3DOverlay.cpp b/interface/src/ui/overlays/Text3DOverlay.cpp index 9b80d873f9..92f6350936 100644 --- a/interface/src/ui/overlays/Text3DOverlay.cpp +++ b/interface/src/ui/overlays/Text3DOverlay.cpp @@ -100,12 +100,9 @@ void Text3DOverlay::render(RenderArgs* args) { const float SLIGHTLY_BEHIND = -0.005f; - glBegin(GL_QUADS); - glVertex3f(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(-halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - glEnd(); + glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); + glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); + DependencyManager::get()->renderQuad(topLeft, bottomRight); const int FIXED_FONT_SCALING_RATIO = FIXED_FONT_POINT_SIZE * 40.0f; // this is a ratio determined through experimentation diff --git a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp index 24f4a71295..76431b55bc 100644 --- a/libraries/entities-renderer/src/RenderableTextEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableTextEntityItem.cpp @@ -12,6 +12,8 @@ #include #include + +#include #include #include @@ -51,12 +53,9 @@ void RenderableTextEntityItem::render(RenderArgs* args) { const float SLIGHTLY_BEHIND = -0.005f; - glBegin(GL_QUADS); - glVertex3f(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - glVertex3f(-halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); - glEnd(); + glm::vec3 topLeft(-halfDimensions.x, -halfDimensions.y, SLIGHTLY_BEHIND); + glm::vec3 bottomRight(halfDimensions.x, halfDimensions.y, SLIGHTLY_BEHIND); + DependencyManager::get()->renderQuad(topLeft, bottomRight); 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/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index f6ea9247ce..391543acfd 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -787,6 +787,144 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } +void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight) { + Vec3Pair key(topLeft, bottomRight); + VerticesIndices& vbo = _quad3DVBOs[key]; + const int FLOATS_PER_VERTEX = 3; + const int NUM_BYTES_PER_VERTEX = FLOATS_PER_VERTEX * sizeof(GLfloat); + const int vertices = 4; + const int indices = 4; + if (vbo.first == 0) { + 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++] = topLeft.x; + vertex[v++] = topLeft.y; + vertex[v++] = topLeft.z; + + vertex[v++] = bottomRight.x; + vertex[v++] = topLeft.y; + vertex[v++] = topLeft.z; + + vertex[v++] = bottomRight.x; + vertex[v++] = bottomRight.y; + vertex[v++] = bottomRight.z; + + vertex[v++] = topLeft.x; + vertex[v++] = bottomRight.y; + vertex[v++] = bottomRight.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; + + qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); + + } 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_QUADS, 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::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) { + + Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); + + VerticesIndices& vbo = _quad3DTextureVBOs[key]; + 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) { + 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; + + vertex[v++] = topLeft.x; + vertex[v++] = topLeft.y; + vertex[v++] = topLeft.z; + vertex[v++] = texCoordTopLeft.x; + vertex[v++] = texCoordTopLeft.y; + + vertex[v++] = bottomRight.x; + vertex[v++] = topLeft.y; + vertex[v++] = topLeft.z; + vertex[v++] = texCoordBottomRight.x; + vertex[v++] = texCoordTopLeft.y; + + vertex[v++] = bottomRight.x; + vertex[v++] = bottomRight.y; + vertex[v++] = bottomRight.z; + vertex[v++] = texCoordBottomRight.x; + vertex[v++] = texCoordBottomRight.y; + + vertex[v++] = topLeft.x; + vertex[v++] = bottomRight.y; + vertex[v++] = bottomRight.z; + vertex[v++] = texCoordTopLeft.x; + vertex[v++] = texCoordBottomRight.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; + + qDebug() << "new quad + texture VBO made -- _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + } else { + glBindBuffer(GL_ARRAY_BUFFER, vbo.first); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); + } + + 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 *)(3 * sizeof(float))); + + glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); +} QSharedPointer GeometryCache::getGeometry(const QUrl& url, const QUrl& fallback, bool delayLoad) { return getResource(url, fallback, delayLoad).staticCast(); } diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index f7971e78d6..aadbef77c5 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -34,6 +34,8 @@ class NetworkTexture; typedef QPair Vec2Pair; typedef QPair Vec2PairPair; +typedef QPair Vec3Pair; +typedef QPair Vec3PairVec2Pair; inline uint qHash(const glm::vec2& v, uint seed) { // multiply by prime numbers greater than the possible size @@ -53,6 +55,25 @@ 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 + + 5021 * v.second.x + 5023 * v.second.y + 5039 * v.second.z, 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 + + 5021 * v.first.second.x + 5023 * v.first.second.y + 5039 * v.first.second.z + + 5051 * v.second.first.x + 5059 * v.second.first.y + + 5077 * v.second.second.x + 5081 * v.second.second.y, seed); +} + /// Stores cached geometry. class GeometryCache : public ResourceCache { @@ -77,6 +98,11 @@ public: const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight); + + void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, + const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable /// \param delayLoad if true, don't load the geometry immediately; wait until load is first requested @@ -103,6 +129,8 @@ private: QHash _solidCubeVBOs; QHash _quad2DVBOs; QHash _quad2DTextureVBOs; + QHash _quad3DVBOs; + QHash _quad3DTextureVBOs; QHash _gridBuffers; From 0790bd77b71807320b6d2fb70e396cffa7d5416b Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Wed, 24 Dec 2014 11:14:50 -0800 Subject: [PATCH 05/23] almost completely eliminate immediate mode QUADS --- interface/src/ui/ApplicationOverlay.cpp | 45 +++++++++------- libraries/render-utils/src/GeometryCache.cpp | 56 +++++++++++++------- libraries/render-utils/src/GeometryCache.h | 9 +++- 3 files changed, 70 insertions(+), 40 deletions(-) diff --git a/interface/src/ui/ApplicationOverlay.cpp b/interface/src/ui/ApplicationOverlay.cpp index 079cb8c803..6c68e0add1 100644 --- a/interface/src/ui/ApplicationOverlay.cpp +++ b/interface/src/ui/ApplicationOverlay.cpp @@ -110,10 +110,13 @@ void renderReticle(glm::quat orientation, float alpha) { glm::vec3 axis = glm::axis(orientation); glRotatef(glm::degrees(glm::angle(orientation)), axis.x, axis.y, axis.z); glm::vec3 topLeft = getPoint(reticleSize / 2.0f, -reticleSize / 2.0f); + 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); - glm::vec2 texCoordTopLeft(0.0f, 0.0f); - glm::vec2 texCoordBottomRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + glColor4f(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)); } glPopMatrix(); } @@ -363,11 +366,12 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as GLfloat y = -halfQuadHeight; glDisable(GL_DEPTH_TEST); - glm::vec3 topLeft(x, y + quadHeight, -distance); - glm::vec3 bottomRight(x + quadWidth, y, -distance); - glm::vec2 texCoordTopLeft(0.0f, 1.0f); - glm::vec2 texCoordBottomRight(1.0f, 0.0f); - DependencyManager::get()->renderQuad(topLeft, bottomRight, texCoordTopLeft, texCoordBottomRight); + DependencyManager::get()->renderQuad(glm::vec3(x, y + quadHeight, -distance), + glm::vec3(x + quadWidth, y + quadHeight, -distance), + 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)); GLCanvas::SharedPointer glCanvas = DependencyManager::get(); if (_crosshairTexture == 0) { @@ -385,12 +389,13 @@ void ApplicationOverlay::displayOverlayTexture3DTV(Camera& whichCamera, float as glColor3f(RETICLE_COLOR[0], RETICLE_COLOR[1], RETICLE_COLOR[2]); - glm::vec3 reticleTopLeft(x + mouseX, y + mouseY, -distance); - glm::vec3 reticleBottomRight(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance); - glm::vec2 reticleTexCoordTopLeft(0.0f, 0.0f); - glm::vec2 reticleTexCoordBottomRight(1.0f, 1.0f); - DependencyManager::get()->renderQuad(reticleTopLeft, reticleBottomRight, reticleTexCoordTopLeft, reticleTexCoordBottomRight); - + DependencyManager::get()->renderQuad(glm::vec3(x + mouseX, y + mouseY, -distance), + glm::vec3(x + mouseX + reticleSize, y + mouseY, -distance), + glm::vec3(x + mouseX + reticleSize, y + mouseY - reticleSize, -distance), + 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)); + glEnable(GL_DEPTH_TEST); glPopMatrix(); @@ -736,13 +741,13 @@ void ApplicationOverlay::renderMagnifier(glm::vec2 magPos, float sizeMult, bool glEnable(GL_TEXTURE_2D); } glColor4f(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)); - glBegin(GL_QUADS); { - glTexCoord2f(magnifyULeft, magnifyVBottom); glVertex3f(bottomLeft.x, bottomLeft.y, bottomLeft.z); - glTexCoord2f(magnifyURight, magnifyVBottom); glVertex3f(bottomRight.x, bottomRight.y, bottomRight.z); - glTexCoord2f(magnifyURight, magnifyVTop); glVertex3f(topRight.x, topRight.y, topRight.z); - glTexCoord2f(magnifyULeft, magnifyVTop); glVertex3f(topLeft.x, topLeft.y, topLeft.z); - } glEnd(); } glPopMatrix(); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 391543acfd..e7d40c7627 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -699,7 +699,9 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); + #ifdef WANT_DEBUG + qDebug() << "new quad VBO made -- _quad2DVBOs.size():" << _quad2DVBOs.size(); + #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -767,7 +769,9 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); + #ifdef WANT_DEBUG + qDebug() << "new quad + texture VBO made -- _quad2DTextureVBOs.size():" << _quad2DTextureVBOs.size(); + #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); @@ -833,7 +837,9 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); + #ifdef WANT_DEBUG + qDebug() << "new quad VBO made -- _quad3DVBOs.size():" << _quad3DVBOs.size(); + #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); @@ -849,8 +855,20 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom } -void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight) { +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) { + + #ifdef WANT_DEBUG + qDebug() << "renderQuad() vec3 + texture VBO..."; + qDebug() << " topLeft:" << topLeft; + qDebug() << " bottomLeft:" << bottomLeft; + qDebug() << " bottomRight:" << bottomRight; + qDebug() << " topRight:" << topRight; + qDebug() << " texCoordTopLeft:" << texCoordTopLeft; + qDebug() << " texCoordBottomRight:" << texCoordBottomRight; + #endif //def WANT_DEBUG Vec3PairVec2Pair key(Vec3Pair(topLeft, bottomRight), Vec2Pair(texCoordTopLeft, texCoordBottomRight)); @@ -872,11 +890,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom vertex[v++] = texCoordTopLeft.x; vertex[v++] = texCoordTopLeft.y; - vertex[v++] = bottomRight.x; - vertex[v++] = topLeft.y; - vertex[v++] = topLeft.z; - vertex[v++] = texCoordBottomRight.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; @@ -884,11 +902,11 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom vertex[v++] = texCoordBottomRight.x; vertex[v++] = texCoordBottomRight.y; - vertex[v++] = topLeft.x; - vertex[v++] = bottomRight.y; - vertex[v++] = bottomRight.z; - vertex[v++] = texCoordTopLeft.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); @@ -905,8 +923,10 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices * NUM_BYTES_PER_INDEX, indexData, GL_STATIC_DRAW); delete[] indexData; - - qDebug() << "new quad + texture VBO made -- _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + + #ifdef WANT_DEBUG + qDebug() << " _quad3DTextureVBOs.size():" << _quad3DTextureVBOs.size(); + #endif } else { glBindBuffer(GL_ARRAY_BUFFER, vbo.first); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo.second); @@ -914,7 +934,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glVertexPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); + glVertexPointer(3, GL_FLOAT, NUM_BYTES_PER_VERTEX, 0); glTexCoordPointer(2, GL_FLOAT, NUM_BYTES_PER_VERTEX, (const void *)(3 * sizeof(float))); glDrawRangeElementsEXT(GL_QUADS, 0, vertices - 1, indices, GL_UNSIGNED_SHORT, 0); diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index aadbef77c5..9a76973f77 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -100,8 +100,13 @@ public: void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight); - void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, - const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + //void renderQuad(const glm::vec3& topLeft, const glm::vec3& bottomRight, + // const glm::vec2& texCoordTopLeft, const glm::vec2& texCoordBottomRight); + + 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); /// Loads geometry from the specified URL. /// \param fallback a fallback URL to load if the desired one is unavailable From 4586afc6c5dabe8f192f2b5ca9312330a0d08e9c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Mon, 29 Dec 2014 17:23:54 -0800 Subject: [PATCH 06/23] Fix for new version of cmake --- cmake/macros/IncludeDependencyIncludes.cmake | 11 +++++++---- cmake/macros/LinkHifiLibraries.cmake | 8 +++++++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmake/macros/IncludeDependencyIncludes.cmake b/cmake/macros/IncludeDependencyIncludes.cmake index a375404164..cc2e5ca121 100644 --- a/cmake/macros/IncludeDependencyIncludes.cmake +++ b/cmake/macros/IncludeDependencyIncludes.cmake @@ -15,8 +15,11 @@ macro(INCLUDE_DEPENDENCY_INCLUDES) # include those in our own target include_directories(SYSTEM ${${TARGET_NAME}_DEPENDENCY_INCLUDES}) - endif () - - # set the property on this target so it can be retreived by targets linking to us - set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") + + list(LENGTH ${TARGET_NAME}_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) + if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) + # set the property on this target so it can be retreived by targets linking to us + set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") + endif () + endif() endmacro(INCLUDE_DEPENDENCY_INCLUDES) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index 646b680f27..7d3aff0e78 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -27,7 +27,13 @@ macro(LINK_HIFI_LIBRARIES) # ask the library what its include dependencies are and link them get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) + + if(LINKED_TARGET_DEPENDENCY_INCLUDES) + list(LENGTH LINKED_TARGET_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) + if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) + list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) + endif() + endif() endforeach() endmacro(LINK_HIFI_LIBRARIES) \ No newline at end of file From a0ec2ddfe96b845b467ccb47beb18ee082d71542 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Mon, 29 Dec 2014 21:07:04 -0800 Subject: [PATCH 07/23] clamp frame index between 0 and 100,000 --- libraries/animation/src/AnimationLoop.cpp | 9 +++++---- libraries/animation/src/AnimationLoop.h | 8 +++++--- libraries/entities/src/ModelEntityItem.cpp | 15 +++++++++++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/libraries/animation/src/AnimationLoop.cpp b/libraries/animation/src/AnimationLoop.cpp index 75a3cdd338..e60df1eaf9 100644 --- a/libraries/animation/src/AnimationLoop.cpp +++ b/libraries/animation/src/AnimationLoop.cpp @@ -12,16 +12,18 @@ #include "AnimationCache.h" #include "AnimationLoop.h" +const float AnimationLoop::MAXIMUM_POSSIBLE_FRAME = 100000.0f; + AnimationLoop::AnimationLoop() : _fps(30.0f), _loop(false), _hold(false), _startAutomatically(false), _firstFrame(0.0f), - _lastFrame(FLT_MAX), + _lastFrame(MAXIMUM_POSSIBLE_FRAME), _running(false), _frameIndex(0.0f), - _maxFrameIndexHint(FLT_MAX) + _maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME) { } @@ -53,10 +55,9 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati void AnimationLoop::simulate(float deltaTime) { _frameIndex += deltaTime * _fps; - // If we knew the number of frames from the animation, we'd consider using it here // animationGeometry.animationFrames.size() - float maxFrame = _maxFrameIndexHint; + float maxFrame = _maxFrameIndexHint; float endFrameIndex = qMin(_lastFrame, maxFrame - (_loop ? 0.0f : 1.0f)); float startFrameIndex = qMin(_firstFrame, endFrameIndex); if ((!_loop && (_frameIndex < startFrameIndex || _frameIndex > endFrameIndex)) || startFrameIndex == endFrameIndex) { diff --git a/libraries/animation/src/AnimationLoop.h b/libraries/animation/src/AnimationLoop.h index aff2cd86ee..d4537c4656 100644 --- a/libraries/animation/src/AnimationLoop.h +++ b/libraries/animation/src/AnimationLoop.h @@ -16,6 +16,8 @@ class AnimationDetails; class AnimationLoop { public: + static const float MAXIMUM_POSSIBLE_FRAME; + AnimationLoop(); AnimationLoop(const AnimationDetails& animationDetails); AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame, @@ -33,10 +35,10 @@ public: void setStartAutomatically(bool startAutomatically); bool getStartAutomatically() const { return _startAutomatically; } - void setFirstFrame(float firstFrame) { _firstFrame = firstFrame; } + void setFirstFrame(float firstFrame) { _firstFrame = glm::clamp(firstFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getFirstFrame() const { return _firstFrame; } - void setLastFrame(float lastFrame) { _lastFrame = lastFrame; } + void setLastFrame(float lastFrame) { _lastFrame = glm::clamp(lastFrame, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getLastFrame() const { return _lastFrame; } void setRunning(bool running); @@ -45,7 +47,7 @@ public: void setFrameIndex(float frameIndex) { _frameIndex = glm::clamp(frameIndex, _firstFrame, _lastFrame); } float getFrameIndex() const { return _frameIndex; } - void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = value; } + void setMaxFrameIndexHint(float value) { _maxFrameIndexHint = glm::clamp(value, 0.0f, MAXIMUM_POSSIBLE_FRAME); } float getMaxFrameIndexHint() const { return _maxFrameIndexHint; } void start() { setRunning(true); } diff --git a/libraries/entities/src/ModelEntityItem.cpp b/libraries/entities/src/ModelEntityItem.cpp index 28dcbc44ca..0989068f2a 100644 --- a/libraries/entities/src/ModelEntityItem.cpp +++ b/libraries/entities/src/ModelEntityItem.cpp @@ -402,11 +402,15 @@ void ModelEntityItem::setAnimationURL(const QString& url) { } void ModelEntityItem::setAnimationFrameIndex(float value) { +#ifdef WANT_DEBUG if (isAnimatingSomething()) { qDebug() << "ModelEntityItem::setAnimationFrameIndex()"; qDebug() << " value:" << value; qDebug() << " was:" << _animationLoop.getFrameIndex(); + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); } +#endif _animationLoop.setFrameIndex(value); } @@ -425,6 +429,17 @@ void ModelEntityItem::setAnimationSettings(const QString& value) { if (settingsMap.contains("frameIndex")) { float frameIndex = settingsMap["frameIndex"].toFloat(); +#ifdef WANT_DEBUG + if (isAnimatingSomething()) { + qDebug() << "ModelEntityItem::setAnimationSettings() calling setAnimationFrameIndex()..."; + qDebug() << " model URL:" << getModelURL(); + qDebug() << " animation URL:" << getAnimationURL(); + qDebug() << " settings:" << value; + qDebug() << " settingsMap[frameIndex]:" << settingsMap["frameIndex"]; + qDebug(" frameIndex: %20.5f", frameIndex); + } +#endif + setAnimationFrameIndex(frameIndex); } From cb951763fd823c67ba1187655b2772503439f417 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 10:29:18 -0800 Subject: [PATCH 08/23] CR feedback spacing --- 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 e7d40c7627..d71aa0b5cf 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -730,7 +730,7 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom 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 }; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; int v = 0; vertex[v++] = topLeft.x; @@ -802,7 +802,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom int vertexPoints = vertices * FLOATS_PER_VERTEX; GLfloat* vertexData = new GLfloat[vertexPoints]; // only vertices GLfloat* vertex = vertexData; - static GLubyte cannonicalIndices[indices] = { 0, 1, 2, 3 }; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; int v = 0; vertex[v++] = topLeft.x; @@ -881,7 +881,7 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom 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 }; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; int v = 0; vertex[v++] = topLeft.x; From 53a7d83f352176da68d925cfaf45edcb1e4d4a51 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Tue, 30 Dec 2014 10:33:22 -0800 Subject: [PATCH 09/23] CR feedback spacing --- libraries/render-utils/src/GeometryCache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index d71aa0b5cf..a1cadf2c20 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -672,7 +672,7 @@ void GeometryCache::renderQuad(const glm::vec2& topLeft, const glm::vec2& bottom 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 }; + static GLubyte cannonicalIndices[indices] = {0, 1, 2, 3}; vertex[0] = topLeft.x; vertex[1] = topLeft.y; From 729034dd947fd5c4337f80f2030a5aaee54eabd3 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 30 Dec 2014 11:13:00 -0800 Subject: [PATCH 10/23] Removed unnecessary list(LENGTH ...) --- cmake/macros/IncludeDependencyIncludes.cmake | 7 ++----- cmake/macros/LinkHifiLibraries.cmake | 5 +---- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/cmake/macros/IncludeDependencyIncludes.cmake b/cmake/macros/IncludeDependencyIncludes.cmake index cc2e5ca121..4474bdc53a 100644 --- a/cmake/macros/IncludeDependencyIncludes.cmake +++ b/cmake/macros/IncludeDependencyIncludes.cmake @@ -16,10 +16,7 @@ macro(INCLUDE_DEPENDENCY_INCLUDES) # include those in our own target include_directories(SYSTEM ${${TARGET_NAME}_DEPENDENCY_INCLUDES}) - list(LENGTH ${TARGET_NAME}_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) - if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) - # set the property on this target so it can be retreived by targets linking to us - set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") - endif () + # set the property on this target so it can be retreived by targets linking to us + set_target_properties(${TARGET_NAME} PROPERTIES DEPENDENCY_INCLUDES "${${TARGET_NAME}_DEPENDENCY_INCLUDES}") endif() endmacro(INCLUDE_DEPENDENCY_INCLUDES) \ No newline at end of file diff --git a/cmake/macros/LinkHifiLibraries.cmake b/cmake/macros/LinkHifiLibraries.cmake index 7d3aff0e78..ef0c8321c6 100644 --- a/cmake/macros/LinkHifiLibraries.cmake +++ b/cmake/macros/LinkHifiLibraries.cmake @@ -29,10 +29,7 @@ macro(LINK_HIFI_LIBRARIES) get_target_property(LINKED_TARGET_DEPENDENCY_INCLUDES ${HIFI_LIBRARY} DEPENDENCY_INCLUDES) if(LINKED_TARGET_DEPENDENCY_INCLUDES) - list(LENGTH LINKED_TARGET_DEPENDENCY_INCLUDES NUM_DEPENDENCY_INCLUDES) - if(NUM_DEPENDENCY_INCLUDES STRGREATER 0) - list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) - endif() + list(APPEND ${TARGET_NAME}_DEPENDENCY_INCLUDES ${LINKED_TARGET_DEPENDENCY_INCLUDES}) endif() endforeach() From a474243f08e8b866fa0a9273ee94b406031354cf Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:21:50 -0800 Subject: [PATCH 11/23] Update to ignore mouseRelease events if mousePress event handles by tool --- examples/editEntities.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index 0b5c089c07..632fed088c 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -494,8 +494,10 @@ var mouseHasMovedSincePress = false; function mousePressEvent(event) { mouseHasMovedSincePress = false; + mouseCapturedByTool = false; - if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event)) { + if (toolBar.mousePressEvent(event) || progressDialog.mousePressEvent(event) || gridTool.mousePressEvent(event)) { + mouseCapturedByTool = true; return; } if (isActive) { @@ -519,6 +521,7 @@ function mousePressEvent(event) { } var highlightedEntityID = { isKnownID: false }; +var mouseCapturedByTool = false; function mouseMoveEvent(event) { mouseHasMovedSincePress = true; @@ -563,6 +566,9 @@ function mouseReleaseEvent(event) { if (isActive && selectionManager.hasSelection()) { tooltip.show(false); } + if (mouseCapturedByTool) { + return; + } cameraManager.mouseReleaseEvent(event); From 9a6bce3767a553c3e35f0dfcd7862b84b0b3da9d Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:26:44 -0800 Subject: [PATCH 12/23] Add getters/setters to Grid --- examples/libraries/gridTool.js | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 7d98befec8..f9fc07f4dd 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -27,9 +27,6 @@ Grid = function(opts) { majorGridEvery: 2, }); - that.getMinorIncrement = function() { return minorGridSpacing; }; - that.getMajorIncrement = function() { return minorGridSpacing * majorGridEvery; }; - that.visible = false; that.enabled = false; @@ -37,13 +34,39 @@ Grid = function(opts) { return origin; } + that.getMinorIncrement = function() { return minorGridWidth; }; + that.getMajorIncrement = function() { return minorGridWidth * majorGridEvery; }; + + that.getMinorGridWidth = function() { return minorGridWidth; }; + that.setMinorGridWidth = function(value) { + minorGridWidth = value; + updateGrid(); + }; + + that.getMajorGridEvery = function() { return majorGridEvery; }; + that.setMajorGridEvery = function(value) { + majorGridEvery = value; + updateGrid(); + }; + + that.getColorIndex = function() { return colorIndex; }; + that.setColorIndex = function(value) { + colorIndex = value; + updateGrid(); + }; + that.getSnapToGrid = function() { return snapToGrid; }; + that.setSnapToGrid = function(value) { + snapToGrid = value; + that.emitUpdate(); + }; that.setEnabled = function(enabled) { that.enabled = enabled; updateGrid(); } + that.getVisible = function() { return that.visible; }; that.setVisible = function(visible, noUpdate) { that.visible = visible; updateGrid(); From fdba41a69dd5871556c2ac514a7b13dec4c88e9c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:27:16 -0800 Subject: [PATCH 13/23] Add grid colors to Grid --- examples/libraries/gridTool.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index f9fc07f4dd..242dbb0d10 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -1,8 +1,14 @@ Grid = function(opts) { var that = {}; - var color = { red: 100, green: 152, blue: 203 }; - var gridColor = { red: 100, green: 152, blue: 203 }; + var colors = [ + { red: 102, green: 180, blue: 126 }, + { red: 83, green: 210, blue: 83 }, + { red: 235, green: 173, blue: 0 }, + { red: 210, green: 115, blue: 0 }, + { red: 48, green: 116, blue: 119 }, + ]; + var colorIndex = 0; var gridAlpha = 1.0; var origin = { x: 0, y: 0, z: 0 }; var majorGridEvery = 5; @@ -20,7 +26,7 @@ Grid = function(opts) { var gridOverlay = Overlays.addOverlay("grid", { position: { x: 0 , y: 0, z: 0 }, visible: true, - color: { red: 0, green: 0, blue: 128 }, + color: colors[0], alpha: 1.0, rotation: Quat.fromPitchYawRollDegrees(90, 0, 0), minorGridWidth: 0.1, @@ -149,7 +155,6 @@ Grid = function(opts) { gridSize: halfSize, visible: that.visible, snapToGrid: snapToGrid, - gridColor: gridColor, }); } }; @@ -175,8 +180,8 @@ Grid = function(opts) { majorGridEvery = data.majorGridEvery; } - if (data.gridColor) { - gridColor = data.gridColor; + if (data.colorIndex !== undefined) { + colorIndex = data.colorIndex; } if (data.gridSize) { @@ -196,8 +201,8 @@ Grid = function(opts) { visible: that.visible && that.enabled, minorGridWidth: minorGridSpacing, majorGridEvery: majorGridEvery, - color: gridColor, - alpha: gridAlpha, + color: colors[colorIndex], + alpha: gridAlpha, }); that.emitUpdate(); From fbd189bde301f29305c771bcc76323b254d06ae0 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:28:10 -0800 Subject: [PATCH 14/23] Rename minorGridSpacing to minorGridWidth --- examples/libraries/gridTool.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 242dbb0d10..82ac6bbba4 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -12,14 +12,13 @@ Grid = function(opts) { var gridAlpha = 1.0; var origin = { x: 0, y: 0, z: 0 }; var majorGridEvery = 5; - var minorGridSpacing = 0.2; + var minorGridWidth = 0.2; var halfSize = 40; var yOffset = 0.001; var worldSize = 16384; var minorGridWidth = 0.5; - var majorGridWidth = 1.5; var snapToGrid = false; @@ -107,7 +106,7 @@ Grid = function(opts) { dimensions = { x: 0, y: 0, z: 0 }; } - var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing; + var spacing = majorOnly ? (minorGridWidth * majorGridEvery) : minorGridWidth; position = Vec3.subtract(position, origin); @@ -123,7 +122,7 @@ Grid = function(opts) { return delta; } - var spacing = majorOnly ? (minorGridSpacing * majorGridEvery) : minorGridSpacing; + var spacing = majorOnly ? (minorGridWidth * majorGridEvery) : minorGridWidth; var snappedDelta = { x: Math.round(delta.x / spacing) * spacing, @@ -150,7 +149,7 @@ Grid = function(opts) { if (that.onUpdate) { that.onUpdate({ origin: origin, - minorGridSpacing: minorGridSpacing, + minorGridWidth: minorGridWidth, majorGridEvery: majorGridEvery, gridSize: halfSize, visible: that.visible, @@ -172,8 +171,8 @@ Grid = function(opts) { that.setPosition(pos, true); } - if (data.minorGridSpacing) { - minorGridSpacing = data.minorGridSpacing; + if (data.minorGridWidth) { + minorGridWidth = data.minorGridWidth; } if (data.majorGridEvery) { @@ -199,7 +198,7 @@ Grid = function(opts) { Overlays.editOverlay(gridOverlay, { position: { x: origin.y, y: origin.y, z: -origin.y }, visible: that.visible && that.enabled, - minorGridWidth: minorGridSpacing, + minorGridWidth: minorGridWidth, majorGridEvery: majorGridEvery, color: colors[colorIndex], alpha: gridAlpha, From 552a421f24ed8b856e8868ce3e2368c8135b552a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:31:29 -0800 Subject: [PATCH 15/23] Update grid tool to be an overlay --- examples/libraries/gridTool.js | 286 +++++++++++++++++++++++++++++---- 1 file changed, 256 insertions(+), 30 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 82ac6bbba4..95c4ae19f3 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -226,46 +226,272 @@ 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 url = Script.resolvePath('html/gridControls.html'); - var webView = new WebWindow('Grid', url, 200, 280); + var uiOverlays = {}; + var allOverlays = []; - horizontalGrid.addListener(function(data) { - webView.eventBridge.emitScriptEvent(JSON.stringify(data)); - selectionDisplay.updateHandles(); - }); + function addUIOverlay(key, overlay, x, y, width, height) { + uiOverlays[key] = { + overlay: overlay, + x: x, + y: y, + width: width, + height: height, + }; + allOverlays.push(overlay); + } - 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); - } - } else if (data.type == "action") { - var action = data.action; - if (action == "moveToAvatar") { - grid.setPosition(MyAvatar.position); - } else if (action == "moveToSelection") { - var newPosition = selectionManager.worldPosition; - newPosition = Vec3.subtract(newPosition, { x: 0, y: selectionManager.worldDimensions.y * 0.5, z: 0 }); - grid.setPosition(newPosition); - } + var lastKnownWindowWidth = null; + function repositionUI() { + if (lastKnownWindowWidth == Window.innerWidth) { + return; } - }); - that.addListener = function(callback) { - listeners.push(callback); + 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, + } + }); + } + + 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) { - webView.setVisible(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) { + horizontalGrid.setPosition(MyAvatar.position); + } else if (overlay == uiOverlays.moveToSelection.overlay) { + 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 }); + } + } + } + + // Clicking anywhere within the toolbar will "consume" this press event + return true; + } + + return false; + }; + + that.mouseReleaseEvent = function(event) { + }; + + 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(); + }); + + updateOverlays(); + repositionUI(); + return that; }; From a0cb40597b416eba0294141e3cb4834e7ef9afd6 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:31:47 -0800 Subject: [PATCH 16/23] Remove gridControls.html --- examples/html/gridControls.html | 167 -------------------------------- 1 file changed, 167 deletions(-) delete mode 100644 examples/html/gridControls.html diff --git a/examples/html/gridControls.html b/examples/html/gridControls.html deleted file mode 100644 index 06090da423..0000000000 --- a/examples/html/gridControls.html +++ /dev/null @@ -1,167 +0,0 @@ - - - - - - -
- -
- -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - - - -
- -
- - -
- -
- - - -
-
- - - -
-
- - From 16bf4e87e624326a982557e6611b39978075d3c7 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 11:34:59 -0800 Subject: [PATCH 17/23] Remove unused function --- examples/libraries/gridTool.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 95c4ae19f3..79ec70b13f 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -475,9 +475,6 @@ GridTool = function(opts) { return false; }; - that.mouseReleaseEvent = function(event) { - }; - Script.scriptEnding.connect(function() { for (var i = 0; i < allOverlays.length; i++) { Overlays.deleteOverlay(allOverlays[i]); From 1da253d39f72facfd23717b87e1e20183ce4b05a Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 12:13:40 -0800 Subject: [PATCH 18/23] Remove duplicate minorGridWidth variable --- examples/libraries/gridTool.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index 79ec70b13f..e222ff3adb 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -18,8 +18,6 @@ Grid = function(opts) { var worldSize = 16384; - var minorGridWidth = 0.5; - var snapToGrid = false; var gridOverlay = Overlays.addOverlay("grid", { From c9b3b5ff7d523b7b26b6b4aab6c16eb09e4c165d Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Dec 2014 12:30:38 -0800 Subject: [PATCH 19/23] Scale back on first dropped packet, use Qt send/receive buffer size options rather than setsockopt/getsockopt. --- .../metavoxels/src/DatagramSequencer.cpp | 2 +- libraries/networking/src/LimitedNodeList.cpp | 33 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/libraries/metavoxels/src/DatagramSequencer.cpp b/libraries/metavoxels/src/DatagramSequencer.cpp index 65d548ba1c..e236ffd217 100644 --- a/libraries/metavoxels/src/DatagramSequencer.cpp +++ b/libraries/metavoxels/src/DatagramSequencer.cpp @@ -353,7 +353,7 @@ void DatagramSequencer::sendRecordLost(const SendRecord& record) { if (_packetDropCount == 0 || record.packetNumber == _lastPacketDropped + 1) { _packetDropCount++; _lastPacketDropped = record.packetNumber; - const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 3; + const int CONSECUTIVE_DROPS_BEFORE_REDUCTION = 1; if (_packetDropCount >= CONSECUTIVE_DROPS_BEFORE_REDUCTION && record.packetNumber >= _packetRateDecreasePacketNumber) { _packetsPerGroup = qMax(_packetsPerGroup * 0.5f, 1.0f); _slowStartThreshold = _packetsPerGroup; diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index 5e13f6bbc9..b0c2defd9b 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -147,28 +147,21 @@ QUdpSocket& LimitedNodeList::getDTLSSocket() { } void LimitedNodeList::changeSocketBufferSizes(int numBytes) { - // change the socket send buffer size to be 1MB - int oldBufferSize = 0; - -#ifdef Q_OS_WIN - int sizeOfInt = sizeof(oldBufferSize); -#else - unsigned int sizeOfInt = sizeof(oldBufferSize); -#endif - for (int i = 0; i < 2; i++) { - int bufferOpt = (i == 0) ? SO_SNDBUF : SO_RCVBUF; - - getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&oldBufferSize), &sizeOfInt); - - setsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&numBytes), - sizeof(numBytes)); - - QString bufferTypeString = (i == 0) ? "send" : "receive"; - + QAbstractSocket::SocketOption bufferOpt; + QString bufferTypeString; + if (i == 0) { + bufferOpt = QAbstractSocket::SendBufferSizeSocketOption; + bufferTypeString = "send"; + + } else { + bufferOpt = QAbstractSocket::ReceiveBufferSizeSocketOption; + bufferTypeString = "receive"; + } + int oldBufferSize = _nodeSocket.socketOption(bufferOpt).toInt(); if (oldBufferSize < numBytes) { - int newBufferSize = 0; - getsockopt(_nodeSocket.socketDescriptor(), SOL_SOCKET, bufferOpt, reinterpret_cast(&newBufferSize), &sizeOfInt); + _nodeSocket.setSocketOption(bufferOpt, numBytes); + int newBufferSize = _nodeSocket.socketOption(bufferOpt).toInt(); qDebug() << "Changed socket" << bufferTypeString << "buffer size from" << oldBufferSize << "to" << newBufferSize << "bytes"; From e752edc44ae42d6501b7c35c19a95d9cfe9adb09 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 30 Dec 2014 12:35:00 -0800 Subject: [PATCH 20/23] Moving the shaders used in Model.cpp from resources folder into the built-in executable --- .../resources/shaders/model_lightmap.frag | 37 ---- .../resources/shaders/model_lightmap.vert | 40 ---- .../shaders/model_lightmap_normal_map.frag | 50 ----- .../shaders/model_lightmap_normal_map.vert | 46 ----- .../model_lightmap_normal_specular_map.frag | 54 ------ .../shaders/model_lightmap_specular_map.frag | 40 ---- .../resources/shaders/model_normal_map.frag | 43 ----- .../resources/shaders/model_normal_map.vert | 40 ---- .../shaders/model_normal_specular_map.frag | 47 ----- interface/resources/shaders/model_shadow.frag | 17 -- interface/resources/shaders/model_shadow.vert | 17 -- .../resources/shaders/model_specular_map.frag | 33 ---- .../resources/shaders/model_translucent.frag | 20 -- interface/resources/shaders/skin_model.vert | 46 ----- .../shaders/skin_model_normal_map.vert | 54 ------ .../resources/shaders/skin_model_shadow.vert | 30 --- libraries/render-utils/src/Model.cpp | 177 ++++++++---------- 17 files changed, 79 insertions(+), 712 deletions(-) delete mode 100644 interface/resources/shaders/model_lightmap.frag delete mode 100644 interface/resources/shaders/model_lightmap.vert delete mode 100644 interface/resources/shaders/model_lightmap_normal_map.frag delete mode 100644 interface/resources/shaders/model_lightmap_normal_map.vert delete mode 100644 interface/resources/shaders/model_lightmap_normal_specular_map.frag delete mode 100644 interface/resources/shaders/model_lightmap_specular_map.frag delete mode 100644 interface/resources/shaders/model_normal_map.frag delete mode 100644 interface/resources/shaders/model_normal_map.vert delete mode 100644 interface/resources/shaders/model_normal_specular_map.frag delete mode 100644 interface/resources/shaders/model_shadow.frag delete mode 100644 interface/resources/shaders/model_shadow.vert delete mode 100644 interface/resources/shaders/model_specular_map.frag delete mode 100644 interface/resources/shaders/model_translucent.frag delete mode 100644 interface/resources/shaders/skin_model.vert delete mode 100644 interface/resources/shaders/skin_model_normal_map.vert delete mode 100644 interface/resources/shaders/skin_model_shadow.vert diff --git a/interface/resources/shaders/model_lightmap.frag b/interface/resources/shaders/model_lightmap.frag deleted file mode 100644 index 7c352b877e..0000000000 --- a/interface/resources/shaders/model_lightmap.frag +++ /dev/null @@ -1,37 +0,0 @@ -#version 120 - -// -// model_lightmap.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -void main(void) { - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); - gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_lightmap.vert b/interface/resources/shaders/model_lightmap.vert deleted file mode 100644 index ff1b07e503..0000000000 --- a/interface/resources/shaders/model_lightmap.vert +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model_lightmap.vert -// vertex shader -// -// Created by Sam Gateau on 11/21/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -attribute vec2 texcoord1; - -// the interpolated normal -varying vec4 normal; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -void main(void) { - // transform and store the normal for interpolation - normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; - - // use standard pipeline transform - gl_Position = ftransform(); -} - diff --git a/interface/resources/shaders/model_lightmap_normal_map.frag b/interface/resources/shaders/model_lightmap_normal_map.frag deleted file mode 100644 index 475126eb0c..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_map.frag +++ /dev/null @@ -1,50 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -varying vec2 interpolatedTexcoord1; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_lightmap_normal_map.vert b/interface/resources/shaders/model_lightmap_normal_map.vert deleted file mode 100644 index 4faf5688cf..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_map.vert +++ /dev/null @@ -1,46 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_map.vert -// vertex shader -// -// Created by Sam Gateau on 11/21/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -attribute vec2 texcoord1; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -// the interpolated texcoord1 -varying vec2 interpolatedTexcoord1; - -void main(void) { - // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; - - // use standard pipeline transform - gl_Position = ftransform(); -} diff --git a/interface/resources/shaders/model_lightmap_normal_specular_map.frag b/interface/resources/shaders/model_lightmap_normal_specular_map.frag deleted file mode 100644 index 4d0d29ed71..0000000000 --- a/interface/resources/shaders/model_lightmap_normal_specular_map.frag +++ /dev/null @@ -1,54 +0,0 @@ -#version 120 - -// -// model_lightmap_normal_specular_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the normal map texture -uniform sampler2D normalMap; - -// the specular map texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -varying vec2 interpolatedTexcoord1; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, - gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_lightmap_specular_map.frag b/interface/resources/shaders/model_lightmap_specular_map.frag deleted file mode 100644 index c616764cae..0000000000 --- a/interface/resources/shaders/model_lightmap_specular_map.frag +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model_lightmap_specular_map.frag -// fragment shader -// -// Created by Samuel Gateau on 11/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the emissive map texture and parameters -uniform sampler2D emissiveMap; -uniform vec2 emissiveParams; - -// the specular texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -varying vec2 interpolatedTexcoord1; - -void main(void) { - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, - gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_normal_map.frag b/interface/resources/shaders/model_normal_map.frag deleted file mode 100644 index f5a1047b2b..0000000000 --- a/interface/resources/shaders/model_normal_map.frag +++ /dev/null @@ -1,43 +0,0 @@ -#version 120 - -// -// model_normal_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 10/29/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_normal_map.vert b/interface/resources/shaders/model_normal_map.vert deleted file mode 100644 index 3d91a75c63..0000000000 --- a/interface/resources/shaders/model_normal_map.vert +++ /dev/null @@ -1,40 +0,0 @@ -#version 120 - -// -// model.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/14/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; - -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // transform and store the normal and tangent for interpolation - interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); - interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); - - // pass along the diffuse color - gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - // use standard pipeline transform - gl_Position = ftransform(); -} diff --git a/interface/resources/shaders/model_normal_specular_map.frag b/interface/resources/shaders/model_normal_specular_map.frag deleted file mode 100644 index 08321c0017..0000000000 --- a/interface/resources/shaders/model_normal_specular_map.frag +++ /dev/null @@ -1,47 +0,0 @@ -#version 120 - -// -// model_normal_specular_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 5/6/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the normal map texture -uniform sampler2D normalMap; - -// the specular map texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - // compute the view normal from the various bits - vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); - vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); - vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); - vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); - vec4 viewNormal = vec4(normalizedTangent * localNormal.x + - normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); - - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, - gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_shadow.frag b/interface/resources/shaders/model_shadow.frag deleted file mode 100644 index 567899fd82..0000000000 --- a/interface/resources/shaders/model_shadow.frag +++ /dev/null @@ -1,17 +0,0 @@ -#version 120 - -// -// model_shadow.frag -// fragment shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -void main(void) { - // fixed color for now (we may eventually want to use texture alpha) - gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0); -} diff --git a/interface/resources/shaders/model_shadow.vert b/interface/resources/shaders/model_shadow.vert deleted file mode 100644 index a18f5fcd5d..0000000000 --- a/interface/resources/shaders/model_shadow.vert +++ /dev/null @@ -1,17 +0,0 @@ -#version 120 - -// -// model_shadow.vert -// vertex shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -void main(void) { - // just use standard pipeline transform - gl_Position = ftransform(); -} diff --git a/interface/resources/shaders/model_specular_map.frag b/interface/resources/shaders/model_specular_map.frag deleted file mode 100644 index bcf658dc15..0000000000 --- a/interface/resources/shaders/model_specular_map.frag +++ /dev/null @@ -1,33 +0,0 @@ -#version 120 - -// -// model_specular_map.frag -// fragment shader -// -// Created by Andrzej Kapolka on 5/6/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -// the specular texture -uniform sampler2D specularMap; - -// the alpha threshold -uniform float alphaThreshold; - -// the interpolated normal -varying vec4 normal; - -void main(void) { - // set the diffuse, normal, specular data - vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); - gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); - gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); - gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, - gl_FrontMaterial.shininess / 128.0); -} diff --git a/interface/resources/shaders/model_translucent.frag b/interface/resources/shaders/model_translucent.frag deleted file mode 100644 index dbb640d3b1..0000000000 --- a/interface/resources/shaders/model_translucent.frag +++ /dev/null @@ -1,20 +0,0 @@ -#version 120 - -// -// model_translucent.frag -// fragment shader -// -// Created by Andrzej Kapolka on 9/19/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -// the diffuse texture -uniform sampler2D diffuseMap; - -void main(void) { - // set the diffuse data - gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st); -} diff --git a/interface/resources/shaders/skin_model.vert b/interface/resources/shaders/skin_model.vert deleted file mode 100644 index fd4dea51bb..0000000000 --- a/interface/resources/shaders/skin_model.vert +++ /dev/null @@ -1,46 +0,0 @@ -#version 120 - -// -// skin_model.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/14/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -// the interpolated normal -varying vec4 normal; - -void main(void) { - vec4 position = vec4(0.0, 0.0, 0.0, 0.0); - normal = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - position += clusterMatrix * gl_Vertex * clusterWeight; - normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; - } - - normal = normalize(gl_ModelViewMatrix * normal); - - // pass along the diffuse color - gl_FrontColor = gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - gl_Position = gl_ModelViewProjectionMatrix * position; -} diff --git a/interface/resources/shaders/skin_model_normal_map.vert b/interface/resources/shaders/skin_model_normal_map.vert deleted file mode 100644 index 5814dfc584..0000000000 --- a/interface/resources/shaders/skin_model_normal_map.vert +++ /dev/null @@ -1,54 +0,0 @@ -#version 120 - -// -// skin_model_normal_map.vert -// vertex shader -// -// Created by Andrzej Kapolka on 10/29/13. -// Copyright 2013 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_TEXCOORDS = 2; -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; -uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; - -// the tangent vector -attribute vec3 tangent; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -// the interpolated normal -varying vec4 interpolatedNormal; - -// the interpolated tangent -varying vec4 interpolatedTangent; - -void main(void) { - vec4 interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0); - interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); - interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - interpolatedPosition += clusterMatrix * gl_Vertex * clusterWeight; - interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; - interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight; - } - interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; - interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; - - // pass along the diffuse color - gl_FrontColor = gl_FrontMaterial.diffuse; - - // and the texture coordinates - gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); - - gl_Position = gl_ModelViewProjectionMatrix * interpolatedPosition; -} diff --git a/interface/resources/shaders/skin_model_shadow.vert b/interface/resources/shaders/skin_model_shadow.vert deleted file mode 100644 index 6d9d5ebbf5..0000000000 --- a/interface/resources/shaders/skin_model_shadow.vert +++ /dev/null @@ -1,30 +0,0 @@ -#version 120 - -// -// skin_model_shadow.vert -// vertex shader -// -// Created by Andrzej Kapolka on 3/24/14. -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -const int MAX_CLUSTERS = 128; -const int INDICES_PER_VERTEX = 4; - -uniform mat4 clusterMatrices[MAX_CLUSTERS]; - -attribute vec4 clusterIndices; -attribute vec4 clusterWeights; - -void main(void) { - vec4 position = vec4(0.0, 0.0, 0.0, 0.0); - for (int i = 0; i < INDICES_PER_VERTEX; i++) { - mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; - float clusterWeight = clusterWeights[i]; - position += clusterMatrix * gl_Vertex * clusterWeight; - } - gl_Position = gl_ModelViewProjectionMatrix * position; -} diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index 680d193aa3..ce121f616c 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -36,7 +36,25 @@ #include "Model.h" #include "model_vert.h" +#include "model_shadow_vert.h" +#include "model_normal_map_vert.h" +#include "model_lightmap_vert.h" +#include "model_lightmap_normal_map_vert.h" +#include "skin_model_vert.h" +#include "skin_model_shadow_vert.h" +#include "skin_model_normal_map_vert.h" + #include "model_frag.h" +#include "model_shadow_frag.h" +#include "model_normal_map_frag.h" +#include "model_normal_specular_map_frag.h" +#include "model_specular_map_frag.h" +#include "model_lightmap_frag.h" +#include "model_lightmap_normal_map_frag.h" +#include "model_lightmap_normal_specular_map_frag.h" +#include "model_lightmap_specular_map_frag.h" +#include "model_translucent_frag.h" + #define GLBATCH( call ) batch._##call //#define GLBATCH( call ) call @@ -237,106 +255,69 @@ void Model::init() { if (!_program.isLinked()) { _program.addShaderFromSourceCode(QGLShader::Vertex, model_vert); _program.addShaderFromSourceCode(QGLShader::Fragment, model_frag); - initProgram(_program, _locations); - _normalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); - _normalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); - - initProgram(_normalMapProgram, _normalMapLocations); - - _specularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); - _specularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); - - initProgram(_specularMapProgram, _specularMapLocations); - - _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_normal_map.vert"); - _normalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); - - initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations); - - _translucentProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); - _translucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_translucent.frag"); - - initProgram(_translucentProgram, _translucentLocations); - - // Lightmap - _lightmapProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); - _lightmapProgram.addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/model_lightmap.frag"); - - initProgram(_lightmapProgram, _lightmapLocations); - - _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); - _lightmapNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.frag"); - - initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations); - - _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap.vert"); - _lightmapSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_specular_map.frag"); - - initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations); - - _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_map.vert"); - _lightmapNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_lightmap_normal_specular_map.frag"); - - initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations); - // end lightmap - - - _shadowProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/model_shadow.vert"); - _shadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_shadow.frag"); - - _skinProgram.addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag); - - initSkinProgram(_skinProgram, _skinLocations); - - _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); - _skinNormalMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_map.frag"); - - initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations); - - _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_specular_map.frag"); - - initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations); - - _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_normal_map.vert"); - _skinNormalSpecularMapProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_normal_specular_map.frag"); - - initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations); - - _skinShadowProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model_shadow.vert"); - _skinShadowProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_shadow.frag"); - - initSkinProgram(_skinShadowProgram, _skinShadowLocations); - - _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Vertex, - PathUtils::resourcesPath() + "shaders/skin_model.vert"); - _skinTranslucentProgram.addShaderFromSourceFile(QGLShader::Fragment, - PathUtils::resourcesPath() + "shaders/model_translucent.frag"); - + _normalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert); + _normalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag); + initProgram(_normalMapProgram, _normalMapLocations); + + _specularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _specularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag); + initProgram(_specularMapProgram, _specularMapLocations); + + _normalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_normal_map_vert); + _normalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag); + initProgram(_normalSpecularMapProgram, _normalSpecularMapLocations); + + _translucentProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _translucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag); + initProgram(_translucentProgram, _translucentLocations); + + // Lightmap + _lightmapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert); + _lightmapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_frag); + initProgram(_lightmapProgram, _lightmapLocations); + + _lightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert); + _lightmapNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_map_frag); + initProgram(_lightmapNormalMapProgram, _lightmapNormalMapLocations); + + _lightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_vert); + _lightmapSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_specular_map_frag); + initProgram(_lightmapSpecularMapProgram, _lightmapSpecularMapLocations); + + _lightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_lightmap_normal_map_vert); + _lightmapNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_lightmap_normal_specular_map_frag); + initProgram(_lightmapNormalSpecularMapProgram, _lightmapNormalSpecularMapLocations); + // end lightmap + + + _shadowProgram.addShaderFromSourceCode(QGLShader::Vertex, model_shadow_vert); + _shadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag); + + _skinProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert); + _skinProgram.addShaderFromSourceCode(QGLShader::Fragment, model_frag); + initSkinProgram(_skinProgram, _skinLocations); + + _skinNormalMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert); + _skinNormalMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_map_frag); + initSkinProgram(_skinNormalMapProgram, _skinNormalMapLocations); + + _skinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, model_vert); + _skinSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_specular_map_frag); + initSkinProgram(_skinSpecularMapProgram, _skinSpecularMapLocations); + + _skinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_normal_map_vert); + _skinNormalSpecularMapProgram.addShaderFromSourceCode(QGLShader::Fragment, model_normal_specular_map_frag); + initSkinProgram(_skinNormalSpecularMapProgram, _skinNormalSpecularMapLocations); + + _skinShadowProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_shadow_vert); + _skinShadowProgram.addShaderFromSourceCode(QGLShader::Fragment, model_shadow_frag); + initSkinProgram(_skinShadowProgram, _skinShadowLocations); + + + _skinTranslucentProgram.addShaderFromSourceCode(QGLShader::Vertex, skin_model_vert); + _skinTranslucentProgram.addShaderFromSourceCode(QGLShader::Fragment, model_translucent_frag); initSkinProgram(_skinTranslucentProgram, _skinTranslucentLocations); } } From a022e948146f132096e210bcd7267679445d9e0a Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 30 Dec 2014 12:38:36 -0800 Subject: [PATCH 21/23] Adding the shader files --- libraries/render-utils/src/model_lightmap.slf | 38 +++++++++++++ libraries/render-utils/src/model_lightmap.slv | 41 ++++++++++++++ .../src/model_lightmap_normal_map.slf | 51 +++++++++++++++++ .../src/model_lightmap_normal_map.slv | 47 ++++++++++++++++ .../model_lightmap_normal_specular_map.slf | 55 +++++++++++++++++++ .../src/model_lightmap_specular_map.slf | 41 ++++++++++++++ .../render-utils/src/model_normal_map.slf | 44 +++++++++++++++ .../render-utils/src/model_normal_map.slv | 41 ++++++++++++++ .../src/model_normal_specular_map.slf | 48 ++++++++++++++++ libraries/render-utils/src/model_shadow.slf | 18 ++++++ libraries/render-utils/src/model_shadow.slv | 18 ++++++ .../render-utils/src/model_specular_map.slf | 34 ++++++++++++ .../render-utils/src/model_translucent.slf | 21 +++++++ libraries/render-utils/src/skin_model.slv | 47 ++++++++++++++++ .../src/skin_model_normal_map.slv | 55 +++++++++++++++++++ .../render-utils/src/skin_model_shadow.slv | 31 +++++++++++ 16 files changed, 630 insertions(+) create mode 100755 libraries/render-utils/src/model_lightmap.slf create mode 100755 libraries/render-utils/src/model_lightmap.slv create mode 100755 libraries/render-utils/src/model_lightmap_normal_map.slf create mode 100755 libraries/render-utils/src/model_lightmap_normal_map.slv create mode 100755 libraries/render-utils/src/model_lightmap_normal_specular_map.slf create mode 100755 libraries/render-utils/src/model_lightmap_specular_map.slf create mode 100755 libraries/render-utils/src/model_normal_map.slf create mode 100755 libraries/render-utils/src/model_normal_map.slv create mode 100755 libraries/render-utils/src/model_normal_specular_map.slf create mode 100755 libraries/render-utils/src/model_shadow.slf create mode 100755 libraries/render-utils/src/model_shadow.slv create mode 100755 libraries/render-utils/src/model_specular_map.slf create mode 100755 libraries/render-utils/src/model_translucent.slf create mode 100755 libraries/render-utils/src/skin_model.slv create mode 100755 libraries/render-utils/src/skin_model_normal_map.slv create mode 100755 libraries/render-utils/src/skin_model_shadow.slv diff --git a/libraries/render-utils/src/model_lightmap.slf b/libraries/render-utils/src/model_lightmap.slf new file mode 100755 index 0000000000..9feacbe057 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap.slf @@ -0,0 +1,38 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +void main(void) { + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 0.5); + gl_FragData[2] = vec4((vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_lightmap.slv b/libraries/render-utils/src/model_lightmap.slv new file mode 100755 index 0000000000..9f19ae8de2 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap.slv @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap.vert +// vertex shader +// +// Created by Sam Gateau on 11/21/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +attribute vec2 texcoord1; + +// the interpolated normal +varying vec4 normal; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +void main(void) { + // transform and store the normal for interpolation + normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0)); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; + + // use standard pipeline transform + gl_Position = ftransform(); +} + diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slf b/libraries/render-utils/src/model_lightmap_normal_map.slf new file mode 100755 index 0000000000..5bebbee3f6 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map.slf @@ -0,0 +1,51 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +varying vec2 interpolatedTexcoord1; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_lightmap_normal_map.slv b/libraries/render-utils/src/model_lightmap_normal_map.slv new file mode 100755 index 0000000000..c19336ddae --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_map.slv @@ -0,0 +1,47 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_map.vert +// vertex shader +// +// Created by Sam Gateau on 11/21/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +attribute vec2 texcoord1; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +// the interpolated texcoord1 +varying vec2 interpolatedTexcoord1; + +void main(void) { + // transform and store the normal and tangent for interpolation + interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + interpolatedTexcoord1 = vec2(texcoordMatrices[1] * vec4(texcoord1.xy, 0.0, 1.0)).xy; + + // use standard pipeline transform + gl_Position = ftransform(); +} diff --git a/libraries/render-utils/src/model_lightmap_normal_specular_map.slf b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf new file mode 100755 index 0000000000..d2f76e4ef3 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_normal_specular_map.slf @@ -0,0 +1,55 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_normal_specular_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the normal map texture +uniform sampler2D normalMap; + +// the specular map texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +varying vec2 interpolatedTexcoord1; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, + gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_lightmap_specular_map.slf b/libraries/render-utils/src/model_lightmap_specular_map.slf new file mode 100755 index 0000000000..40879a8fc3 --- /dev/null +++ b/libraries/render-utils/src/model_lightmap_specular_map.slf @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_lightmap_specular_map.frag +// fragment shader +// +// Created by Samuel Gateau on 11/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the emissive map texture and parameters +uniform sampler2D emissiveMap; +uniform vec2 emissiveParams; + +// the specular texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +varying vec2 interpolatedTexcoord1; + +void main(void) { + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + vec4 emissive = texture2D(emissiveMap, interpolatedTexcoord1.st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb * (vec3(emissiveParams.x) + emissiveParams.y * emissive.rgb), mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, + gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_normal_map.slf b/libraries/render-utils/src/model_normal_map.slf new file mode 100755 index 0000000000..b625b346ed --- /dev/null +++ b/libraries/render-utils/src/model_normal_map.slf @@ -0,0 +1,44 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_normal_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 10/29/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb, gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_normal_map.slv b/libraries/render-utils/src/model_normal_map.slv new file mode 100755 index 0000000000..0eb974912f --- /dev/null +++ b/libraries/render-utils/src/model_normal_map.slv @@ -0,0 +1,41 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/14/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; + +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // transform and store the normal and tangent for interpolation + interpolatedNormal = gl_ModelViewMatrix * vec4(gl_Normal, 0.0); + interpolatedTangent = gl_ModelViewMatrix * vec4(tangent, 0.0); + + // pass along the diffuse color + gl_FrontColor = gl_Color * gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + // use standard pipeline transform + gl_Position = ftransform(); +} diff --git a/libraries/render-utils/src/model_normal_specular_map.slf b/libraries/render-utils/src/model_normal_specular_map.slf new file mode 100755 index 0000000000..fd288f0867 --- /dev/null +++ b/libraries/render-utils/src/model_normal_specular_map.slf @@ -0,0 +1,48 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_normal_specular_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 5/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the normal map texture +uniform sampler2D normalMap; + +// the specular map texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + // compute the view normal from the various bits + vec3 normalizedNormal = normalize(vec3(interpolatedNormal)); + vec3 normalizedTangent = normalize(vec3(interpolatedTangent)); + vec3 normalizedBitangent = normalize(cross(normalizedNormal, normalizedTangent)); + vec3 localNormal = vec3(texture2D(normalMap, gl_TexCoord[0].st)) - vec3(0.5, 0.5, 0.5); + vec4 viewNormal = vec4(normalizedTangent * localNormal.x + + normalizedBitangent * localNormal.y + normalizedNormal * localNormal.z, 0.0); + + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = viewNormal + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, + gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_shadow.slf b/libraries/render-utils/src/model_shadow.slf new file mode 100755 index 0000000000..1fbb44140b --- /dev/null +++ b/libraries/render-utils/src/model_shadow.slf @@ -0,0 +1,18 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_shadow.frag +// fragment shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +void main(void) { + // fixed color for now (we may eventually want to use texture alpha) + gl_FragColor = vec4(1.0, 1.0, 1.0, 0.0); +} diff --git a/libraries/render-utils/src/model_shadow.slv b/libraries/render-utils/src/model_shadow.slv new file mode 100755 index 0000000000..6ff8c23f5a --- /dev/null +++ b/libraries/render-utils/src/model_shadow.slv @@ -0,0 +1,18 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_shadow.vert +// vertex shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +void main(void) { + // just use standard pipeline transform + gl_Position = ftransform(); +} diff --git a/libraries/render-utils/src/model_specular_map.slf b/libraries/render-utils/src/model_specular_map.slf new file mode 100755 index 0000000000..4428173562 --- /dev/null +++ b/libraries/render-utils/src/model_specular_map.slf @@ -0,0 +1,34 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_specular_map.frag +// fragment shader +// +// Created by Andrzej Kapolka on 5/6/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +// the specular texture +uniform sampler2D specularMap; + +// the alpha threshold +uniform float alphaThreshold; + +// the interpolated normal +varying vec4 normal; + +void main(void) { + // set the diffuse, normal, specular data + vec4 diffuse = texture2D(diffuseMap, gl_TexCoord[0].st); + gl_FragData[0] = vec4(gl_Color.rgb * diffuse.rgb, mix(gl_Color.a, 1.0 - gl_Color.a, step(diffuse.a, alphaThreshold))); + gl_FragData[1] = normalize(normal) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(gl_FrontMaterial.specular.rgb * texture2D(specularMap, gl_TexCoord[0].st).rgb, + gl_FrontMaterial.shininess / 128.0); +} diff --git a/libraries/render-utils/src/model_translucent.slf b/libraries/render-utils/src/model_translucent.slf new file mode 100755 index 0000000000..497f5962bc --- /dev/null +++ b/libraries/render-utils/src/model_translucent.slf @@ -0,0 +1,21 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// model_translucent.frag +// fragment shader +// +// Created by Andrzej Kapolka on 9/19/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +// the diffuse texture +uniform sampler2D diffuseMap; + +void main(void) { + // set the diffuse data + gl_FragData[0] = gl_Color * texture2D(diffuseMap, gl_TexCoord[0].st); +} diff --git a/libraries/render-utils/src/skin_model.slv b/libraries/render-utils/src/skin_model.slv new file mode 100755 index 0000000000..4144198969 --- /dev/null +++ b/libraries/render-utils/src/skin_model.slv @@ -0,0 +1,47 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/14/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +// the interpolated normal +varying vec4 normal; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + normal = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + position += clusterMatrix * gl_Vertex * clusterWeight; + normal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; + } + + normal = normalize(gl_ModelViewMatrix * normal); + + // pass along the diffuse color + gl_FrontColor = gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + gl_Position = gl_ModelViewProjectionMatrix * position; +} diff --git a/libraries/render-utils/src/skin_model_normal_map.slv b/libraries/render-utils/src/skin_model_normal_map.slv new file mode 100755 index 0000000000..b021184591 --- /dev/null +++ b/libraries/render-utils/src/skin_model_normal_map.slv @@ -0,0 +1,55 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_normal_map.vert +// vertex shader +// +// Created by Andrzej Kapolka on 10/29/13. +// Copyright 2013 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_TEXCOORDS = 2; +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; +uniform mat4 texcoordMatrices[MAX_TEXCOORDS]; + +// the tangent vector +attribute vec3 tangent; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +// the interpolated normal +varying vec4 interpolatedNormal; + +// the interpolated tangent +varying vec4 interpolatedTangent; + +void main(void) { + vec4 interpolatedPosition = vec4(0.0, 0.0, 0.0, 0.0); + interpolatedNormal = vec4(0.0, 0.0, 0.0, 0.0); + interpolatedTangent = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + interpolatedPosition += clusterMatrix * gl_Vertex * clusterWeight; + interpolatedNormal += clusterMatrix * vec4(gl_Normal, 0.0) * clusterWeight; + interpolatedTangent += clusterMatrix * vec4(tangent, 0.0) * clusterWeight; + } + interpolatedNormal = gl_ModelViewMatrix * interpolatedNormal; + interpolatedTangent = gl_ModelViewMatrix * interpolatedTangent; + + // pass along the diffuse color + gl_FrontColor = gl_FrontMaterial.diffuse; + + // and the texture coordinates + gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0); + + gl_Position = gl_ModelViewProjectionMatrix * interpolatedPosition; +} diff --git a/libraries/render-utils/src/skin_model_shadow.slv b/libraries/render-utils/src/skin_model_shadow.slv new file mode 100755 index 0000000000..9a594ac26c --- /dev/null +++ b/libraries/render-utils/src/skin_model_shadow.slv @@ -0,0 +1,31 @@ +<@include Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// skin_model_shadow.vert +// vertex shader +// +// Created by Andrzej Kapolka on 3/24/14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +const int MAX_CLUSTERS = 128; +const int INDICES_PER_VERTEX = 4; + +uniform mat4 clusterMatrices[MAX_CLUSTERS]; + +attribute vec4 clusterIndices; +attribute vec4 clusterWeights; + +void main(void) { + vec4 position = vec4(0.0, 0.0, 0.0, 0.0); + for (int i = 0; i < INDICES_PER_VERTEX; i++) { + mat4 clusterMatrix = clusterMatrices[int(clusterIndices[i])]; + float clusterWeight = clusterWeights[i]; + position += clusterMatrix * gl_Vertex * clusterWeight; + } + gl_Position = gl_ModelViewProjectionMatrix * position; +} From 0d07875f94ff51685bb4a33d13a1f22e90b349b6 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Tue, 30 Dec 2014 12:54:12 -0800 Subject: [PATCH 22/23] Fix overflow warning. --- interface/src/ModelUploader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/ModelUploader.cpp b/interface/src/ModelUploader.cpp index e702d9db76..89b6a4c9c0 100644 --- a/interface/src/ModelUploader.cpp +++ b/interface/src/ModelUploader.cpp @@ -55,8 +55,8 @@ static const QString MODEL_URL = "/api/v1/models"; static const QString SETTING_NAME = "LastModelUploadLocation"; -static const int BYTES_PER_MEGABYTES = 1024 * 1024; -static const unsigned long MAX_SIZE = 50 * 1024 * BYTES_PER_MEGABYTES; // 50 GB (Virtually remove limit) +static const long long BYTES_PER_MEGABYTES = 1024 * 1024; +static const unsigned long long MAX_SIZE = 50 * 1024 * BYTES_PER_MEGABYTES; // 50 GB (Virtually remove limit) static const int MAX_TEXTURE_SIZE = 1024; static const int TIMEOUT = 1000; static const int MAX_CHECK = 30; From ea69dcaf29f5d802b5cd27f97a46bcc65972ef38 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Tue, 30 Dec 2014 13:10:23 -0800 Subject: [PATCH 23/23] Update grid colors --- examples/libraries/gridTool.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/libraries/gridTool.js b/examples/libraries/gridTool.js index e222ff3adb..2462caff23 100644 --- a/examples/libraries/gridTool.js +++ b/examples/libraries/gridTool.js @@ -2,11 +2,11 @@ Grid = function(opts) { var that = {}; var colors = [ - { red: 102, green: 180, blue: 126 }, - { red: 83, green: 210, blue: 83 }, - { red: 235, green: 173, blue: 0 }, - { red: 210, green: 115, blue: 0 }, - { red: 48, green: 116, blue: 119 }, + { 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: 0, blue: 0 }, ]; var colorIndex = 0; var gridAlpha = 1.0;