From 6f5b37ec871708760210a22a9f14eee693e251e3 Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 26 Jun 2019 16:36:04 -0700 Subject: [PATCH 01/15] removed extraneous conversion to SRGB and back during deferred rendering --- .../Basic2DWindowOpenGLDisplayPlugin.cpp | 6 ------ .../src/display-plugins/OpenGLDisplayPlugin.cpp | 6 +----- .../src/display-plugins/OpenGLDisplayPlugin.h | 1 - .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 4 ++++ libraries/render-utils/src/toneMapping.slf | 15 ++++++++++++--- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp index b8912d95b6..a35496f88e 100644 --- a/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/Basic2DWindowOpenGLDisplayPlugin.cpp @@ -113,14 +113,8 @@ gpu::PipelinePointer Basic2DWindowOpenGLDisplayPlugin::getRenderTexturePipeline( #if defined(Q_OS_ANDROID) return _linearToSRGBPipeline; #else - -#ifndef USE_GLES - return _SRGBToLinearPipeline; -#else return _drawTexturePipeline; #endif - -#endif } void Basic2DWindowOpenGLDisplayPlugin::compositeExtra() { diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 75cdf5ebef..f90dcaa599 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -642,7 +642,7 @@ void OpenGLDisplayPlugin::compositeScene() { batch.setStateScissorRect(ivec4(uvec2(), _compositeFramebuffer->getSize())); batch.resetViewTransform(); batch.setProjectionTransform(mat4()); - batch.setPipeline(getCompositeScenePipeline()); + batch.setPipeline(_drawTexturePipeline); batch.setResourceTexture(0, _currentFrame->framebuffer->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); }); @@ -964,7 +964,3 @@ gpu::PipelinePointer OpenGLDisplayPlugin::getRenderTexturePipeline() { return _drawTexturePipeline; } -gpu::PipelinePointer OpenGLDisplayPlugin::getCompositeScenePipeline() { - return _drawTexturePipeline; -} - diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 777c74822a..85ba235e7a 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -162,7 +162,6 @@ protected: float _compositeHUDAlpha{ 1.0f }; virtual gpu::PipelinePointer getRenderTexturePipeline(); - virtual gpu::PipelinePointer getCompositeScenePipeline(); struct CursorData { QImage image; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 3952c2c90e..1323f76423 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -174,6 +174,10 @@ float HmdDisplayPlugin::getLeftCenterPixel() const { return leftCenterPixel; } +gpu::PipelinePointer HmdDisplayPlugin::getRenderTexturePipeline() { + return _drawTexturePipeline; +} + void HmdDisplayPlugin::internalPresent() { PROFILE_RANGE_EX(render, __FUNCTION__, 0xff00ff00, (uint64_t)presentCount()) diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index 3fe53d9be1..16b84babb5 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -20,6 +20,7 @@ struct ToneMappingParams { ivec4 _toneCurve_s0_s1_s2; }; +const float GAMMA_22 = 2.2; const float INV_GAMMA_22 = 1.0 / 2.2; const int ToneCurveNone = 0; const int ToneCurveGamma22 = 1; @@ -55,9 +56,17 @@ void main(void) { } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); - } else if (toneCurve == ToneCurveGamma22) { - tonedColor = pow(srcColor, vec3(INV_GAMMA_22)); - } // else None toned = src + } else if (toneCurve == ToneCurveNone) { + // For debugging purposes, we may want to see what the colors look like before the automatic OpenGL + // conversion mentioned above, so we undo it here + tonedColor = pow(srcColor, vec3(GAMMA_22)); + } else { + // toneCurve == ToneCurveGamma22 + // We use glEnable(GL_FRAMEBUFFER_SRGB), which automatically converts textures from RGB to SRGB + // when writing from an RGB framebuffer to an SRGB framebuffer (note that it doesn't do anything + // when writing from an SRGB framebuffer to an RGB framebuffer). + // Since the conversion happens automatically, we don't need to do anything in this shader + } outFragColor = vec4(tonedColor, 1.0); } From 24b6d64e344e891f0e3abd41af6b6dc4176f608c Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 26 Jun 2019 17:27:53 -0700 Subject: [PATCH 02/15] removed extraneous code for hmd --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 2 +- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 4 ---- libraries/render-utils/src/toneMapping.slf | 16 +++++++++------- plugins/oculus/src/OculusDisplayPlugin.cpp | 9 --------- plugins/oculus/src/OculusDisplayPlugin.h | 3 --- 5 files changed, 10 insertions(+), 24 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index f90dcaa599..7ae24a9238 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -905,7 +905,7 @@ OpenGLDisplayPlugin::~OpenGLDisplayPlugin() { void OpenGLDisplayPlugin::updateCompositeFramebuffer() { auto renderSize = glm::uvec2(getRecommendedRenderSize()); if (!_compositeFramebuffer || _compositeFramebuffer->getSize() != renderSize) { - _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_RGBA_32, renderSize.x, renderSize.y)); + _compositeFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create("OpenGLDisplayPlugin::composite", gpu::Element::COLOR_SRGBA_32, renderSize.x, renderSize.y)); } } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 1323f76423..3952c2c90e 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -174,10 +174,6 @@ float HmdDisplayPlugin::getLeftCenterPixel() const { return leftCenterPixel; } -gpu::PipelinePointer HmdDisplayPlugin::getRenderTexturePipeline() { - return _drawTexturePipeline; -} - void HmdDisplayPlugin::internalPresent() { PROFILE_RANGE_EX(render, __FUNCTION__, 0xff00ff00, (uint64_t)presentCount()) diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index 16b84babb5..cbdcfd26bb 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -56,17 +56,19 @@ void main(void) { } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); - } else if (toneCurve == ToneCurveNone) { - // For debugging purposes, we may want to see what the colors look like before the automatic OpenGL - // conversion mentioned above, so we undo it here - tonedColor = pow(srcColor, vec3(GAMMA_22)); - } else { - // toneCurve == ToneCurveGamma22 + } + else if (toneCurve == ToneCurveGamma22) { // We use glEnable(GL_FRAMEBUFFER_SRGB), which automatically converts textures from RGB to SRGB // when writing from an RGB framebuffer to an SRGB framebuffer (note that it doesn't do anything // when writing from an SRGB framebuffer to an RGB framebuffer). // Since the conversion happens automatically, we don't need to do anything in this shader - } + } + else { + // toneCurve == ToneCurveNone + // For debugging purposes, we may want to see what the colors look like before the automatic OpenGL + // conversion mentioned above, so we undo it here + tonedColor = pow(srcColor, vec3(GAMMA_22)); + } outFragColor = vec4(tonedColor, 1.0); } diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index f928ccb8a4..bd0c77ae57 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -124,15 +124,6 @@ void OculusDisplayPlugin::uncustomizeContext() { Parent::uncustomizeContext(); } -gpu::PipelinePointer OculusDisplayPlugin::getRenderTexturePipeline() { - //return _SRGBToLinearPipeline; - return _drawTexturePipeline; -} - -gpu::PipelinePointer OculusDisplayPlugin::getCompositeScenePipeline() { - return _SRGBToLinearPipeline; -} - static const uint64_t FRAME_BUDGET = (11 * USECS_PER_MSEC); static const uint64_t FRAME_OVER_BUDGET = (15 * USECS_PER_MSEC); diff --git a/plugins/oculus/src/OculusDisplayPlugin.h b/plugins/oculus/src/OculusDisplayPlugin.h index a892d27534..9209fd373e 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.h +++ b/plugins/oculus/src/OculusDisplayPlugin.h @@ -24,9 +24,6 @@ public: virtual QJsonObject getHardwareStats() const; - virtual gpu::PipelinePointer getRenderTexturePipeline() override; - virtual gpu::PipelinePointer getCompositeScenePipeline() override; - protected: QThread::Priority getPresentPriority() override { return QThread::TimeCriticalPriority; } From 6b79b275a9728e027e11150cdc5c6b82e2112ace Mon Sep 17 00:00:00 2001 From: Anna Date: Wed, 26 Jun 2019 18:00:49 -0700 Subject: [PATCH 03/15] fixed reinhard and filmic curves --- libraries/render-utils/src/toneMapping.slf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index cbdcfd26bb..211b2a50f4 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -51,11 +51,11 @@ void main(void) { int toneCurve = getToneCurve(); vec3 tonedColor = srcColor; if (toneCurve == ToneCurveFilmic) { - vec3 x = max(vec3(0.0), srcColor-0.004); + vec3 rgbColor = pow(srcColor, vec3(GAMMA_22)); + vec3 x = max(vec3(0.0), rgbColor-0.004); tonedColor = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); - tonedColor = pow(tonedColor, vec3(INV_GAMMA_22)); } else if (toneCurve == ToneCurveGamma22) { // We use glEnable(GL_FRAMEBUFFER_SRGB), which automatically converts textures from RGB to SRGB From 787359fdfb45ebc639158c00e385a6ba1c30adea Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 1 Jul 2019 10:52:03 -0700 Subject: [PATCH 04/15] fixed ui flipping issue --- .../display-plugins/OpenGLDisplayPlugin.cpp | 16 +++--- .../src/display-plugins/OpenGLDisplayPlugin.h | 2 +- .../display-plugins/hmd/HmdDisplayPlugin.cpp | 11 ++--- .../display-plugins/hmd/HmdDisplayPlugin.h | 4 +- ...ToSRGB.slf => DrawTextureLinearToSRGB.slf} | 2 +- ...ToSRGB.slp => DrawTextureLinearToSRGB.slp} | 0 .../gpu/src/gpu/DrawTextureMirroredX.slf | 5 +- .../gpu/src/gpu/DrawTextureMirroredX.slp | 2 +- libraries/gpu/src/gpu/DrawTextureOpaque.slf | 2 - ...Linear.slf => DrawTextureSRGBToLinear.slf} | 2 +- ...Linear.slp => DrawTextureSRGBToLinear.slp} | 0 libraries/plugins/src/plugins/DisplayPlugin.h | 2 +- .../render-utils/src/RenderCommonTask.cpp | 49 ++----------------- .../render-utils/src/RenderForwardTask.cpp | 4 +- .../render-utils/src/RenderHUDLayerTask.cpp | 2 +- libraries/render-utils/src/hmd_ui.slf | 3 +- libraries/render/src/render/Args.h | 2 +- plugins/oculus/src/OculusDisplayPlugin.cpp | 2 +- 18 files changed, 31 insertions(+), 79 deletions(-) rename libraries/gpu/src/gpu/{DrawTextureGammaLinearToSRGB.slf => DrawTextureLinearToSRGB.slf} (94%) rename libraries/gpu/src/gpu/{DrawTextureGammaLinearToSRGB.slp => DrawTextureLinearToSRGB.slp} (100%) rename libraries/gpu/src/gpu/{DrawTextureGammaSRGBToLinear.slf => DrawTextureSRGBToLinear.slf} (94%) rename libraries/gpu/src/gpu/{DrawTextureGammaSRGBToLinear.slp => DrawTextureSRGBToLinear.slp} (100%) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 7ae24a9238..83380b18d0 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -392,13 +392,11 @@ void OpenGLDisplayPlugin::customizeContext() { _drawTexturePipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), scissorState); - _linearToSRGBPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaLinearToSRGB), scissorState); + _linearToSRGBPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureLinearToSRGB), scissorState); - _SRGBToLinearPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureGammaSRGBToLinear), scissorState); + _SRGBToLinearPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureSRGBToLinear), scissorState); - _hudPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTexture), blendState); - - _mirrorHUDPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureMirroredX), blendState); + _hudPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureSRGBToLinear), blendState); _cursorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTransformedTexture), blendState); } @@ -413,7 +411,6 @@ void OpenGLDisplayPlugin::uncustomizeContext() { _SRGBToLinearPipeline.reset(); _cursorPipeline.reset(); _hudPipeline.reset(); - _mirrorHUDPipeline.reset(); _compositeFramebuffer.reset(); withPresentThreadLock([&] { @@ -582,17 +579,16 @@ void OpenGLDisplayPlugin::updateFrameData() { }); } -std::function OpenGLDisplayPlugin::getHUDOperator() { +std::function OpenGLDisplayPlugin::getHUDOperator() { auto hudPipeline = _hudPipeline; - auto hudMirrorPipeline = _mirrorHUDPipeline; auto hudStereo = isStereo(); auto hudCompositeFramebufferSize = _compositeFramebuffer->getSize(); std::array hudEyeViewports; for_each_eye([&](Eye eye) { hudEyeViewports[eye] = eyeViewport(eye); }); - return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - auto pipeline = mirror ? hudMirrorPipeline : hudPipeline; + return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture) { + auto pipeline = hudPipeline; if (pipeline && hudTexture) { batch.enableStereo(false); batch.setPipeline(pipeline); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 85ba235e7a..6fb36bff90 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -80,7 +80,7 @@ public: // Three threads, one for rendering, one for texture transfers, one reserved for the GL driver int getRequiredThreadCount() const override { return 3; } - virtual std::function getHUDOperator() override; + virtual std::function getHUDOperator() override; void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 0c7d83cdd8..2eb22723a5 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -175,7 +175,7 @@ float HmdDisplayPlugin::getLeftCenterPixel() const { } gpu::PipelinePointer HmdDisplayPlugin::getRenderTexturePipeline() { - return _SRGBToLinearPipeline; + return _drawTexturePipeline; } void HmdDisplayPlugin::internalPresent() { @@ -417,7 +417,7 @@ void HmdDisplayPlugin::HUDRenderer::build() { pipeline = gpu::Pipeline::create(program, state); } -std::function HmdDisplayPlugin::HUDRenderer::render() { +std::function HmdDisplayPlugin::HUDRenderer::render() { auto hudPipeline = pipeline; auto hudFormat = format; auto hudVertices = vertices; @@ -425,7 +425,7 @@ std::function HmdDis auto hudUniformBuffer = uniformsBuffer; auto hudUniforms = uniforms; auto hudIndexCount = indexCount; - return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { + return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture) { if (hudPipeline && hudTexture) { batch.setPipeline(hudPipeline); @@ -440,9 +440,6 @@ std::function HmdDis auto compositorHelper = DependencyManager::get(); glm::mat4 modelTransform = compositorHelper->getUiTransform(); - if (mirror) { - modelTransform = glm::scale(modelTransform, glm::vec3(-1, 1, 1)); - } batch.setModelTransform(modelTransform); batch.setResourceTexture(0, hudTexture); @@ -475,7 +472,7 @@ void HmdDisplayPlugin::compositePointer() { }); } -std::function HmdDisplayPlugin::getHUDOperator() { +std::function HmdDisplayPlugin::getHUDOperator() { return _hudRenderer.render(); } diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index 1f34e1b52a..e475da0818 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -48,7 +48,7 @@ public: void pluginUpdate() override {}; - std::function getHUDOperator() override; + std::function getHUDOperator() override; virtual StencilMaskMode getStencilMaskMode() const override { return StencilMaskMode::PAINT; } virtual gpu::PipelinePointer getRenderTexturePipeline() override; @@ -125,6 +125,6 @@ private: static const int VERTEX_STRIDE { sizeof(Vertex) }; void build(); - std::function render(); + std::function render(); } _hudRenderer; }; diff --git a/libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slf b/libraries/gpu/src/gpu/DrawTextureLinearToSRGB.slf similarity index 94% rename from libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slf rename to libraries/gpu/src/gpu/DrawTextureLinearToSRGB.slf index 3ca3a92f01..9d78e7286b 100644 --- a/libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slf +++ b/libraries/gpu/src/gpu/DrawTextureLinearToSRGB.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// DrawTextureGammaLinearToSRGB.frag +// DrawTextureLinearToSRGB.frag // // Draw texture 0 fetched at texcoord.xy, and apply linear to sRGB color space conversion // diff --git a/libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slp b/libraries/gpu/src/gpu/DrawTextureLinearToSRGB.slp similarity index 100% rename from libraries/gpu/src/gpu/DrawTextureGammaLinearToSRGB.slp rename to libraries/gpu/src/gpu/DrawTextureLinearToSRGB.slp diff --git a/libraries/gpu/src/gpu/DrawTextureMirroredX.slf b/libraries/gpu/src/gpu/DrawTextureMirroredX.slf index abb52cbe7f..acb93fa5ca 100644 --- a/libraries/gpu/src/gpu/DrawTextureMirroredX.slf +++ b/libraries/gpu/src/gpu/DrawTextureMirroredX.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// DrawTextureMirroredX.frag +// DrawTextureSRGBToLinearMirroredX.frag // // Draw texture 0 fetched at (1.0 - texcoord.x, texcoord.y) // @@ -13,6 +13,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +<@include gpu/Color.slh@> LAYOUT(binding=0) uniform sampler2D colorMap; @@ -20,5 +21,5 @@ layout(location=0) in vec2 varTexCoord0; layout(location=0) out vec4 outFragColor; void main(void) { - outFragColor = texture(colorMap, vec2(1.0 - varTexCoord0.x, varTexCoord0.y)); + outFragColor = vec4(texture(colorMap, vec2(1.0 - varTexCoord0.x, varTexCoord0.y)).xyz, 1.0); } diff --git a/libraries/gpu/src/gpu/DrawTextureMirroredX.slp b/libraries/gpu/src/gpu/DrawTextureMirroredX.slp index db9a4a4fac..e18f38ec1b 100644 --- a/libraries/gpu/src/gpu/DrawTextureMirroredX.slp +++ b/libraries/gpu/src/gpu/DrawTextureMirroredX.slp @@ -1 +1 @@ -VERTEX DrawUnitQuadTexcoord \ No newline at end of file +VERTEX DrawTransformUnitQuad \ No newline at end of file diff --git a/libraries/gpu/src/gpu/DrawTextureOpaque.slf b/libraries/gpu/src/gpu/DrawTextureOpaque.slf index e23529e851..458eff75ed 100755 --- a/libraries/gpu/src/gpu/DrawTextureOpaque.slf +++ b/libraries/gpu/src/gpu/DrawTextureOpaque.slf @@ -14,8 +14,6 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -<@include gpu/ShaderConstants.h@> - LAYOUT(binding=0) uniform sampler2D colorMap; layout(location=0) in vec2 varTexCoord0; diff --git a/libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slf b/libraries/gpu/src/gpu/DrawTextureSRGBToLinear.slf similarity index 94% rename from libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slf rename to libraries/gpu/src/gpu/DrawTextureSRGBToLinear.slf index 870967ec3a..772d45131a 100644 --- a/libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slf +++ b/libraries/gpu/src/gpu/DrawTextureSRGBToLinear.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// DrawTextureGammaSRGBToLinear.frag +// DrawTextureSRGBToLinear.frag // // Draw texture 0 fetched at texcoord.xy, and apply sRGB to Linear color space conversion // diff --git a/libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slp b/libraries/gpu/src/gpu/DrawTextureSRGBToLinear.slp similarity index 100% rename from libraries/gpu/src/gpu/DrawTextureGammaSRGBToLinear.slp rename to libraries/gpu/src/gpu/DrawTextureSRGBToLinear.slp diff --git a/libraries/plugins/src/plugins/DisplayPlugin.h b/libraries/plugins/src/plugins/DisplayPlugin.h index ca4e3bc392..2315f6e4ba 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.h +++ b/libraries/plugins/src/plugins/DisplayPlugin.h @@ -210,7 +210,7 @@ public: // for updating plugin-related commands. Mimics the input plugin. virtual void pluginUpdate() = 0; - virtual std::function getHUDOperator() { return nullptr; } + virtual std::function getHUDOperator() { return nullptr; } virtual StencilMaskMode getStencilMaskMode() const { return StencilMaskMode::NONE; } using StencilMaskMeshOperator = std::function; virtual StencilMaskMeshOperator getStencilMaskMeshOperator() { return nullptr; } diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index e5de6ccd27..54e43abc07 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -128,52 +128,11 @@ void Blit::run(const RenderContextPointer& renderContext, const gpu::Framebuffer gpu::doInBatch("Blit", renderArgs->_context, [&](gpu::Batch& batch) { batch.setFramebuffer(blitFbo); - if (renderArgs->_renderMode == RenderArgs::MIRROR_RENDER_MODE) { - if (renderArgs->isStereo()) { - gpu::Vec4i srcRectLeft; - srcRectLeft.z = width / 2; - srcRectLeft.w = height; + gpu::Vec4i rect; + rect.z = width; + rect.w = height; - gpu::Vec4i srcRectRight; - srcRectRight.x = width / 2; - srcRectRight.z = width; - srcRectRight.w = height; - - gpu::Vec4i destRectLeft; - destRectLeft.x = srcRectLeft.z; - destRectLeft.z = srcRectLeft.x; - destRectLeft.y = srcRectLeft.y; - destRectLeft.w = srcRectLeft.w; - - gpu::Vec4i destRectRight; - destRectRight.x = srcRectRight.z; - destRectRight.z = srcRectRight.x; - destRectRight.y = srcRectRight.y; - destRectRight.w = srcRectRight.w; - - // Blit left to right and right to left in stereo - batch.blit(primaryFbo, srcRectRight, blitFbo, destRectLeft); - batch.blit(primaryFbo, srcRectLeft, blitFbo, destRectRight); - } else { - gpu::Vec4i srcRect; - srcRect.z = width; - srcRect.w = height; - - gpu::Vec4i destRect; - destRect.x = width; - destRect.y = 0; - destRect.z = 0; - destRect.w = height; - - batch.blit(primaryFbo, srcRect, blitFbo, destRect); - } - } else { - gpu::Vec4i rect; - rect.z = width; - rect.w = height; - - batch.blit(primaryFbo, rect, blitFbo, rect); - } + batch.blit(primaryFbo, rect, blitFbo, rect); }); } diff --git a/libraries/render-utils/src/RenderForwardTask.cpp b/libraries/render-utils/src/RenderForwardTask.cpp index d65ad18aa1..ef3dcee15f 100755 --- a/libraries/render-utils/src/RenderForwardTask.cpp +++ b/libraries/render-utils/src/RenderForwardTask.cpp @@ -144,9 +144,9 @@ void RenderForwardTask::build(JobModel& task, const render::Varying& input, rend // Just resolve the msaa const auto resolveInputs = ResolveFramebuffer::Inputs(scaledPrimaryFramebuffer, static_cast(nullptr)).asVarying(); - const auto resolvedFramebuffer = task.addJob("Resolve", resolveInputs); + const auto resolvedFramebuffer = task.addJob("Resolve", resolveInputs); - const auto toneMappedBuffer = resolvedFramebuffer; + const auto toneMappedBuffer = resolvedFramebuffer; #else const auto newResolvedFramebuffer = task.addJob("MakeResolvingFramebuffer"); diff --git a/libraries/render-utils/src/RenderHUDLayerTask.cpp b/libraries/render-utils/src/RenderHUDLayerTask.cpp index ac7a867366..840d9e8002 100644 --- a/libraries/render-utils/src/RenderHUDLayerTask.cpp +++ b/libraries/render-utils/src/RenderHUDLayerTask.cpp @@ -34,7 +34,7 @@ void CompositeHUD::run(const RenderContextPointer& renderContext, const gpu::Fra batch.setFramebuffer(inputs); } if (renderContext->args->_hudOperator) { - renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture, renderContext->args->_renderMode == RenderArgs::RenderMode::MIRROR_RENDER_MODE); + renderContext->args->_hudOperator(batch, renderContext->args->_hudTexture); } }); #endif diff --git a/libraries/render-utils/src/hmd_ui.slf b/libraries/render-utils/src/hmd_ui.slf index 6895a90f9e..af19ef1c06 100644 --- a/libraries/render-utils/src/hmd_ui.slf +++ b/libraries/render-utils/src/hmd_ui.slf @@ -12,6 +12,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // <@include render-utils/ShaderConstants.h@> +<@include gpu/Color.slh@> LAYOUT(binding=0) uniform sampler2D hudTexture; @@ -36,5 +37,5 @@ void main() { discard; } - fragColor0 = color; + fragColor0 = color_sRGBAToLinear(color); } \ No newline at end of file diff --git a/libraries/render/src/render/Args.h b/libraries/render/src/render/Args.h index 1798208981..cb1ca668a7 100644 --- a/libraries/render/src/render/Args.h +++ b/libraries/render/src/render/Args.h @@ -136,7 +136,7 @@ namespace render { render::ScenePointer _scene; int8_t _cameraMode { -1 }; - std::function _hudOperator { nullptr }; + std::function _hudOperator { nullptr }; gpu::TexturePointer _hudTexture { nullptr }; bool _takingSnapshot { false }; diff --git a/plugins/oculus/src/OculusDisplayPlugin.cpp b/plugins/oculus/src/OculusDisplayPlugin.cpp index 161266c4af..bd0c77ae57 100644 --- a/plugins/oculus/src/OculusDisplayPlugin.cpp +++ b/plugins/oculus/src/OculusDisplayPlugin.cpp @@ -163,7 +163,7 @@ void OculusDisplayPlugin::hmdPresent() { batch.setStateScissorRect(ivec4(uvec2(), _outputFramebuffer->getSize())); batch.resetViewTransform(); batch.setProjectionTransform(mat4()); - batch.setPipeline(_SRGBToLinearPipeline); + batch.setPipeline(_drawTexturePipeline); batch.setResourceTexture(0, _compositeFramebuffer->getRenderBuffer(0)); batch.draw(gpu::TRIANGLE_STRIP, 4); }); From f52376563d96f240dbedea9f4a23907ddaee7c50 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 1 Jul 2019 11:14:54 -0700 Subject: [PATCH 05/15] remove redundant getRenderTexturePipeline() override from HMD display plugin --- .../src/display-plugins/hmd/HmdDisplayPlugin.cpp | 4 ---- .../src/display-plugins/hmd/HmdDisplayPlugin.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 2eb22723a5..3cec5e8265 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -174,10 +174,6 @@ float HmdDisplayPlugin::getLeftCenterPixel() const { return leftCenterPixel; } -gpu::PipelinePointer HmdDisplayPlugin::getRenderTexturePipeline() { - return _drawTexturePipeline; -} - void HmdDisplayPlugin::internalPresent() { PROFILE_RANGE_EX(render, __FUNCTION__, 0xff00ff00, (uint64_t)presentCount()) diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index e475da0818..a381f04689 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -51,8 +51,6 @@ public: std::function getHUDOperator() override; virtual StencilMaskMode getStencilMaskMode() const override { return StencilMaskMode::PAINT; } - virtual gpu::PipelinePointer getRenderTexturePipeline() override; - signals: void hmdMountedChanged(); void hmdVisibleChanged(bool visible); From 292dce3e88b943b29f056058b86c56721f358657 Mon Sep 17 00:00:00 2001 From: ingerjm0 Date: Mon, 1 Jul 2019 14:38:56 -0700 Subject: [PATCH 06/15] DOC-66: Show deprecated notices for signals. --- tools/jsdoc/hifi-jsdoc-template/tmpl/signal.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jsdoc/hifi-jsdoc-template/tmpl/signal.tmpl b/tools/jsdoc/hifi-jsdoc-template/tmpl/signal.tmpl index 20743fe052..00bf7122e1 100644 --- a/tools/jsdoc/hifi-jsdoc-template/tmpl/signal.tmpl +++ b/tools/jsdoc/hifi-jsdoc-template/tmpl/signal.tmpl @@ -24,7 +24,7 @@ var self = this; - +

From 95f2dfa551ae0177f8b99741949ed39a9f867d61 Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 1 Jul 2019 15:31:26 -0700 Subject: [PATCH 07/15] added horizontal flip back to mirror mode --- libraries/gpu/src/gpu/DrawTextureMirroredX.slf | 2 +- libraries/render/src/render/ResampleTask.cpp | 11 ++++++++--- libraries/render/src/render/ResampleTask.h | 1 + 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libraries/gpu/src/gpu/DrawTextureMirroredX.slf b/libraries/gpu/src/gpu/DrawTextureMirroredX.slf index acb93fa5ca..f959d8480b 100644 --- a/libraries/gpu/src/gpu/DrawTextureMirroredX.slf +++ b/libraries/gpu/src/gpu/DrawTextureMirroredX.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// DrawTextureSRGBToLinearMirroredX.frag +// DrawTextureMirroredX.frag // // Draw texture 0 fetched at (1.0 - texcoord.x, texcoord.y) // diff --git a/libraries/render/src/render/ResampleTask.cpp b/libraries/render/src/render/ResampleTask.cpp index 3e9bfec8da..1a7a075af6 100644 --- a/libraries/render/src/render/ResampleTask.cpp +++ b/libraries/render/src/render/ResampleTask.cpp @@ -16,6 +16,7 @@ #include using namespace render; +using namespace shader::gpu::program; gpu::PipelinePointer HalfDownsample::_pipeline; @@ -137,6 +138,7 @@ void Upsample::run(const RenderContextPointer& renderContext, const gpu::Framebu } gpu::PipelinePointer UpsampleToBlitFramebuffer::_pipeline; +gpu::PipelinePointer UpsampleToBlitFramebuffer::_mirrorPipeline; void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, const Input& input, gpu::FramebufferPointer& resampledFrameBuffer) { assert(renderContext->args); @@ -148,14 +150,17 @@ void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, c if (resampledFrameBuffer != sourceFramebuffer) { if (!_pipeline) { - gpu::ShaderPointer program = gpu::Shader::createProgram(shader::gpu::program::drawTransformUnitQuadTextureOpaque); gpu::StatePointer state = gpu::StatePointer(new gpu::State()); state->setDepthTest(gpu::State::DepthTest(false, false)); - _pipeline = gpu::Pipeline::create(program, state); + + _pipeline = gpu::Pipeline::create(gpu::Shader::createProgram(drawTransformUnitQuadTextureOpaque), state); + _mirrorPipeline = gpu::Pipeline::create(gpu::Shader::createProgram(DrawTextureMirroredX), state); } const auto bufferSize = resampledFrameBuffer->getSize(); glm::ivec4 viewport{ 0, 0, bufferSize.x, bufferSize.y }; + gpu::PipelinePointer pipeline = args->_renderMode == RenderArgs::MIRROR_RENDER_MODE ? _mirrorPipeline : _pipeline; + gpu::doInBatch("Upsample::run", args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); @@ -164,7 +169,7 @@ void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, c batch.setViewportTransform(viewport); batch.setProjectionTransform(glm::mat4()); batch.resetViewTransform(); - batch.setPipeline(_pipeline); + batch.setPipeline(pipeline); batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(bufferSize, viewport)); batch.setResourceTexture(0, sourceFramebuffer->getRenderBuffer(0)); diff --git a/libraries/render/src/render/ResampleTask.h b/libraries/render/src/render/ResampleTask.h index e62b76e6d0..92f720c843 100644 --- a/libraries/render/src/render/ResampleTask.h +++ b/libraries/render/src/render/ResampleTask.h @@ -80,6 +80,7 @@ namespace render { protected: static gpu::PipelinePointer _pipeline; + static gpu::PipelinePointer _mirrorPipeline; }; } From 6253adf7493974a4b1751356fed5095083f0dd70 Mon Sep 17 00:00:00 2001 From: Simon Walton Date: Mon, 1 Jul 2019 16:36:05 -0700 Subject: [PATCH 08/15] Hook-up remote address-change to Connection class --- libraries/networking/src/LimitedNodeList.cpp | 1 + libraries/networking/src/udt/Socket.h | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/networking/src/LimitedNodeList.cpp b/libraries/networking/src/LimitedNodeList.cpp index b5872a46fd..3519408960 100644 --- a/libraries/networking/src/LimitedNodeList.cpp +++ b/libraries/networking/src/LimitedNodeList.cpp @@ -754,6 +754,7 @@ SharedNodePointer LimitedNodeList::addOrUpdateNode(const QUuid& uuid, NodeType_t connect(newNodePointer.data(), &NetworkPeer::socketUpdated, this, [this, weakPtr] { emit nodeSocketUpdated(weakPtr); }); + connect(newNodePointer.data(), &NetworkPeer::socketUpdated, &_nodeSocket, &udt::Socket::handleRemoteAddressChange); return newNodePointer; } diff --git a/libraries/networking/src/udt/Socket.h b/libraries/networking/src/udt/Socket.h index 74eb413bc2..6cd2d25659 100644 --- a/libraries/networking/src/udt/Socket.h +++ b/libraries/networking/src/udt/Socket.h @@ -99,14 +99,14 @@ signals: public slots: void cleanupConnection(HifiSockAddr sockAddr); void clearConnections(); - + void handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAddr currentAddress); + private slots: void readPendingDatagrams(); void checkForReadyReadBackup(); void handleSocketError(QAbstractSocket::SocketError socketError); void handleStateChanged(QAbstractSocket::SocketState socketState); - void handleRemoteAddressChange(HifiSockAddr previousAddress, HifiSockAddr currentAddress); private: void setSystemBufferSizes(); From f44bc52d5837cc02b8338b48c668986ce8b3eb4f Mon Sep 17 00:00:00 2001 From: Anna Date: Mon, 1 Jul 2019 17:05:13 -0700 Subject: [PATCH 09/15] implemented requested changes, fixed math error in filmic curve --- .../src/display-plugins/OpenGLDisplayPlugin.cpp | 5 ++--- libraries/render-utils/src/toneMapping.slf | 11 ++++------- libraries/render/src/render/ResampleTask.cpp | 4 +--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index 83380b18d0..ebbf888e83 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -588,10 +588,9 @@ std::function OpenGLDisplayPlugin hudEyeViewports[eye] = eyeViewport(eye); }); return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture) { - auto pipeline = hudPipeline; - if (pipeline && hudTexture) { + if (hudPipeline && hudTexture) { batch.enableStereo(false); - batch.setPipeline(pipeline); + batch.setPipeline(hudPipeline); batch.setResourceTexture(0, hudTexture); if (hudStereo) { for_each_eye([&](Eye eye) { diff --git a/libraries/render-utils/src/toneMapping.slf b/libraries/render-utils/src/toneMapping.slf index 211b2a50f4..4f7ed6374d 100644 --- a/libraries/render-utils/src/toneMapping.slf +++ b/libraries/render-utils/src/toneMapping.slf @@ -51,19 +51,16 @@ void main(void) { int toneCurve = getToneCurve(); vec3 tonedColor = srcColor; if (toneCurve == ToneCurveFilmic) { - vec3 rgbColor = pow(srcColor, vec3(GAMMA_22)); - vec3 x = max(vec3(0.0), rgbColor-0.004); - tonedColor = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06); + vec3 x = max(vec3(0.0), srcColor-0.004); + tonedColor = pow((x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06), vec3(GAMMA_22)); } else if (toneCurve == ToneCurveReinhard) { tonedColor = srcColor/(1.0 + srcColor); - } - else if (toneCurve == ToneCurveGamma22) { + } else if (toneCurve == ToneCurveGamma22) { // We use glEnable(GL_FRAMEBUFFER_SRGB), which automatically converts textures from RGB to SRGB // when writing from an RGB framebuffer to an SRGB framebuffer (note that it doesn't do anything // when writing from an SRGB framebuffer to an RGB framebuffer). // Since the conversion happens automatically, we don't need to do anything in this shader - } - else { + } else { // toneCurve == ToneCurveNone // For debugging purposes, we may want to see what the colors look like before the automatic OpenGL // conversion mentioned above, so we undo it here diff --git a/libraries/render/src/render/ResampleTask.cpp b/libraries/render/src/render/ResampleTask.cpp index 1a7a075af6..b3d4b38d02 100644 --- a/libraries/render/src/render/ResampleTask.cpp +++ b/libraries/render/src/render/ResampleTask.cpp @@ -159,8 +159,6 @@ void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, c const auto bufferSize = resampledFrameBuffer->getSize(); glm::ivec4 viewport{ 0, 0, bufferSize.x, bufferSize.y }; - gpu::PipelinePointer pipeline = args->_renderMode == RenderArgs::MIRROR_RENDER_MODE ? _mirrorPipeline : _pipeline; - gpu::doInBatch("Upsample::run", args->_context, [&](gpu::Batch& batch) { batch.enableStereo(false); @@ -169,7 +167,7 @@ void UpsampleToBlitFramebuffer::run(const RenderContextPointer& renderContext, c batch.setViewportTransform(viewport); batch.setProjectionTransform(glm::mat4()); batch.resetViewTransform(); - batch.setPipeline(pipeline); + batch.setPipeline(args->_renderMode == RenderArgs::MIRROR_RENDER_MODE ? _mirrorPipeline : _pipeline); batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(bufferSize, viewport)); batch.setResourceTexture(0, sourceFramebuffer->getRenderBuffer(0)); From 6c66f5a37bb0209ddd9d8d7dbd5d6e6855c7c5dc Mon Sep 17 00:00:00 2001 From: Anthony Thibault Date: Mon, 1 Jul 2019 17:37:57 -0700 Subject: [PATCH 10/15] Fix for DependencyManager crash on shutdown on Mac On Mac, it is possible to crash when shutting down, it is not clear if this is due to shutting down the app on another thread during logout or something that can happen during normal shutdown, because it is so difficult to reproduce. However, from looking at the stack traces it is possible for a [NSApplication terminate:] event to get processed while Appliction::aboutToQuit() is calling ScriptEngine::waitTillDoneRunning() This causes AppKit to invoke the static destructors too early. Which in turn, causes the DependencyManager destructor to fire while there are still many dependencies running. Unfortunatly, the order of destruction is not determinstic, causing them to get shutdown in an incorrect order. To workaround this, we delay the call to QCoreApplication::processEvents() as late as possible, in the Application destructor. Theoretically, this will be a safe time for the static destructors to be invoked, because it is after all of the DependencyManager's dependencies have been manually destroyed. However, this is only a speculative fix, because this is so difficult to reproduce. --- interface/src/Application.cpp | 17 ++++++++++-- libraries/baking/src/MaterialBaker.cpp | 4 +-- .../src/RenderableMaterialEntityItem.cpp | 4 +-- .../src/material-networking/MaterialCache.cpp | 7 +---- .../src/material-networking/MaterialCache.h | 7 ++--- .../model-baker/ParseMaterialMappingTask.cpp | 2 +- libraries/networking/src/AccountManager.cpp | 3 ++- libraries/script-engine/src/ScriptEngine.cpp | 26 +++++++++++++++++-- 8 files changed, 51 insertions(+), 19 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3c80d5fa0f..8ecb16b65f 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -104,6 +104,7 @@ #include #include #include +#include #include #include #include @@ -877,6 +878,7 @@ bool setupEssentials(int& argc, char** argv, bool runningMarkerExisted) { DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); DependencyManager::set(); @@ -2852,6 +2854,7 @@ Application::~Application() { DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); + DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); DependencyManager::destroy(); @@ -2887,6 +2890,16 @@ Application::~Application() { // Can't log to file past this point, FileLogger about to be deleted qInstallMessageHandler(LogHandler::verboseMessageHandler); + +#ifdef Q_OS_MAC + // Clear the event queue before application is totally destructed. + // This will drain the messasge queue of pending "deleteLaters" queued up + // during shutdown of the script engines. + // We do this here because there is a possiblty that [NSApplication terminate:] + // will be called during processEvents which will invoke all static destructors. + // We want to postpone this utill the last possible moment. + QCoreApplication::processEvents(); +#endif } void Application::initializeGL() { @@ -5960,7 +5973,7 @@ void Application::reloadResourceCaches() { DependencyManager::get()->clear(); DependencyManager::get()->refreshAll(); DependencyManager::get()->refreshAll(); - MaterialCache::instance().refreshAll(); + DependencyManager::get()->refreshAll(); DependencyManager::get()->refreshAll(); ShaderCache::instance().refreshAll(); DependencyManager::get()->refreshAll(); @@ -7146,7 +7159,7 @@ void Application::clearDomainOctreeDetails(bool clearAll) { DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); - MaterialCache::instance().clearUnusedResources(); + DependencyManager::get()->clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); ShaderCache::instance().clearUnusedResources(); DependencyManager::get()->clearUnusedResources(); diff --git a/libraries/baking/src/MaterialBaker.cpp b/libraries/baking/src/MaterialBaker.cpp index e23b76f73a..9a1b1b2d24 100644 --- a/libraries/baking/src/MaterialBaker.cpp +++ b/libraries/baking/src/MaterialBaker.cpp @@ -72,7 +72,7 @@ void MaterialBaker::loadMaterial() { _materialResource->parsedMaterials = NetworkMaterialResource::parseJSONMaterials(QJsonDocument::fromJson(_materialData.toUtf8()), QUrl()); } else { qCDebug(material_baking) << "Downloading material" << _materialData; - _materialResource = MaterialCache::instance().getMaterial(_materialData); + _materialResource = DependencyManager::get()->getMaterial(_materialData); } if (_materialResource) { @@ -280,4 +280,4 @@ void MaterialBaker::setMaterials(const QHash& materials, void MaterialBaker::setMaterials(const NetworkMaterialResourcePointer& materialResource) { _materialResource = materialResource; -} \ No newline at end of file +} diff --git a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp index 01eac7b203..22e3205531 100644 --- a/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableMaterialEntityItem.cpp @@ -172,7 +172,7 @@ void MaterialEntityRenderer::doRenderUpdateAsynchronousTyped(const TypedEntityPo } if (urlChanged && !usingMaterialData) { - _networkMaterial = MaterialCache::instance().getMaterial(_materialURL); + _networkMaterial = DependencyManager::get()->getMaterial(_materialURL); auto onMaterialRequestFinished = [this, oldParentID, oldParentMaterialName, newCurrentMaterialName](bool success) { if (success) { deleteMaterial(oldParentID, oldParentMaterialName); @@ -412,4 +412,4 @@ void MaterialEntityRenderer::applyMaterial() { // if we've reached this point, we couldn't find our parent, so we need to try again later _retryApply = true; -} \ No newline at end of file +} diff --git a/libraries/material-networking/src/material-networking/MaterialCache.cpp b/libraries/material-networking/src/material-networking/MaterialCache.cpp index cfe3b73e49..fd218fe074 100644 --- a/libraries/material-networking/src/material-networking/MaterialCache.cpp +++ b/libraries/material-networking/src/material-networking/MaterialCache.cpp @@ -441,11 +441,6 @@ std::pair> NetworkMaterialResource return std::pair>(name, material); } -MaterialCache& MaterialCache::instance() { - static MaterialCache _instance; - return _instance; -} - NetworkMaterialResourcePointer MaterialCache::getMaterial(const QUrl& url) { return ResourceCache::getResource(url).staticCast(); } @@ -761,4 +756,4 @@ void NetworkMaterial::checkResetOpacityMap() { if (albedoTexture.texture) { resetOpacityMap(); } -} \ No newline at end of file +} diff --git a/libraries/material-networking/src/material-networking/MaterialCache.h b/libraries/material-networking/src/material-networking/MaterialCache.h index 66e6b8250b..18aa5e5994 100644 --- a/libraries/material-networking/src/material-networking/MaterialCache.h +++ b/libraries/material-networking/src/material-networking/MaterialCache.h @@ -110,10 +110,11 @@ using NetworkMaterialResourcePointer = QSharedPointer; using MaterialMapping = std::vector>; Q_DECLARE_METATYPE(MaterialMapping) -class MaterialCache : public ResourceCache { -public: - static MaterialCache& instance(); +class MaterialCache : public ResourceCache, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY +public: NetworkMaterialResourcePointer getMaterial(const QUrl& url); protected: diff --git a/libraries/model-baker/src/model-baker/ParseMaterialMappingTask.cpp b/libraries/model-baker/src/model-baker/ParseMaterialMappingTask.cpp index 17b62d0915..c4c4f7f74b 100644 --- a/libraries/model-baker/src/model-baker/ParseMaterialMappingTask.cpp +++ b/libraries/model-baker/src/model-baker/ParseMaterialMappingTask.cpp @@ -61,7 +61,7 @@ void processMaterialMapping(MaterialMapping& materialMapping, const QJsonObject& } else if (mappingJSON.isString()) { auto mappingValue = mappingJSON.toString(); materialMapping.push_back(std::pair(mapping.toStdString(), - MaterialCache::instance().getMaterial(url.resolved(mappingValue)))); + DependencyManager::get()->getMaterial(url.resolved(mappingValue)))); } } } diff --git a/libraries/networking/src/AccountManager.cpp b/libraries/networking/src/AccountManager.cpp index e2e9d33eb6..96cfa66013 100644 --- a/libraries/networking/src/AccountManager.cpp +++ b/libraries/networking/src/AccountManager.cpp @@ -92,6 +92,7 @@ const QString DOUBLE_SLASH_SUBSTITUTE = "slashslash"; const QString ACCOUNT_MANAGER_REQUESTED_SCOPE = "owner"; void AccountManager::logout() { + // a logout means we want to delete the DataServerAccountInfo we currently have for this URL, in-memory and in file _accountInfo = DataServerAccountInfo(); @@ -959,4 +960,4 @@ void AccountManager::saveLoginStatus(bool isLoggedIn) { QMetaObject::invokeMethod(qApp, "quit", Qt::QueuedConnection); } } -} \ No newline at end of file +} diff --git a/libraries/script-engine/src/ScriptEngine.cpp b/libraries/script-engine/src/ScriptEngine.cpp index 02dcde3695..5e20f06a7f 100644 --- a/libraries/script-engine/src/ScriptEngine.cpp +++ b/libraries/script-engine/src/ScriptEngine.cpp @@ -224,7 +224,7 @@ ScriptEngine::ScriptEngine(Context context, const QString& scriptContents, const if (_type == Type::ENTITY_CLIENT || _type == Type::ENTITY_SERVER) { QObject::connect(this, &ScriptEngine::update, this, [this]() { // process pending entity script content - if (!_contentAvailableQueue.empty()) { + if (!_contentAvailableQueue.empty() && !(_isFinished || _isStopping)) { EntityScriptContentAvailableMap pending; std::swap(_contentAvailableQueue, pending); for (auto& pair : pending) { @@ -343,7 +343,7 @@ void ScriptEngine::runDebuggable() { // we check for 'now' in the past in case people set their clock back if (_lastUpdate < now) { float deltaTime = (float)(now - _lastUpdate) / (float)USECS_PER_SECOND; - if (!_isFinished) { + if (!(_isFinished || _isStopping)) { emit update(deltaTime); } } @@ -411,6 +411,27 @@ void ScriptEngine::waitTillDoneRunning() { // We should never be waiting (blocking) on our own thread assert(workerThread != QThread::currentThread()); +#ifdef Q_OS_MAC + // On mac, don't call QCoreApplication::processEvents() here. This is to prevent + // [NSApplication terminate:] from prematurely destroying the static destructors + // while we are waiting for the scripts to shutdown. We will pump the message + // queue later in the Application destructor. + if (workerThread->isRunning()) { + workerThread->quit(); + + if (isEvaluating()) { + qCWarning(scriptengine) << "Script Engine has been running too long, aborting:" << getFilename(); + abortEvaluation(); + } + + // Wait for the scripting thread to stop running, as + // flooding it with aborts/exceptions will persist it longer + static const auto MAX_SCRIPT_QUITTING_TIME = 0.5 * MSECS_PER_SECOND; + if (!workerThread->wait(MAX_SCRIPT_QUITTING_TIME)) { + workerThread->terminate(); + } + } +#else auto startedWaiting = usecTimestampNow(); while (workerThread->isRunning()) { // If the final evaluation takes too long, then tell the script engine to stop running @@ -448,6 +469,7 @@ void ScriptEngine::waitTillDoneRunning() { // Avoid a pure busy wait QThread::yieldCurrentThread(); } +#endif scriptInfoMessage("Script Engine has stopped:" + getFilename()); } From ccc4b0d9e108caad5b6d63a841ad3ab89689f5e2 Mon Sep 17 00:00:00 2001 From: milad Date: Tue, 2 Jul 2019 10:33:19 -0700 Subject: [PATCH 11/15] added unlit property --- .../resources/modules/defaultLocalEntityProps.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/defaultLocalEntityProps.js b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/defaultLocalEntityProps.js index 1947a47220..709c42f8b8 100644 --- a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/defaultLocalEntityProps.js +++ b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/defaultLocalEntityProps.js @@ -20,7 +20,8 @@ var localEntityProps = { backgroundAlpha: 0.6, billboardMode: "full", lifetime: 3, - canCastShadow: true + canCastShadow: true, + unlit: true }; -module.exports = localEntityProps; \ No newline at end of file +module.exports = localEntityProps; From 0670147bf844b24ab251ba9fc2f0d27c7e999f3f Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Tue, 2 Jul 2019 14:24:02 -0700 Subject: [PATCH 12/15] Fixed paths to included files and collision with 'clamp' --- script-archive/example/ui/MyEnergyBar.js | 4 ++-- script-archive/example/ui/energyBar.js | 4 ++-- scripts/simplifiedUI/system/libraries/WebTablet.js | 10 +++++----- scripts/simplifiedUI/system/libraries/utils.js | 2 +- scripts/system/libraries/WebTablet.js | 10 +++++----- scripts/system/libraries/utils.js | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/script-archive/example/ui/MyEnergyBar.js b/script-archive/example/ui/MyEnergyBar.js index 2d01a66317..98fb35814c 100644 --- a/script-archive/example/ui/MyEnergyBar.js +++ b/script-archive/example/ui/MyEnergyBar.js @@ -33,14 +33,14 @@ var bar = Overlays.addOverlay("text", { // Takes an energy value between 0 and 1 and sets energy bar width appropriately function setEnergy(energy) { - energy = clamp(energy, 0, 1); + energy = hifiClamp(energy, 0, 1); var barWidth = totalWidth * energy; var color = energy <= lowEnergyThreshold ? lowEnergyColor: energyColor; Overlays.editOverlay(bar, { width: barWidth, backgroundColor: color}); } function update() { - currentEnergy = clamp(MyAvatar.energy, 0, 1); + currentEnergy = hifiClamp(MyAvatar.energy, 0, 1); setEnergy(currentEnergy); } diff --git a/script-archive/example/ui/energyBar.js b/script-archive/example/ui/energyBar.js index 498eef2751..6a97f88472 100644 --- a/script-archive/example/ui/energyBar.js +++ b/script-archive/example/ui/energyBar.js @@ -45,14 +45,14 @@ var bar = Overlays.addOverlay("text", { // Takes an energy value between 0 and 1 and sets energy bar width appropriately function setEnergy(energy) { - energy = clamp(energy, 0, 1); + energy = hifiClamp(energy, 0, 1); var barWidth = totalWidth * energy; var color = energy <= lowEnergyThreshold ? lowEnergyColor: energyColor; Overlays.editOverlay(bar, { width: barWidth, backgroundColor: color}); } function update() { - currentEnergy = clamp(MyAvatar.energy, 0, 1); + currentEnergy = hifiClamp(MyAvatar.energy, 0, 1); setEnergy(currentEnergy); } diff --git a/scripts/simplifiedUI/system/libraries/WebTablet.js b/scripts/simplifiedUI/system/libraries/WebTablet.js index 9d333a1ae4..0ee5259ffa 100644 --- a/scripts/simplifiedUI/system/libraries/WebTablet.js +++ b/scripts/simplifiedUI/system/libraries/WebTablet.js @@ -10,9 +10,9 @@ /* global getControllerWorldLocation, Tablet, WebTablet:true, HMD, Settings, Script, Vec3, Quat, MyAvatar, Entities, Overlays, Camera, Messages, Xform, clamp, Controller, Mat4, resizeTablet */ -Script.include(Script.resolvePath("../libraries/utils.js")); -Script.include(Script.resolvePath("../libraries/controllers.js")); -Script.include(Script.resolvePath("../libraries/Xform.js")); +Script.include(Script.resolvePath("utils.js")); +Script.include(Script.resolvePath("controllers.js")); +Script.include(Script.resolvePath("Xform.js")); var Y_AXIS = {x: 0, y: 1, z: 0}; var X_AXIS = {x: 1, y: 0, z: 0}; @@ -380,8 +380,8 @@ WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function (windowPos var TABLET_TEXEL_PADDING = {x: 60, y: 90}; var X_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().x / 2) + TABLET_TEXEL_PADDING.x); var Y_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().y / 2) + TABLET_TEXEL_PADDING.y); - windowPos.x = clamp(windowPos.x, X_CLAMP, Window.innerWidth - X_CLAMP); - windowPos.y = clamp(windowPos.y, Y_CLAMP, Window.innerHeight - Y_CLAMP); + windowPos.x = hifiClamp(windowPos.x, X_CLAMP, Window.innerWidth - X_CLAMP); + windowPos.y = hifiClamp(windowPos.y, Y_CLAMP, Window.innerHeight - Y_CLAMP); var fov = (Settings.getValue('fieldOfView') || DEFAULT_VERTICAL_FIELD_OF_VIEW) * (Math.PI / 180); diff --git a/scripts/simplifiedUI/system/libraries/utils.js b/scripts/simplifiedUI/system/libraries/utils.js index 508e8d46e3..cd64e4ad80 100644 --- a/scripts/simplifiedUI/system/libraries/utils.js +++ b/scripts/simplifiedUI/system/libraries/utils.js @@ -340,7 +340,7 @@ calculateHandSizeRatio = function() { return handSizeRatio; } -clamp = function(val, min, max){ +hifiClamp = function (val, min, max) { return Math.max(min, Math.min(max, val)) } diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index 9d333a1ae4..0ee5259ffa 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -10,9 +10,9 @@ /* global getControllerWorldLocation, Tablet, WebTablet:true, HMD, Settings, Script, Vec3, Quat, MyAvatar, Entities, Overlays, Camera, Messages, Xform, clamp, Controller, Mat4, resizeTablet */ -Script.include(Script.resolvePath("../libraries/utils.js")); -Script.include(Script.resolvePath("../libraries/controllers.js")); -Script.include(Script.resolvePath("../libraries/Xform.js")); +Script.include(Script.resolvePath("utils.js")); +Script.include(Script.resolvePath("controllers.js")); +Script.include(Script.resolvePath("Xform.js")); var Y_AXIS = {x: 0, y: 1, z: 0}; var X_AXIS = {x: 1, y: 0, z: 0}; @@ -380,8 +380,8 @@ WebTablet.prototype.calculateWorldAttitudeRelativeToCamera = function (windowPos var TABLET_TEXEL_PADDING = {x: 60, y: 90}; var X_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().x / 2) + TABLET_TEXEL_PADDING.x); var Y_CLAMP = (DESKTOP_TABLET_SCALE / 100) * ((this.getTabletTextureResolution().y / 2) + TABLET_TEXEL_PADDING.y); - windowPos.x = clamp(windowPos.x, X_CLAMP, Window.innerWidth - X_CLAMP); - windowPos.y = clamp(windowPos.y, Y_CLAMP, Window.innerHeight - Y_CLAMP); + windowPos.x = hifiClamp(windowPos.x, X_CLAMP, Window.innerWidth - X_CLAMP); + windowPos.y = hifiClamp(windowPos.y, Y_CLAMP, Window.innerHeight - Y_CLAMP); var fov = (Settings.getValue('fieldOfView') || DEFAULT_VERTICAL_FIELD_OF_VIEW) * (Math.PI / 180); diff --git a/scripts/system/libraries/utils.js b/scripts/system/libraries/utils.js index 508e8d46e3..cd64e4ad80 100644 --- a/scripts/system/libraries/utils.js +++ b/scripts/system/libraries/utils.js @@ -340,7 +340,7 @@ calculateHandSizeRatio = function() { return handSizeRatio; } -clamp = function(val, min, max){ +hifiClamp = function (val, min, max) { return Math.max(min, Math.min(max, val)) } From d840723fe36b8e33cc51ffcda077fd45860e3ad0 Mon Sep 17 00:00:00 2001 From: RebeccaStankus Date: Tue, 2 Jul 2019 15:08:34 -0700 Subject: [PATCH 13/15] Fixed space before function params --- scripts/simplifiedUI/system/libraries/utils.js | 4 ++-- scripts/system/libraries/utils.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/simplifiedUI/system/libraries/utils.js b/scripts/simplifiedUI/system/libraries/utils.js index cd64e4ad80..d5155ff465 100644 --- a/scripts/simplifiedUI/system/libraries/utils.js +++ b/scripts/simplifiedUI/system/libraries/utils.js @@ -340,8 +340,8 @@ calculateHandSizeRatio = function() { return handSizeRatio; } -hifiClamp = function (val, min, max) { - return Math.max(min, Math.min(max, val)) +hifiClamp = function(val, min, max) { + return Math.max(min, Math.min(max, val)); } // flattens an array of arrays into a single array diff --git a/scripts/system/libraries/utils.js b/scripts/system/libraries/utils.js index cd64e4ad80..d5155ff465 100644 --- a/scripts/system/libraries/utils.js +++ b/scripts/system/libraries/utils.js @@ -340,8 +340,8 @@ calculateHandSizeRatio = function() { return handSizeRatio; } -hifiClamp = function (val, min, max) { - return Math.max(min, Math.min(max, val)) +hifiClamp = function(val, min, max) { + return Math.max(min, Math.min(max, val)); } // flattens an array of arrays into a single array From 83546de9dad112a52e7a66a7b879625de02f4dbe Mon Sep 17 00:00:00 2001 From: milad Date: Tue, 2 Jul 2019 16:40:23 -0700 Subject: [PATCH 14/15] removed distance check for redraw to prevent nametag in user's body --- .../resources/modules/nameTagListManager.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js index de783f8661..fdfb6a7b08 100644 --- a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js +++ b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js @@ -344,24 +344,20 @@ function makeNameTag(uuid) { }, REDRAW_TIMEOUT_AMOUNT_MS); } - +console.log("\n\nV2\n\n"); // Check to see if the display named changed or if the distance is big enough to need a redraw. var MAX_RADIUS_IGNORE_METERS = 22; var MAX_ON_MODE_DISTANCE = 35; -var CHECK_AVATAR = true; -var MIN_DISTANCE_FOR_REDRAW_METERS = 0.1; function maybeRedraw(uuid) { var avatar = _this.avatars[uuid]; getAvatarData(uuid); getDistance(uuid); - var distanceDelta = Math.abs(avatar.currentDistance - avatar.previousDistance); - var name = getCorrectName(uuid); if (avatar.previousName !== name) { updateName(uuid, name); - } else if (distanceDelta > MIN_DISTANCE_FOR_REDRAW_METERS) { + } else { redraw(uuid); } } From c7f5a5064d638a8d236331816622b19e8721b3c3 Mon Sep 17 00:00:00 2001 From: milad Date: Tue, 2 Jul 2019 16:41:24 -0700 Subject: [PATCH 15/15] removed bad log --- .../ui/simplifiedNametag/resources/modules/nameTagListManager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js index fdfb6a7b08..216767c1cb 100644 --- a/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js +++ b/scripts/simplifiedUI/ui/simplifiedNametag/resources/modules/nameTagListManager.js @@ -344,7 +344,6 @@ function makeNameTag(uuid) { }, REDRAW_TIMEOUT_AMOUNT_MS); } -console.log("\n\nV2\n\n"); // Check to see if the display named changed or if the distance is big enough to need a redraw. var MAX_RADIUS_IGNORE_METERS = 22; var MAX_ON_MODE_DISTANCE = 35;