From b8cf4ea29de72a79201c05b4de19b3c509124926 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 16 Jun 2015 21:19:31 -0700 Subject: [PATCH 01/26] use -Woverloaded-virtual with g++. quiet compiler warnings --- CMakeLists.txt | 2 +- libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c283bfff17..99d4a75585 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ if (WIN32) else () set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -fno-strict-aliasing -Wno-unused-parameter") if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ggdb -Woverloaded-virtual") endif () endif(WIN32) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index 77aeb24f2a..f05e02ac69 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -45,6 +45,7 @@ public: bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const; + using PolyVoxEntityItem::setVoxelSurfaceStyle; virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle); void getModel(); From 22ac61e476ee43f1beabcd736314ad2ddab2051b Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 17 Jun 2015 14:40:24 -0700 Subject: [PATCH 02/26] work around hiding of virtual functions in PolyVox entity classses --- .../src/RenderablePolyVoxEntityItem.cpp | 10 +++------- .../src/RenderablePolyVoxEntityItem.h | 11 ++++++----- libraries/entities/src/PolyVoxEntityItem.h | 14 +++++++++++--- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp index 71c3537a0c..4106559b6c 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.cpp @@ -141,11 +141,7 @@ void RenderablePolyVoxEntityItem::setVoxelVolumeSize(glm::vec3 voxelVolumeSize) decompressVolumeData(); } -void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { - if (voxelSurfaceStyle == _voxelSurfaceStyle) { - return; - } - +void RenderablePolyVoxEntityItem::updateVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { // if we are switching to or from "edged" we need to force a resize of _volData. if (voxelSurfaceStyle == SURFACE_EDGED_CUBIC || _voxelSurfaceStyle == SURFACE_EDGED_CUBIC) { @@ -153,10 +149,10 @@ void RenderablePolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxel delete _volData; } _volData = nullptr; - PolyVoxEntityItem::setVoxelSurfaceStyle(voxelSurfaceStyle); + _voxelSurfaceStyle = voxelSurfaceStyle; setVoxelVolumeSize(_voxelVolumeSize); } else { - PolyVoxEntityItem::setVoxelSurfaceStyle(voxelSurfaceStyle); + _voxelSurfaceStyle = voxelSurfaceStyle; } _needsModelReload = true; } diff --git a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h index c785ed2c1a..1097ad21be 100644 --- a/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h +++ b/libraries/entities-renderer/src/RenderablePolyVoxEntityItem.h @@ -36,18 +36,15 @@ public: virtual uint8_t getVoxel(int x, int y, int z); virtual void setVoxel(int x, int y, int z, uint8_t toValue); - + void updateOnCount(int x, int y, int z, uint8_t new_value); void render(RenderArgs* args); virtual bool supportsDetailedRayIntersection() const { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, - bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, + bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const; - using PolyVoxEntityItem::setVoxelSurfaceStyle; - virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle); - void getModel(); virtual void setVoxelData(QByteArray voxelData); @@ -75,6 +72,9 @@ public: SIMPLE_RENDERABLE(); +protected: + virtual void updateVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle); + private: // The PolyVoxEntityItem class has _voxelData which contains dimensions and compressed voxel data. The dimensions // may not match _voxelVolumeSize. @@ -83,6 +83,7 @@ private: void compressVolumeData(); void decompressVolumeData(); + PolyVox::SimpleVolume* _volData = nullptr; model::Geometry _modelGeometry; bool _needsModelReload = true; diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index e5d511c087..39d67fb9a3 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -61,10 +61,14 @@ class PolyVoxEntityItem : public EntityItem { SURFACE_EDGED_CUBIC }; - virtual void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { _voxelSurfaceStyle = voxelSurfaceStyle; } - virtual void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { - setVoxelSurfaceStyle((PolyVoxSurfaceStyle) voxelSurfaceStyle); + void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { + if (voxelSurfaceStyle == _voxelSurfaceStyle) { + return; + } + updateVoxelSurfaceStyle(voxelSurfaceStyle); } + // this other version of setVoxelSurfaceStyle is needed for SET_ENTITY_PROPERTY_FROM_PROPERTIES + void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { setVoxelSurfaceStyle((PolyVoxSurfaceStyle) voxelSurfaceStyle); } virtual PolyVoxSurfaceStyle getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; } static const glm::vec3 DEFAULT_VOXEL_VOLUME_SIZE; @@ -89,6 +93,10 @@ class PolyVoxEntityItem : public EntityItem { static QByteArray makeEmptyVoxelData(quint16 voxelXSize = 16, quint16 voxelYSize = 16, quint16 voxelZSize = 16); protected: + virtual void updateVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { + _voxelSurfaceStyle = voxelSurfaceStyle; + } + glm::vec3 _voxelVolumeSize; // this is always 3 bytes QByteArray _voxelData; PolyVoxSurfaceStyle _voxelSurfaceStyle; From a486ed1a57a486bb8b9e60205b105ca800f259e2 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 15:13:03 +0200 Subject: [PATCH 03/26] Add _glUniform1i to Batches --- libraries/gpu/src/gpu/Batch.h | 2 ++ libraries/gpu/src/gpu/GLBackend.cpp | 23 +++++++++++++++++++++++ libraries/gpu/src/gpu/GLBackend.h | 1 + 3 files changed, 26 insertions(+) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index bbd2121c54..9d2838127e 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -148,6 +148,7 @@ public: void _glDrawBuffers(GLsizei n, const GLenum* bufs); void _glUseProgram(GLuint program); + void _glUniform1i(GLint location, GLint v0); void _glUniform1f(GLint location, GLfloat v0); void _glUniform2f(GLint location, GLfloat v0, GLfloat v1); void _glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2); @@ -210,6 +211,7 @@ public: COMMAND_glDrawBuffers, COMMAND_glUseProgram, + COMMAND_glUniform1i, COMMAND_glUniform1f, COMMAND_glUniform2f, COMMAND_glUniform3f, diff --git a/libraries/gpu/src/gpu/GLBackend.cpp b/libraries/gpu/src/gpu/GLBackend.cpp index 20a6b60901..154d6b9e3f 100644 --- a/libraries/gpu/src/gpu/GLBackend.cpp +++ b/libraries/gpu/src/gpu/GLBackend.cpp @@ -59,6 +59,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] = (&::gpu::GLBackend::do_glDrawBuffers), (&::gpu::GLBackend::do_glUseProgram), + (&::gpu::GLBackend::do_glUniform1i), (&::gpu::GLBackend::do_glUniform1f), (&::gpu::GLBackend::do_glUniform2f), (&::gpu::GLBackend::do_glUniform3f), @@ -433,6 +434,28 @@ void GLBackend::do_glUseProgram(Batch& batch, uint32 paramOffset) { (void) CHECK_GL_ERROR(); } +void Batch::_glUniform1i(GLint location, GLint v0) { + if (location < 0) { + return; + } + ADD_COMMAND_GL(glUniform1i); + _params.push_back(v0); + _params.push_back(location); + + DO_IT_NOW(_glUniform1i, 1); +} +void GLBackend::do_glUniform1i(Batch& batch, uint32 paramOffset) { + if (_pipeline._program == 0) { + // We should call updatePipeline() to bind the program but we are not doing that + // because these uniform setters are deprecated and we don;t want to create side effect + return; + } + glUniform1f( + batch._params[paramOffset + 1]._int, + batch._params[paramOffset + 0]._int); + (void) CHECK_GL_ERROR(); +} + void Batch::_glUniform1f(GLint location, GLfloat v0) { if (location < 0) { return; diff --git a/libraries/gpu/src/gpu/GLBackend.h b/libraries/gpu/src/gpu/GLBackend.h index c87394869c..f20b6735b0 100644 --- a/libraries/gpu/src/gpu/GLBackend.h +++ b/libraries/gpu/src/gpu/GLBackend.h @@ -377,6 +377,7 @@ protected: void do_glDrawBuffers(Batch& batch, uint32 paramOffset); void do_glUseProgram(Batch& batch, uint32 paramOffset); + void do_glUniform1i(Batch& batch, uint32 paramOffset); void do_glUniform1f(Batch& batch, uint32 paramOffset); void do_glUniform2f(Batch& batch, uint32 paramOffset); void do_glUniform3f(Batch& batch, uint32 paramOffset); From e8e1f818803da1601cbbdc39e52dd5581494a8fc Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 15:13:43 +0200 Subject: [PATCH 04/26] Make Batch copy constructor explicit --- libraries/gpu/src/gpu/Batch.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/gpu/src/gpu/Batch.h b/libraries/gpu/src/gpu/Batch.h index 9d2838127e..9c97db65ef 100644 --- a/libraries/gpu/src/gpu/Batch.h +++ b/libraries/gpu/src/gpu/Batch.h @@ -70,7 +70,7 @@ public: typedef Stream::Slot Slot; Batch(); - Batch(const Batch& batch); + explicit Batch(const Batch& batch); ~Batch(); void clear(); From bdaf8a8a32c74cf94f0b0bd64243dc3e17ddec4a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 17:14:05 +0200 Subject: [PATCH 05/26] Fix bevel quads --- libraries/render-utils/src/GeometryCache.cpp | 78 +++++++++++--------- 1 file changed, 44 insertions(+), 34 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 303d63bef8..8fb10beca6 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1026,12 +1026,12 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int } const int FLOATS_PER_VERTEX = 2; // vertices - const int vertices = 8; + const int NUM_VERTICES = 12; if (!details.isCreated) { details.isCreated = true; - details.vertices = vertices; + details.vertices = NUM_VERTICES; details.vertexSize = FLOATS_PER_VERTEX; gpu::BufferPointer verticesBuffer(new gpu::Buffer()); @@ -1044,62 +1044,72 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int details.streamFormat = streamFormat; details.stream = stream; - details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ), 0); + details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::XYZ)); details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA)); details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride); details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); - int vertexPoints = vertices * FLOATS_PER_VERTEX; - GLfloat* vertexBuffer = new GLfloat[vertexPoints]; // only vertices, no normals because we're a 2D quad - GLfloat* vertex = vertexBuffer; + int vertexPoints = NUM_VERTICES * FLOATS_PER_VERTEX; + GLfloat vertexBuffer[vertexPoints]; // only vertices, no normals because we're a 2D quad int vertexPoint = 0; - // left side - vertex[vertexPoint++] = x; - vertex[vertexPoint++] = y + bevelDistance; + // left side quad + vertexBuffer[vertexPoint++] = x; + vertexBuffer[vertexPoint++] = y + bevelDistance; - vertex[vertexPoint++] = x; - vertex[vertexPoint++] = y + height - bevelDistance; - - // top side - vertex[vertexPoint++] = x + bevelDistance; - vertex[vertexPoint++] = y + height; + vertexBuffer[vertexPoint++] = x + bevelDistance; + vertexBuffer[vertexPoint++] = y; - vertex[vertexPoint++] = x + width - bevelDistance; - vertex[vertexPoint++] = y + height; + vertexBuffer[vertexPoint++] = x + bevelDistance; + vertexBuffer[vertexPoint++] = y + height; + + vertexBuffer[vertexPoint++] = x; + vertexBuffer[vertexPoint++] = y + height - bevelDistance; - // right - vertex[vertexPoint++] = x + width; - vertex[vertexPoint++] = y + height - bevelDistance; - vertex[vertexPoint++] = x + width; - vertex[vertexPoint++] = y + bevelDistance; + // middle quad + vertexBuffer[vertexPoint++] = x + bevelDistance; + vertexBuffer[vertexPoint++] = y; + + vertexBuffer[vertexPoint++] = x + width - bevelDistance; + vertexBuffer[vertexPoint++] = y; + + vertexBuffer[vertexPoint++] = x + width - bevelDistance; + vertexBuffer[vertexPoint++] = y + height; + + vertexBuffer[vertexPoint++] = x + bevelDistance; + vertexBuffer[vertexPoint++] = y + height; - // bottom - vertex[vertexPoint++] = x + width - bevelDistance; - vertex[vertexPoint++] = y; - vertex[vertexPoint++] = x +bevelDistance; - vertex[vertexPoint++] = y; - - const int NUM_COLOR_SCALARS_PER_QUAD = 8; + // right side quad + vertexBuffer[vertexPoint++] = x + width - bevelDistance; + vertexBuffer[vertexPoint++] = y; + + vertexBuffer[vertexPoint++] = x + width; + vertexBuffer[vertexPoint++] = y + bevelDistance; + + vertexBuffer[vertexPoint++] = x + width; + vertexBuffer[vertexPoint++] = y + height - bevelDistance; + + vertexBuffer[vertexPoint++] = x + width - bevelDistance; + vertexBuffer[vertexPoint++] = y + height; + int compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | ((int(color.z * 255.0f) & 0xFF) << 16) | ((int(color.w * 255.0f) & 0xFF) << 24); - int colors[NUM_COLOR_SCALARS_PER_QUAD] = { compactColor, compactColor, compactColor, compactColor, - compactColor, compactColor, compactColor, compactColor }; + int colors[NUM_VERTICES] = { compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor, + compactColor, compactColor, compactColor, compactColor }; details.verticesBuffer->append(sizeof(vertexBuffer), (gpu::Byte*) vertexBuffer); details.colorBuffer->append(sizeof(colors), (gpu::Byte*) colors); - - delete[] vertexBuffer; } batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); - batch.draw(gpu::QUADS, 4, 0); + batch.draw(gpu::QUADS, details.vertices, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { From ca98b378df465497812001dbbc4751d24a7b0d2d Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 17:17:47 +0200 Subject: [PATCH 06/26] Adjust sdf frag shader alpha correctly --- libraries/render-utils/src/TextRenderer3D.cpp | 2 +- libraries/render-utils/src/sdf_text3D.slf | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index 2f898542b9..5894a2a258 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -429,8 +429,8 @@ void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, setupGPU(); batch.setPipeline(_pipeline); batch.setUniformTexture(_fontLoc, _texture); - batch._glUniform1f(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT) ? 1.0f : 0.0f); batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)&color); + batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT)); batch.setInputFormat(_format); batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 3980045d08..07ca75237b 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -11,7 +11,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html uniform sampler2D Font; -uniform float Outline; +uniform bool Outline; uniform vec4 Color; const float gamma = 2.6; @@ -22,7 +22,7 @@ const float outlineExpansion = 0.2; void main() { // retrieve signed distance float sdf = texture2D(Font, gl_TexCoord[0].xy).g; - if (Outline == 1.0f) { + if (Outline) { if (sdf > interiorCutoff) { sdf = 1.0 - sdf; } else { @@ -31,7 +31,7 @@ void main() { } // perform adaptive anti-aliasing of the edges // The larger we're rendering, the less anti-aliasing we need - float s = smoothing * length(fwidth(gl_TexCoord[0])); + float s = smoothing * length(fwidth(gl_TexCoord[0].xy)); float w = clamp( s, 0.0, 0.5); float a = smoothstep(0.5 - w, 0.5 + w, sdf); @@ -43,5 +43,5 @@ void main() { } // final color - gl_FragColor = vec4(Color.rgb, a); + gl_FragColor = vec4(Color.rgb, Color.a * a); } \ No newline at end of file From 47634a48a62ffcdb2b4a32a37ca092477a5e08df Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 17:29:08 +0200 Subject: [PATCH 07/26] Make renderDisplayName const --- interface/src/avatar/Avatar.cpp | 77 ++++++++++++---------------- interface/src/avatar/Avatar.h | 10 ++-- interface/src/avatar/MyAvatar.h | 2 +- libraries/avatars/src/AvatarData.cpp | 5 +- libraries/avatars/src/AvatarData.h | 3 +- 5 files changed, 42 insertions(+), 55 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 71f4621205..4c4bc93036 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -57,7 +57,7 @@ const float CHAT_MESSAGE_SCALE = 0.0015f; const float CHAT_MESSAGE_HEIGHT = 0.1f; const float DISPLAYNAME_FADE_TIME = 0.5f; const float DISPLAYNAME_FADE_FACTOR = pow(0.01f, 1.0f / DISPLAYNAME_FADE_TIME); -const float DISPLAYNAME_ALPHA = 0.95f; +const float DISPLAYNAME_ALPHA = 1.0f; const float DISPLAYNAME_BACKGROUND_ALPHA = 0.4f; namespace render { @@ -323,7 +323,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo _referential->update(); } - auto batch = renderArgs->_batch; + auto& batch = *renderArgs->_batch; if (postLighting && glm::distance(DependencyManager::get()->getMyAvatar()->getPosition(), _position) < 10.0f) { @@ -354,9 +354,9 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo Transform pointerTransform; pointerTransform.setTranslation(position); pointerTransform.setRotation(rotation); - batch->setModelTransform(pointerTransform); - deferredLighting->bindSimpleProgram(*batch); - geometryCache->renderLine(*batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); + batch.setModelTransform(pointerTransform); + deferredLighting->bindSimpleProgram(batch); + geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } } @@ -377,9 +377,9 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo Transform pointerTransform; pointerTransform.setTranslation(position); pointerTransform.setRotation(rotation); - batch->setModelTransform(pointerTransform); - deferredLighting->bindSimpleProgram(*batch); - geometryCache->renderLine(*batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); + batch.setModelTransform(pointerTransform); + deferredLighting->bindSimpleProgram(batch); + geometryCache->renderLine(batch, glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, laserLength, 0.0f), laserColor); } } } @@ -464,8 +464,8 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo } Transform transform; transform.setTranslation(position); - batch->setModelTransform(transform); - DependencyManager::get()->renderSolidSphere(*batch, LOOK_AT_INDICATOR_RADIUS + batch.setModelTransform(transform); + DependencyManager::get()->renderSolidSphere(batch, LOOK_AT_INDICATOR_RADIUS , 15, 15, LOOK_AT_INDICATOR_COLOR); } } @@ -492,14 +492,14 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo Transform transform; transform.setTranslation(_position); transform.setScale(height); - batch->setModelTransform(transform); + batch.setModelTransform(transform); if (_voiceSphereID == GeometryCache::UNKNOWN_ID) { _voiceSphereID = DependencyManager::get()->allocateID(); } - DependencyManager::get()->bindSimpleProgram(*batch); - DependencyManager::get()->renderSphere(*batch, sphereRadius, 15, 15, + DependencyManager::get()->bindSimpleProgram(batch); + DependencyManager::get()->renderSphere(batch, sphereRadius, 15, 15, glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE), true, _voiceSphereID); } @@ -507,14 +507,13 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo } const float DISPLAYNAME_DISTANCE = 20.0f; - setShowDisplayName(renderArgs->_renderMode == RenderArgs::NORMAL_RENDER_MODE && distanceToTarget < DISPLAYNAME_DISTANCE); + setShowDisplayName(distanceToTarget < DISPLAYNAME_DISTANCE); - if (renderArgs->_renderMode != RenderArgs::NORMAL_RENDER_MODE || (isMyAvatar() && - Application::getInstance()->getCamera()->getMode() == CAMERA_MODE_FIRST_PERSON)) { - return; + + auto cameraMode = Application::getInstance()->getCamera()->getMode(); + if (!isMyAvatar() || cameraMode != CAMERA_MODE_FIRST_PERSON) { + renderDisplayName(batch); } - - renderDisplayName(renderArgs); } glm::quat Avatar::computeRotationFromBodyToWorldUp(float proportion) const { @@ -654,7 +653,7 @@ float Avatar::getBillboardSize() const { return _scale * BILLBOARD_DISTANCE * tanf(glm::radians(BILLBOARD_FIELD_OF_VIEW / 2.0f)); } -glm::vec3 Avatar::getDisplayNamePosition() { +glm::vec3 Avatar::getDisplayNamePosition() const { glm::vec3 namePosition; if (getSkeletonModel().getNeckPosition(namePosition)) { namePosition += getBodyUpDirection() * getHeadHeight() * 1.1f; @@ -665,7 +664,7 @@ glm::vec3 Avatar::getDisplayNamePosition() { return namePosition; } -float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) { +float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) const { // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates // We project a unit vector and check the difference in screen coordinates, to check which is the @@ -710,9 +709,7 @@ float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, boo return scaleFactor; } -void Avatar::renderDisplayName(RenderArgs* renderArgs) { - auto batch = renderArgs->_batch; - +void Avatar::renderDisplayName(gpu::Batch& batch) const { bool shouldShowReceiveStats = DependencyManager::get()->shouldShowReceiveStats() && !isMyAvatar(); if ((_displayName.isEmpty() && !shouldShowReceiveStats) || _displayNameAlpha == 0.0f) { @@ -738,7 +735,6 @@ void Avatar::renderDisplayName(RenderArgs* renderArgs) { // optionally render timing stats for this avatar with the display name QString renderedDisplayName = _displayName; - QRect nameDynamicRect = _displayNameBoundingRect; if (shouldShowReceiveStats) { float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / (float) BYTES_PER_KILOBIT; @@ -750,11 +746,10 @@ void Avatar::renderDisplayName(RenderArgs* renderArgs) { QString statsText = statsFormat.arg(QString::number(kilobitsPerSecond, 'f', 2)).arg(getReceiveRate()); renderedDisplayName += statsText; - - glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(renderedDisplayName); - nameDynamicRect = QRect(0, 0, (int)extent.x, (int)extent.y); } - + + glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(renderedDisplayName); + QRect nameDynamicRect = QRect(0, 0, (int)extent.x, (int)extent.y);; int text_x = -nameDynamicRect.width() / 2; int text_y = -nameDynamicRect.height() / 2; @@ -763,26 +758,27 @@ void Avatar::renderDisplayName(RenderArgs* renderArgs) { int right = left + nameDynamicRect.width(); int bottom = text_y; int top = bottom + nameDynamicRect.height(); - const int border = 8; + const int border = 0.1f * nameDynamicRect.height(); bottom -= border; left -= border; top += border; right += border; + int bevelDistance = 0.1f * (top - bottom); glm::vec4 textColor(0.93f, 0.93f, 0.93f, _displayNameAlpha); glm::vec4 backgroundColor(0.2f, 0.2f, 0.2f, - _displayNameAlpha * DISPLAYNAME_BACKGROUND_ALPHA / DISPLAYNAME_ALPHA); + (_displayNameAlpha / DISPLAYNAME_ALPHA) * DISPLAYNAME_BACKGROUND_ALPHA); auto backgroundTransform = textTransform; backgroundTransform.postTranslate(glm::vec3(0.0f, 0.0f, -0.001f)); - batch->setModelTransform(backgroundTransform); - DependencyManager::get()->bindSimpleProgram(*batch); - DependencyManager::get()->renderBevelCornersRect(*batch, left, bottom, right - left, top - bottom, 3, - backgroundColor); + batch.setModelTransform(backgroundTransform); + DependencyManager::get()->bindSimpleProgram(batch); + DependencyManager::get()->renderBevelCornersRect(batch, left, bottom, right - left, top - bottom, + bevelDistance, backgroundColor); QByteArray nameUTF8 = renderedDisplayName.toLocal8Bit(); - batch->setModelTransform(textTransform); - textRenderer(DISPLAYNAME)->draw(*batch, text_x, -text_y, nameUTF8.data(), textColor); + batch.setModelTransform(textTransform); + textRenderer(DISPLAYNAME)->draw(batch, text_x, -text_y, nameUTF8.data(), textColor); } bool Avatar::findRayIntersection(RayIntersectionInfo& intersection) const { @@ -987,13 +983,6 @@ void Avatar::setAttachmentData(const QVector& attachmentData) { } } -void Avatar::setDisplayName(const QString& displayName) { - AvatarData::setDisplayName(displayName); - // FIXME is this a sufficient replacement for tightBoundingRect? - glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(displayName); - _displayNameBoundingRect = QRect(0, 0, (int)extent.x, (int)extent.y); -} - void Avatar::setBillboard(const QByteArray& billboard) { AvatarData::setBillboard(billboard); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 2590808347..6c6082ca33 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -98,6 +98,7 @@ public: //getters bool isInitialized() const { return _initialized; } SkeletonModel& getSkeletonModel() { return _skeletonModel; } + const SkeletonModel& getSkeletonModel() const { return _skeletonModel; } const QVector& getAttachmentModels() const { return _attachmentModels; } glm::vec3 getChestPosition() const; float getScale() const { return _scale; } @@ -131,7 +132,7 @@ public: /// \return whether or not the plane penetrated bool findPlaneCollisions(const glm::vec4& plane, CollisionList& collisions); - virtual bool isMyAvatar() { return false; } + virtual bool isMyAvatar() const { return false; } virtual QVector getJointRotations() const; virtual glm::quat getJointRotation(int index) const; @@ -141,7 +142,6 @@ public: virtual void setFaceModelURL(const QUrl& faceModelURL); virtual void setSkeletonModelURL(const QUrl& skeletonModelURL); virtual void setAttachmentData(const QVector& attachmentData); - virtual void setDisplayName(const QString& displayName); virtual void setBillboard(const QByteArray& billboard); void setShowDisplayName(bool showDisplayName); @@ -232,10 +232,10 @@ protected: float getSkeletonHeight() const; float getHeadHeight() const; float getPelvisFloatingHeight() const; - glm::vec3 getDisplayNamePosition(); + glm::vec3 getDisplayNamePosition() const; - float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD); - void renderDisplayName(RenderArgs* renderArgs); + float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) const; + void renderDisplayName(gpu::Batch& batch) const; virtual void renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const RenderArgs* renderArgs, const glm::vec3& cameraPosition) const; virtual void fixupModelsInScene(); diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index 7adaf908f4..618184cce8 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -90,7 +90,7 @@ public: void relayDriveKeysToCharacterController(); - bool isMyAvatar() { return true; } + bool isMyAvatar() const { return true; } bool isLookingAtLeftEye(); diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index c7ab6dce2e..9a6400ae16 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -52,9 +52,8 @@ AvatarData::AvatarData() : _headData(NULL), _handData(NULL), _faceModelURL("http://invalid.com"), - _displayNameBoundingRect(), - _displayNameTargetAlpha(0.0f), - _displayNameAlpha(0.0f), + _displayNameTargetAlpha(1.0f), + _displayNameAlpha(1.0f), _billboard(), _errorLogExpiry(0), _owningAvatarMixer(), diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 2a452f8510..c482f52bf1 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -163,7 +163,7 @@ public: AvatarData(); virtual ~AvatarData(); - virtual bool isMyAvatar() { return false; } + virtual bool isMyAvatar() const { return false; } const QUuid& getSessionUUID() const { return _sessionUUID; } @@ -378,7 +378,6 @@ protected: QVector _attachmentData; QString _displayName; - QRect _displayNameBoundingRect; float _displayNameTargetAlpha; float _displayNameAlpha; From d7b9a1b0321c5f6046bad0f86a045ea52a18af25 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 17:31:22 +0200 Subject: [PATCH 08/26] Cleanup TextRenderer3D methods args --- interface/src/avatar/Avatar.cpp | 4 +- libraries/render-utils/src/TextRenderer3D.cpp | 39 +++++++------------ libraries/render-utils/src/TextRenderer3D.h | 19 +++++---- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4c4bc93036..9b1d161177 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -280,9 +280,9 @@ enum TextRendererType { }; static TextRenderer3D* textRenderer(TextRendererType type) { - static TextRenderer3D* chatRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, 24, -1, + static TextRenderer3D* chatRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, -1, false, TextRenderer3D::SHADOW_EFFECT); - static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY, 12); + static TextRenderer3D* displayNameRenderer = TextRenderer3D::getInstance(SANS_FONT_FAMILY); switch(type) { case CHAT: diff --git a/libraries/render-utils/src/TextRenderer3D.cpp b/libraries/render-utils/src/TextRenderer3D.cpp index 5894a2a258..d202d89aba 100644 --- a/libraries/render-utils/src/TextRenderer3D.cpp +++ b/libraries/render-utils/src/TextRenderer3D.cpp @@ -30,11 +30,6 @@ #include "GeometryCache.h" #include "DeferredLightingEffect.h" -// FIXME support the shadow effect, or remove it from the API -// FIXME figure out how to improve the anti-aliasing on the -// interior of the outline fonts -const float DEFAULT_POINT_SIZE = 12; - // Helper functions for reading binary data from an IO device template void readStream(QIODevice& in, T& t) { @@ -117,7 +112,7 @@ public: // Render string to batch void drawString(gpu::Batch& batch, float x, float y, const QString& str, - const glm::vec4& color, TextRenderer3D::EffectType effectType, + const glm::vec4* color, TextRenderer3D::EffectType effectType, const glm::vec2& bound); private: @@ -367,7 +362,7 @@ void Font3D::setupGPU() { } } -void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color, +void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4* color, TextRenderer3D::EffectType effectType, const glm::vec2& bounds) { if (str == "") { return; @@ -429,39 +424,33 @@ void Font3D::drawString(gpu::Batch& batch, float x, float y, const QString& str, setupGPU(); batch.setPipeline(_pipeline); batch.setUniformTexture(_fontLoc, _texture); - batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)&color); batch._glUniform1i(_outlineLoc, (effectType == TextRenderer3D::OUTLINE_EFFECT)); + batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)color); batch.setInputFormat(_format); batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride); batch.draw(gpu::QUADS, _numVertices, 0); } -TextRenderer3D* TextRenderer3D::getInstance(const char* family, float pointSize, - int weight, bool italic, EffectType effect, int effectThickness, - const QColor& color) { - if (pointSize < 0) { - pointSize = DEFAULT_POINT_SIZE; - } - return new TextRenderer3D(family, pointSize, weight, italic, effect, - effectThickness, color); +TextRenderer3D* TextRenderer3D::getInstance(const char* family, + int weight, bool italic, EffectType effect, int effectThickness) { + return new TextRenderer3D(family, weight, italic, effect, effectThickness); } -TextRenderer3D::TextRenderer3D(const char* family, float pointSize, int weight, bool italic, - EffectType effect, int effectThickness, const QColor& color) : +TextRenderer3D::TextRenderer3D(const char* family, int weight, bool italic, + EffectType effect, int effectThickness) : _effectType(effect), _effectThickness(effectThickness), - _color(toGlm(color)), _font(loadFont3D(family)) { if (!_font) { qWarning() << "Unable to load font with family " << family; _font = loadFont3D("Courier"); } if (1 != _effectThickness) { - qWarning() << "Effect thickness not current supported"; + qWarning() << "Effect thickness not currently supported"; } if (NO_EFFECT != _effectType && OUTLINE_EFFECT != _effectType) { - qWarning() << "Effect thickness not current supported"; + qWarning() << "Effect type not currently supported"; } } @@ -486,11 +475,9 @@ void TextRenderer3D::draw(gpu::Batch& batch, float x, float y, const QString& st const glm::vec2& bounds) { // The font does all the OpenGL work if (_font) { - glm::vec4 actualColor(color); - if (actualColor.r < 0) { - actualColor = _color; - } - _font->drawString(batch, x, y, str, actualColor, _effectType, bounds); + // Cache color so that the pointer stays valid. + _color = color; + _font->drawString(batch, x, y, str, &_color, _effectType, bounds); } } diff --git a/libraries/render-utils/src/TextRenderer3D.h b/libraries/render-utils/src/TextRenderer3D.h index 9f6a16d743..c4200a8d23 100644 --- a/libraries/render-utils/src/TextRenderer3D.h +++ b/libraries/render-utils/src/TextRenderer3D.h @@ -39,25 +39,24 @@ class Batch; class Font3D; // TextRenderer3D is actually a fairly thin wrapper around a Font class -// defined in the cpp file. +// defined in the cpp file. class TextRenderer3D { public: enum EffectType { NO_EFFECT, SHADOW_EFFECT, OUTLINE_EFFECT }; - static TextRenderer3D* getInstance(const char* family, float pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255)); - + static TextRenderer3D* getInstance(const char* family, int weight = -1, bool italic = false, + EffectType effect = NO_EFFECT, int effectThickness = 1); ~TextRenderer3D(); glm::vec2 computeExtent(const QString& str) const; - float getFontSize() const; + float getFontSize() const; // Pixel size - void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(-1.0f), - const glm::vec2& bounds = glm::vec2(-1.0f)); + void draw(gpu::Batch& batch, float x, float y, const QString& str, const glm::vec4& color = glm::vec4(1.0f), + const glm::vec2& bounds = glm::vec2(-1.0f)); private: - TextRenderer3D(const char* family, float pointSize = -1, int weight = -1, bool italic = false, - EffectType effect = NO_EFFECT, int effectThickness = 1, const QColor& color = QColor(255, 255, 255)); + TextRenderer3D(const char* family, int weight = -1, bool italic = false, + EffectType effect = NO_EFFECT, int effectThickness = 1); // the type of effect to apply const EffectType _effectType; @@ -66,7 +65,7 @@ private: const int _effectThickness; // text color - const glm::vec4 _color; + glm::vec4 _color; Font3D* _font; }; From 70a020c7e30ac24509b27ae7bdbef0dc4401973b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 19:58:43 +0200 Subject: [PATCH 09/26] BevelRect use triangle strips --- libraries/render-utils/src/GeometryCache.cpp | 48 +++++++++----------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 8fb10beca6..926d894a2f 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1026,7 +1026,7 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int } const int FLOATS_PER_VERTEX = 2; // vertices - const int NUM_VERTICES = 12; + const int NUM_VERTICES = 8; if (!details.isCreated) { @@ -1055,51 +1055,45 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int GLfloat vertexBuffer[vertexPoints]; // only vertices, no normals because we're a 2D quad int vertexPoint = 0; - // left side quad + // Triangle strip points + // 4 ------ 6 + // / \ + // 2 8 + // | | + // 1 7 + // \ / + // 3 ------ 5 + + // 1 vertexBuffer[vertexPoint++] = x; vertexBuffer[vertexPoint++] = y + bevelDistance; - - vertexBuffer[vertexPoint++] = x + bevelDistance; - vertexBuffer[vertexPoint++] = y; - - vertexBuffer[vertexPoint++] = x + bevelDistance; - vertexBuffer[vertexPoint++] = y + height; - + // 2 vertexBuffer[vertexPoint++] = x; vertexBuffer[vertexPoint++] = y + height - bevelDistance; - - // middle quad + // 3 vertexBuffer[vertexPoint++] = x + bevelDistance; vertexBuffer[vertexPoint++] = y; - - vertexBuffer[vertexPoint++] = x + width - bevelDistance; - vertexBuffer[vertexPoint++] = y; - - vertexBuffer[vertexPoint++] = x + width - bevelDistance; - vertexBuffer[vertexPoint++] = y + height; - + // 4 vertexBuffer[vertexPoint++] = x + bevelDistance; vertexBuffer[vertexPoint++] = y + height; - - // right side quad + // 5 vertexBuffer[vertexPoint++] = x + width - bevelDistance; vertexBuffer[vertexPoint++] = y; - + // 6 + vertexBuffer[vertexPoint++] = x + width - bevelDistance; + vertexBuffer[vertexPoint++] = y + height; + // 7 vertexBuffer[vertexPoint++] = x + width; vertexBuffer[vertexPoint++] = y + bevelDistance; - + // 8 vertexBuffer[vertexPoint++] = x + width; vertexBuffer[vertexPoint++] = y + height - bevelDistance; - vertexBuffer[vertexPoint++] = x + width - bevelDistance; - vertexBuffer[vertexPoint++] = y + height; - int compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | ((int(color.z * 255.0f) & 0xFF) << 16) | ((int(color.w * 255.0f) & 0xFF) << 24); int colors[NUM_VERTICES] = { compactColor, compactColor, compactColor, compactColor, - compactColor, compactColor, compactColor, compactColor, compactColor, compactColor, compactColor, compactColor }; @@ -1109,7 +1103,7 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int batch.setInputFormat(details.streamFormat); batch.setInputStream(0, *details.stream); - batch.draw(gpu::QUADS, details.vertices, 0); + batch.draw(gpu::TRIANGLE_STRIP, details.vertices, 0); } void GeometryCache::renderQuad(const glm::vec2& minCorner, const glm::vec2& maxCorner, const glm::vec4& color, int id) { From 254f05072fbaa8c14ebc51a91f72989f24dd75fd Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 20:05:38 +0200 Subject: [PATCH 10/26] Fix inverted if --- libraries/shared/src/Transform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index f3b5b14385..7e2bf83ed7 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -323,7 +323,7 @@ inline void Transform::setScale(const Vec3& scale) { } inline void Transform::postScale(float scale) { - if (isValidScale(scale) || scale == 1.0f) { + if (!isValidScale(scale) || scale == 1.0f) { return; } if (isScaling()) { From a9d2bb1e1c6b815c0953dd8e39ea23a2d69684a2 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 20:07:35 +0200 Subject: [PATCH 11/26] Coding standard --- libraries/model/src/model/Skybox.cpp | 4 ++-- libraries/octree/src/ViewFrustum.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/model/src/model/Skybox.cpp b/libraries/model/src/model/Skybox.cpp index 933c737b83..10199adda3 100755 --- a/libraries/model/src/model/Skybox.cpp +++ b/libraries/model/src/model/Skybox.cpp @@ -72,7 +72,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky thePipeline = gpu::PipelinePointer(gpu::Pipeline::create(skyShader, skyState)); - const float CLIP = 1.0; + const float CLIP = 1.0f; const glm::vec2 vertices[4] = { {-CLIP, -CLIP}, {CLIP, -CLIP}, {-CLIP, CLIP}, {CLIP, CLIP}}; theBuffer.reset(new gpu::Buffer(sizeof(vertices), (const gpu::Byte*) vertices)); @@ -110,7 +110,7 @@ void Skybox::render(gpu::Batch& batch, const ViewFrustum& viewFrustum, const Sky } else { // skybox has no cubemap, just clear the color buffer auto color = skybox.getColor(); - batch.clearFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(color, 0.0f), 0.f, 0); + batch.clearFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(color, 0.0f), 0.0f, 0); } } diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 80f0023970..415552f1d6 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -545,9 +545,9 @@ void ViewFrustum::printDebugDetails() const { glm::vec2 ViewFrustum::projectPoint(glm::vec3 point, bool& pointInView) const { - glm::vec4 pointVec4 = glm::vec4(point,1); + glm::vec4 pointVec4 = glm::vec4(point, 1.0f); glm::vec4 projectedPointVec4 = _ourModelViewProjectionMatrix * pointVec4; - pointInView = (projectedPointVec4.w > 0); // math! If the w result is negative then the point is behind the viewer + pointInView = (projectedPointVec4.w > 0.0f); // math! If the w result is negative then the point is behind the viewer // what happens with w is 0??? float x = projectedPointVec4.x / projectedPointVec4.w; From 8a3a7e5b7f7ffc13d08eadc67179cd9f253e6cfc Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Tue, 16 Jun 2015 20:30:49 +0200 Subject: [PATCH 12/26] Reorder triangle strip --- libraries/render-utils/src/GeometryCache.cpp | 28 ++++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 926d894a2f..7f7350fee7 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1056,38 +1056,38 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int int vertexPoint = 0; // Triangle strip points - // 4 ------ 6 - // / \ - // 2 8 - // | | - // 1 7 - // \ / // 3 ------ 5 + // / \ + // 1 7 + // | | + // 2 8 + // \ / + // 4 ------ 6 // 1 vertexBuffer[vertexPoint++] = x; - vertexBuffer[vertexPoint++] = y + bevelDistance; + vertexBuffer[vertexPoint++] = y + height - bevelDistance; // 2 vertexBuffer[vertexPoint++] = x; - vertexBuffer[vertexPoint++] = y + height - bevelDistance; + vertexBuffer[vertexPoint++] = y + bevelDistance; // 3 vertexBuffer[vertexPoint++] = x + bevelDistance; - vertexBuffer[vertexPoint++] = y; + vertexBuffer[vertexPoint++] = y + height; // 4 vertexBuffer[vertexPoint++] = x + bevelDistance; - vertexBuffer[vertexPoint++] = y + height; + vertexBuffer[vertexPoint++] = y; // 5 vertexBuffer[vertexPoint++] = x + width - bevelDistance; - vertexBuffer[vertexPoint++] = y; + vertexBuffer[vertexPoint++] = y + height; // 6 vertexBuffer[vertexPoint++] = x + width - bevelDistance; - vertexBuffer[vertexPoint++] = y + height; + vertexBuffer[vertexPoint++] = y; // 7 vertexBuffer[vertexPoint++] = x + width; - vertexBuffer[vertexPoint++] = y + bevelDistance; + vertexBuffer[vertexPoint++] = y + height - bevelDistance; // 8 vertexBuffer[vertexPoint++] = x + width; - vertexBuffer[vertexPoint++] = y + height - bevelDistance; + vertexBuffer[vertexPoint++] = y + bevelDistance; int compactColor = ((int(color.x * 255.0f) & 0xFF)) | ((int(color.y * 255.0f) & 0xFF) << 8) | From 1cab853f1849b2bf7dd2ef354c1c36c98f587e18 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 16:03:48 +0200 Subject: [PATCH 13/26] Better guard Transform scale --- libraries/shared/src/Transform.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/shared/src/Transform.h b/libraries/shared/src/Transform.h index 7e2bf83ed7..e961f379c8 100644 --- a/libraries/shared/src/Transform.h +++ b/libraries/shared/src/Transform.h @@ -29,7 +29,7 @@ inline bool isValidScale(glm::vec3 scale) { } inline bool isValidScale(float scale) { - bool result = scale != 0.0f; + bool result = scale != 0.0f && !glm::isnan(scale) && !glm::isinf(scale); assert(result); return result; } From e1b5a3c204078dd3bb21fd4a9687c597ca83bf5a Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 16:11:08 +0200 Subject: [PATCH 14/26] Fix display name transform They now have a fixed pixel size and ar pixel aligned --- interface/src/avatar/Avatar.cpp | 155 +++++++++++++++----------------- interface/src/avatar/Avatar.h | 4 +- 2 files changed, 74 insertions(+), 85 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 9b1d161177..89847d6cd6 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -509,10 +509,9 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo const float DISPLAYNAME_DISTANCE = 20.0f; setShowDisplayName(distanceToTarget < DISPLAYNAME_DISTANCE); - auto cameraMode = Application::getInstance()->getCamera()->getMode(); if (!isMyAvatar() || cameraMode != CAMERA_MODE_FIRST_PERSON) { - renderDisplayName(batch); + renderDisplayName(batch, *frustum); } } @@ -654,7 +653,7 @@ float Avatar::getBillboardSize() const { } glm::vec3 Avatar::getDisplayNamePosition() const { - glm::vec3 namePosition; + glm::vec3 namePosition(0.0f); if (getSkeletonModel().getNeckPosition(namePosition)) { namePosition += getBodyUpDirection() * getHeadHeight() * 1.1f; } else { @@ -664,78 +663,68 @@ glm::vec3 Avatar::getDisplayNamePosition() const { return namePosition; } -float Avatar::calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) const { - - // We need to compute the scale factor such as the text remains with fixed size respect to window coordinates - // We project a unit vector and check the difference in screen coordinates, to check which is the - // correction scale needed - // save the matrices for later scale correction factor - // The up vector must be relative to the rotation current rotation matrix: - // we set the identity +Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize) const { + Transform result; + // We assume textPosition is whithin the frustum + glm::vec3 textPosition = getDisplayNamePosition(); + + // Compute viewProjection matrix + glm::mat4 projMat, viewMat; + Transform view; + frustum.evalProjectionMatrix(projMat); + frustum.evalViewTransform(view); + glm::mat4 viewProj = projMat * view.getInverseMatrix(viewMat); + + // Used to determine correct scale glm::vec3 testPoint0 = textPosition; - glm::vec3 testPoint1 = textPosition + (Application::getInstance()->getCamera()->getRotation() * IDENTITY_UP); - - double textWindowHeight; - + glm::vec3 testPoint1 = testPoint0 + glm::normalize(frustum.getUp()); + // testPoints projections + glm::vec4 p0 = viewProj * glm::vec4(testPoint0, 1.0); + glm::vec4 p1 = viewProj * glm::vec4(testPoint1, 1.0); + + // TODO REMOVE vvv GLint viewportMatrix[4]; glGetIntegerv(GL_VIEWPORT, viewportMatrix); glm::dmat4 modelViewMatrix; - float windowSizeX = viewportMatrix[2] - viewportMatrix[0]; float windowSizeY = viewportMatrix[3] - viewportMatrix[1]; - - glm::dmat4 projectionMatrix; - Application::getInstance()->getModelViewMatrix(&modelViewMatrix); - Application::getInstance()->getProjectionMatrix(&projectionMatrix); - - - glm::dvec4 p0 = modelViewMatrix * glm::dvec4(testPoint0, 1.0); - p0 = projectionMatrix * p0; - glm::dvec2 result0 = glm::vec2(windowSizeX * (p0.x / p0.w + 1.0f) * 0.5f, windowSizeY * (p0.y / p0.w + 1.0f) * 0.5f); - - glm::dvec4 p1 = modelViewMatrix * glm::dvec4(testPoint1, 1.0); - p1 = projectionMatrix * p1; - glm::vec2 result1 = glm::vec2(windowSizeX * (p1.x / p1.w + 1.0f) * 0.5f, windowSizeY * (p1.y / p1.w + 1.0f) * 0.5f); - textWindowHeight = abs(result1.y - result0.y); - - // need to scale to compensate for the font resolution due to the device - float scaleFactor = QApplication::desktop()->windowHandle()->devicePixelRatio() * - ((textWindowHeight > EPSILON) ? 1.0f / textWindowHeight : 1.0f); - if (inHMD) { - const float HMDMODE_NAME_SCALE = 0.65f; - scaleFactor *= HMDMODE_NAME_SCALE; - } else { - scaleFactor *= Application::getInstance()->getRenderResolutionScale(); - } - return scaleFactor; + // TODO REMOVE ^^^ + + const float DESIRED_HIGHT_ON_SCREEN = 25; // In pixels (this is double on retinas) + + // Projected point are between -1.0f and 1.0f, hence 0.5f * windowSizeY + double pixelHeight = 0.5f * windowSizeY * glm::abs((p1.y / p1.w) - (p0.y / p0.w)); // + // Handles pixel density (especially for macs retina displays) + double devicePixelRatio = qApp->getDevicePixelRatio() * qApp->getRenderResolutionScale(); // pixels / unit + + // Compute correct scale to apply + float scale = DESIRED_HIGHT_ON_SCREEN / (fontSize * pixelHeight) * devicePixelRatio; + + float clipToPix = 0.5f * windowSizeY / p1.w; // Got from clip to pixel coordinates + glm::vec4 screenPos = clipToPix * p1; // in pixels coords + glm::vec4 screenOffset = (glm::round(screenPos) - screenPos) / clipToPix; // in clip coords + glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight; + + result.setTranslation(textPosition); + result.setRotation(frustum.getOrientation()); // Always face the screen + + // Pixel alignment + result.postTranslate(worldOffset); + + result.setScale(scale); + return result; } -void Avatar::renderDisplayName(gpu::Batch& batch) const { +void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) const { bool shouldShowReceiveStats = DependencyManager::get()->shouldShowReceiveStats() && !isMyAvatar(); + // If we have nothing to draw, or it's tottaly transparent, return if ((_displayName.isEmpty() && !shouldShowReceiveStats) || _displayNameAlpha == 0.0f) { return; } - - // which viewing mode? - bool inHMD = Application::getInstance()->isHMDMode(); - - glm::vec3 textPosition = getDisplayNamePosition(); - - // we need "always facing camera": we must remove the camera rotation from the stac - glm::quat rotation = Application::getInstance()->getCamera()->getRotation(); - - // TODO: Fix scaling - at some point this or the text rendering changed in scale. - float scaleFactor = calculateDisplayNameScaleFactor(textPosition, inHMD); - scaleFactor /= 3.5f; - - Transform textTransform; - textTransform.setTranslation(textPosition); - textTransform.setRotation(rotation); - textTransform.setScale(scaleFactor); + auto renderer = textRenderer(DISPLAYNAME); // optionally render timing stats for this avatar with the display name QString renderedDisplayName = _displayName; - if (shouldShowReceiveStats) { float kilobitsPerSecond = getAverageBytesReceivedPerSecond() / (float) BYTES_PER_KILOBIT; @@ -743,42 +732,43 @@ void Avatar::renderDisplayName(gpu::Batch& batch) const { if (!renderedDisplayName.isEmpty()) { statsFormat.prepend(" - "); } - - QString statsText = statsFormat.arg(QString::number(kilobitsPerSecond, 'f', 2)).arg(getReceiveRate()); - renderedDisplayName += statsText; + renderedDisplayName += statsFormat.arg(QString::number(kilobitsPerSecond, 'f', 2)).arg(getReceiveRate()); } - glm::vec2 extent = textRenderer(DISPLAYNAME)->computeExtent(renderedDisplayName); - QRect nameDynamicRect = QRect(0, 0, (int)extent.x, (int)extent.y);; - int text_x = -nameDynamicRect.width() / 2; - int text_y = -nameDynamicRect.height() / 2; + // Compute display name extent/position offset + glm::vec2 extent = renderer->computeExtent(renderedDisplayName); + QRect nameDynamicRect = QRect(0, 0, (int)extent.x, (int)extent.y); + const int text_x = -nameDynamicRect.width() / 2; + const int text_y = -nameDynamicRect.height() / 2; - // draw a gray background - int left = text_x; - int right = left + nameDynamicRect.width(); - int bottom = text_y; - int top = bottom + nameDynamicRect.height(); + // Compute background position/size + static const float SLIGHTLY_BEHIND = -0.001f; const int border = 0.1f * nameDynamicRect.height(); - bottom -= border; - left -= border; - top += border; - right += border; - int bevelDistance = 0.1f * (top - bottom); + const int left = text_x - border; + const int bottom = text_y - border; + const int width = nameDynamicRect.width() + 2.0f * border; + const int height = nameDynamicRect.height() + 2.0f * border; + const int bevelDistance = 0.1f * height; + // Display name and background colors glm::vec4 textColor(0.93f, 0.93f, 0.93f, _displayNameAlpha); glm::vec4 backgroundColor(0.2f, 0.2f, 0.2f, (_displayNameAlpha / DISPLAYNAME_ALPHA) * DISPLAYNAME_BACKGROUND_ALPHA); + // Compute display name transform + auto textTransform = calculateDisplayNameTransform(frustum, renderer->getFontSize()); + + // Render background slightly behind to avoid z-fighting auto backgroundTransform = textTransform; - backgroundTransform.postTranslate(glm::vec3(0.0f, 0.0f, -0.001f)); + backgroundTransform.postTranslate(glm::vec3(0.0f, 0.0f, SLIGHTLY_BEHIND)); batch.setModelTransform(backgroundTransform); DependencyManager::get()->bindSimpleProgram(batch); - DependencyManager::get()->renderBevelCornersRect(batch, left, bottom, right - left, top - bottom, + DependencyManager::get()->renderBevelCornersRect(batch, left, bottom, width, height, bevelDistance, backgroundColor); + // Render actual name QByteArray nameUTF8 = renderedDisplayName.toLocal8Bit(); - batch.setModelTransform(textTransform); - textRenderer(DISPLAYNAME)->draw(batch, text_x, -text_y, nameUTF8.data(), textColor); + renderer->draw(batch, text_x, -text_y, nameUTF8.data(), textColor); } bool Avatar::findRayIntersection(RayIntersectionInfo& intersection) const { @@ -1105,7 +1095,7 @@ void Avatar::setShowDisplayName(bool showDisplayName) { } // For myAvatar, the alpha update is not done (called in simulate for other avatars) - if (DependencyManager::get()->getMyAvatar() == this) { + if (isMyAvatar()) { if (showDisplayName) { _displayNameAlpha = DISPLAYNAME_ALPHA; } else { @@ -1118,7 +1108,6 @@ void Avatar::setShowDisplayName(bool showDisplayName) { } else { _displayNameTargetAlpha = 0.0f; } - } // virtual diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 6c6082ca33..ecb16f6010 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -234,8 +234,8 @@ protected: float getPelvisFloatingHeight() const; glm::vec3 getDisplayNamePosition() const; - float calculateDisplayNameScaleFactor(const glm::vec3& textPosition, bool inHMD) const; - void renderDisplayName(gpu::Batch& batch) const; + Transform calculateDisplayNameTransform(const ViewFrustum& frustum, float fontSize) const; + void renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) const; virtual void renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, bool postLighting, float glowLevel = 0.0f); virtual bool shouldRenderHead(const RenderArgs* renderArgs, const glm::vec3& cameraPosition) const; virtual void fixupModelsInScene(); From 3b41a8f209d50572b24ecaa795a081b03256c7a8 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 16:31:38 +0200 Subject: [PATCH 15/26] Cancel display names roll This is annoying in HMD --- interface/src/avatar/Avatar.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 89847d6cd6..22ac352941 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -699,17 +699,21 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa // Compute correct scale to apply float scale = DESIRED_HIGHT_ON_SCREEN / (fontSize * pixelHeight) * devicePixelRatio; + // Compute pixel alignment offset float clipToPix = 0.5f * windowSizeY / p1.w; // Got from clip to pixel coordinates glm::vec4 screenPos = clipToPix * p1; // in pixels coords glm::vec4 screenOffset = (glm::round(screenPos) - screenPos) / clipToPix; // in clip coords glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight; + // Compute orientation + glm::vec3 eulerAngles = ::safeEulerAngles(frustum.getOrientation()); + eulerAngles.z = 0.0f; // Cancel roll + glm::quat orientation(eulerAngles); // back to quaternions + + // Set transform (The order IS important) result.setTranslation(textPosition); - result.setRotation(frustum.getOrientation()); // Always face the screen - - // Pixel alignment - result.postTranslate(worldOffset); - + result.setRotation(orientation); // Always face the screen + result.postTranslate(worldOffset); // Pixel alignment result.setScale(scale); return result; } From fb6de91cbe17cac28fe2acd6f0c5c3d06ea064b8 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 18:04:16 +0200 Subject: [PATCH 16/26] HACK Prevent head hight value explosion --- interface/src/avatar/Avatar.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 22ac352941..f5f2b3778f 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -1075,7 +1075,12 @@ float Avatar::getSkeletonHeight() const { float Avatar::getHeadHeight() const { Extents extents = getHead()->getFaceModel().getMeshExtents(); if (!extents.isEmpty() && extents.isValid()) { - return extents.maximum.y - extents.minimum.y; + + // HACK: We have a really odd case when fading out for some models where this value explodes + float result = extents.maximum.y - extents.minimum.y; + if (result >= 0.0f && result < 100.0f * _scale ) { + return result; + } } extents = _skeletonModel.getMeshExtents(); From be261cd0383382a799a164d35b50d46d6d930496 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 18:05:23 +0200 Subject: [PATCH 17/26] Increase anti z-fighting value --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index f5f2b3778f..550883b033 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -746,7 +746,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) co const int text_y = -nameDynamicRect.height() / 2; // Compute background position/size - static const float SLIGHTLY_BEHIND = -0.001f; + static const float SLIGHTLY_BEHIND = -0.01f; const int border = 0.1f * nameDynamicRect.height(); const int left = text_x - border; const int bottom = text_y - border; From 30fbd376458702f7b006e45016139f9547df13e1 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 18:08:04 +0200 Subject: [PATCH 18/26] Transmit normal to text rendering shader --- libraries/render-utils/src/sdf_text3D.slf | 11 ++++++++--- libraries/render-utils/src/sdf_text3D.slv | 6 ++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libraries/render-utils/src/sdf_text3D.slf b/libraries/render-utils/src/sdf_text3D.slf index 07ca75237b..361f8454ab 100644 --- a/libraries/render-utils/src/sdf_text3D.slf +++ b/libraries/render-utils/src/sdf_text3D.slf @@ -14,8 +14,11 @@ uniform sampler2D Font; uniform bool Outline; uniform vec4 Color; -const float gamma = 2.6; -const float smoothing = 100.0; +// the interpolated normal +varying vec4 interpolatedNormal; + +const float gamma = 2.2; +const float smoothing = 64.0; const float interiorCutoff = 0.8; const float outlineExpansion = 0.2; @@ -43,5 +46,7 @@ void main() { } // final color - gl_FragColor = vec4(Color.rgb, Color.a * a); + gl_FragData[0] = vec4(Color.rgb, Color.a * a); + gl_FragData[1] = vec4(interpolatedNormal.xyz, 0.0) * 0.5 + vec4(0.5, 0.5, 0.5, 1.0); + gl_FragData[2] = vec4(0.0); } \ No newline at end of file diff --git a/libraries/render-utils/src/sdf_text3D.slv b/libraries/render-utils/src/sdf_text3D.slv index f7c35a257c..6838650e75 100644 --- a/libraries/render-utils/src/sdf_text3D.slv +++ b/libraries/render-utils/src/sdf_text3D.slv @@ -13,6 +13,9 @@ <$declareStandardTransform()$> +// the interpolated normal +varying vec4 interpolatedNormal; + void main() { gl_TexCoord[0] = gl_MultiTexCoord0; @@ -20,4 +23,7 @@ void main() { TransformCamera cam = getTransformCamera(); TransformObject obj = getTransformObject(); <$transformModelToClipPos(cam, obj, gl_Vertex, gl_Position)$> + <$transformModelToEyeDir(cam, obj, gl_Normal, interpolatedNormal.xyz)$> + + interpolatedNormal = vec4(normalize(interpolatedNormal.xyz), 0.0); } \ No newline at end of file From 045a6a6ad9d1772c5ff21be4f13d3f9ab606137b Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 19:25:20 +0200 Subject: [PATCH 19/26] Use render args frustum --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 550883b033..381c89fd40 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -511,7 +511,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition, boo auto cameraMode = Application::getInstance()->getCamera()->getMode(); if (!isMyAvatar() || cameraMode != CAMERA_MODE_FIRST_PERSON) { - renderDisplayName(batch, *frustum); + renderDisplayName(batch, *renderArgs->_viewFrustum); } } From c38fa46eb14e90b7313ed88c6b50dd5995804a5c Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 19:25:40 +0200 Subject: [PATCH 20/26] Increase anti z-fighting value --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 381c89fd40..24291f8477 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -746,7 +746,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum) co const int text_y = -nameDynamicRect.height() / 2; // Compute background position/size - static const float SLIGHTLY_BEHIND = -0.01f; + static const float SLIGHTLY_BEHIND = -0.05f; const int border = 0.1f * nameDynamicRect.height(); const int left = text_x - border; const int bottom = text_y - border; From d0f27f164872975d1ad603b2906d6aca6e0988ee Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 20:03:51 +0200 Subject: [PATCH 21/26] Change display names size --- interface/src/avatar/Avatar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 24291f8477..9672d22c69 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -689,7 +689,7 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa float windowSizeY = viewportMatrix[3] - viewportMatrix[1]; // TODO REMOVE ^^^ - const float DESIRED_HIGHT_ON_SCREEN = 25; // In pixels (this is double on retinas) + const float DESIRED_HIGHT_ON_SCREEN = 20; // In pixels (this is double on retinas) // Projected point are between -1.0f and 1.0f, hence 0.5f * windowSizeY double pixelHeight = 0.5f * windowSizeY * glm::abs((p1.y / p1.w) - (p0.y / p0.w)); // From 5166d833a76eb37056448e68e8e29586bf43afab Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 22:15:28 +0200 Subject: [PATCH 22/26] Make array size a constexpr --- libraries/render-utils/src/GeometryCache.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index 7f7350fee7..bdd0c210aa 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1025,11 +1025,11 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int #endif // def WANT_DEBUG } - const int FLOATS_PER_VERTEX = 2; // vertices - const int NUM_VERTICES = 8; - if (!details.isCreated) { - + static const int FLOATS_PER_VERTEX = 2; // vertices + static const int NUM_VERTICES = 8; + static constexpr int NUM_FLOATS = NUM_VERTICES * FLOATS_PER_VERTEX; + details.isCreated = true; details.vertices = NUM_VERTICES; details.vertexSize = FLOATS_PER_VERTEX; @@ -1051,8 +1051,7 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride); - int vertexPoints = NUM_VERTICES * FLOATS_PER_VERTEX; - GLfloat vertexBuffer[vertexPoints]; // only vertices, no normals because we're a 2D quad + GLfloat vertexBuffer[NUM_FLOATS]; // only vertices, no normals because we're a 2D quad int vertexPoint = 0; // Triangle strip points From 26e8c490c3e8c5b8cca18b2588117c8140c44d9e Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 17 Jun 2015 22:43:11 +0200 Subject: [PATCH 23/26] constexpr not handled on windows --- 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 bdd0c210aa..a6602269a4 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -1028,7 +1028,7 @@ void GeometryCache::renderBevelCornersRect(gpu::Batch& batch, int x, int y, int if (!details.isCreated) { static const int FLOATS_PER_VERTEX = 2; // vertices static const int NUM_VERTICES = 8; - static constexpr int NUM_FLOATS = NUM_VERTICES * FLOATS_PER_VERTEX; + static const int NUM_FLOATS = NUM_VERTICES * FLOATS_PER_VERTEX; details.isCreated = true; details.vertices = NUM_VERTICES; From 673e1ee0cc2fb4e1cd223ac1e287fc9ab11cb2e4 Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Jun 2015 09:30:34 -0700 Subject: [PATCH 24/26] first cut and removing openGl dependency in shared --- libraries/{shared => render-utils}/src/OglplusHelpers.cpp | 0 libraries/{shared => render-utils}/src/OglplusHelpers.h | 0 libraries/shared/CMakeLists.txt | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename libraries/{shared => render-utils}/src/OglplusHelpers.cpp (100%) rename libraries/{shared => render-utils}/src/OglplusHelpers.h (100%) diff --git a/libraries/shared/src/OglplusHelpers.cpp b/libraries/render-utils/src/OglplusHelpers.cpp similarity index 100% rename from libraries/shared/src/OglplusHelpers.cpp rename to libraries/render-utils/src/OglplusHelpers.cpp diff --git a/libraries/shared/src/OglplusHelpers.h b/libraries/render-utils/src/OglplusHelpers.h similarity index 100% rename from libraries/shared/src/OglplusHelpers.h rename to libraries/render-utils/src/OglplusHelpers.h diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index c4159b1190..0b3ad05e7e 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME shared) # use setup_hifi_library macro to setup our project and link appropriate Qt modules # TODO: there isn't really a good reason to have Script linked here - let's get what is requiring it out (RegisteredMetaTypes.cpp) -setup_hifi_library(Gui Network OpenGL Script Widgets) +setup_hifi_library(Gui Network Script Widgets) setup_hifi_opengl() From 383a2c3d639746a561a36fa417f3431e3b0761aa Mon Sep 17 00:00:00 2001 From: ZappoMan Date: Thu, 18 Jun 2015 09:43:39 -0700 Subject: [PATCH 25/26] another attempt --- libraries/render-utils/CMakeLists.txt | 64 ++++++++++++++++----------- libraries/shared/CMakeLists.txt | 11 ----- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 373279b299..7feb48a52b 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -1,27 +1,37 @@ -set(TARGET_NAME render-utils) - -AUTOSCRIBE_SHADER_LIB(gpu model render) - -# pull in the resources.qrc file -qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") - -# use setup_hifi_library macro to setup our project and link appropriate Qt modules -setup_hifi_library(Widgets OpenGL Network Qml Quick Script) - -add_dependency_external_projects(glm) -find_package(GLM REQUIRED) -target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) - -if (WIN32) - if (USE_NSIGHT) - # try to find the Nsight package and add it to the build if we find it - find_package(NSIGHT) - if (NSIGHT_FOUND) - include_directories(${NSIGHT_INCLUDE_DIRS}) - add_definitions(-DNSIGHT_FOUND) - target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") - endif () - endif() -endif (WIN32) - -link_hifi_libraries(animation fbx shared gpu model render) +set(TARGET_NAME render-utils) + +AUTOSCRIBE_SHADER_LIB(gpu model render) + +# pull in the resources.qrc file +qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") + +# use setup_hifi_library macro to setup our project and link appropriate Qt modules +setup_hifi_library(Widgets OpenGL Network Qml Quick Script) + +setup_hifi_opengl() + +add_dependency_external_projects(glm) +find_package(GLM REQUIRED) +target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) + +if (WIN32) + if (USE_NSIGHT) + # try to find the Nsight package and add it to the build if we find it + find_package(NSIGHT) + if (NSIGHT_FOUND) + include_directories(${NSIGHT_INCLUDE_DIRS}) + add_definitions(-DNSIGHT_FOUND) + target_link_libraries(${TARGET_NAME} "${NSIGHT_LIBRARIES}") + endif () + endif() + + add_dependency_external_projects(boostconfig) + find_package(BoostConfig REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) + + add_dependency_external_projects(oglplus) + find_package(OGLPLUS REQUIRED) + target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) +endif (WIN32) + +link_hifi_libraries(animation fbx shared gpu model render) diff --git a/libraries/shared/CMakeLists.txt b/libraries/shared/CMakeLists.txt index 0b3ad05e7e..8deda7f4b1 100644 --- a/libraries/shared/CMakeLists.txt +++ b/libraries/shared/CMakeLists.txt @@ -4,18 +4,7 @@ set(TARGET_NAME shared) # TODO: there isn't really a good reason to have Script linked here - let's get what is requiring it out (RegisteredMetaTypes.cpp) setup_hifi_library(Gui Network Script Widgets) -setup_hifi_opengl() - add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -if (WIN32) - add_dependency_external_projects(boostconfig) - find_package(BoostConfig REQUIRED) - target_include_directories(${TARGET_NAME} PUBLIC ${BOOSTCONFIG_INCLUDE_DIRS}) - - add_dependency_external_projects(oglplus) - find_package(OGLPLUS REQUIRED) - target_include_directories(${TARGET_NAME} PUBLIC ${OGLPLUS_INCLUDE_DIRS}) -endif() \ No newline at end of file From 7d707447ca749ed7a3aef93b3d2b00666bcdce77 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Thu, 18 Jun 2015 11:07:50 -0700 Subject: [PATCH 26/26] move multi-line function out of header --- libraries/entities/src/PolyVoxEntityItem.cpp | 7 +++++++ libraries/entities/src/PolyVoxEntityItem.h | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libraries/entities/src/PolyVoxEntityItem.cpp b/libraries/entities/src/PolyVoxEntityItem.cpp index 84fbf11311..6f284caeaa 100644 --- a/libraries/entities/src/PolyVoxEntityItem.cpp +++ b/libraries/entities/src/PolyVoxEntityItem.cpp @@ -168,3 +168,10 @@ void PolyVoxEntityItem::debugDump() const { qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions()); qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now); } + +void PolyVoxEntityItem::setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { + if (voxelSurfaceStyle == _voxelSurfaceStyle) { + return; + } + updateVoxelSurfaceStyle(voxelSurfaceStyle); +} diff --git a/libraries/entities/src/PolyVoxEntityItem.h b/libraries/entities/src/PolyVoxEntityItem.h index 39d67fb9a3..9e20187195 100644 --- a/libraries/entities/src/PolyVoxEntityItem.h +++ b/libraries/entities/src/PolyVoxEntityItem.h @@ -61,12 +61,7 @@ class PolyVoxEntityItem : public EntityItem { SURFACE_EDGED_CUBIC }; - void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle) { - if (voxelSurfaceStyle == _voxelSurfaceStyle) { - return; - } - updateVoxelSurfaceStyle(voxelSurfaceStyle); - } + void setVoxelSurfaceStyle(PolyVoxSurfaceStyle voxelSurfaceStyle); // this other version of setVoxelSurfaceStyle is needed for SET_ENTITY_PROPERTY_FROM_PROPERTIES void setVoxelSurfaceStyle(uint16_t voxelSurfaceStyle) { setVoxelSurfaceStyle((PolyVoxSurfaceStyle) voxelSurfaceStyle); } virtual PolyVoxSurfaceStyle getVoxelSurfaceStyle() const { return _voxelSurfaceStyle; }