diff --git a/interface/src/ui/overlays/Base3DOverlay.cpp b/interface/src/ui/overlays/Base3DOverlay.cpp index 8f2149f02d..ff5177ed3a 100644 --- a/interface/src/ui/overlays/Base3DOverlay.cpp +++ b/interface/src/ui/overlays/Base3DOverlay.cpp @@ -26,7 +26,8 @@ Base3DOverlay::Base3DOverlay() : _isSolid(DEFAULT_IS_SOLID), _isDashedLine(DEFAULT_IS_DASHED_LINE), _ignoreRayIntersection(false), - _drawInFront(false) + _drawInFront(false), + _isAA(true) { } @@ -37,7 +38,8 @@ Base3DOverlay::Base3DOverlay(const Base3DOverlay* base3DOverlay) : _isSolid(base3DOverlay->_isSolid), _isDashedLine(base3DOverlay->_isDashedLine), _ignoreRayIntersection(base3DOverlay->_ignoreRayIntersection), - _drawInFront(base3DOverlay->_drawInFront) + _drawInFront(base3DOverlay->_drawInFront), + _isAA(base3DOverlay->_isAA) { setTransform(base3DOverlay->getTransform()); } @@ -175,6 +177,13 @@ void Base3DOverlay::setProperties(const QVariantMap& originalProperties) { needRenderItemUpdate = true; } + auto isAA = properties["isAA"]; + if (isAA.isValid()) { + bool value = isAA.toBool(); + setIsAA(value); + needRenderItemUpdate = true; + } + // Communicate changes to the renderItem if needed if (needRenderItemUpdate) { auto itemID = getRenderItemID(); @@ -224,6 +233,9 @@ QVariant Base3DOverlay::getProperty(const QString& property) { if (property == "parentJointIndex") { return getParentJointIndex(); } + if (property == "isAA") { + return _isAA; + } return Overlay::getProperty(property); } diff --git a/interface/src/ui/overlays/Base3DOverlay.h b/interface/src/ui/overlays/Base3DOverlay.h index 1860af4e85..18936df504 100644 --- a/interface/src/ui/overlays/Base3DOverlay.h +++ b/interface/src/ui/overlays/Base3DOverlay.h @@ -36,11 +36,14 @@ public: bool getIgnoreRayIntersection() const { return _ignoreRayIntersection; } bool getDrawInFront() const { return _drawInFront; } + virtual bool isAA() const { return _isAA; } + void setLineWidth(float lineWidth) { _lineWidth = lineWidth; } void setIsSolid(bool isSolid) { _isSolid = isSolid; } void setIsDashedLine(bool isDashedLine) { _isDashedLine = isDashedLine; } void setIgnoreRayIntersection(bool value) { _ignoreRayIntersection = value; } void setDrawInFront(bool value) { _drawInFront = value; } + void setIsAA(bool value) { _isAA = value; } virtual AABox getBounds() const override = 0; @@ -64,6 +67,7 @@ protected: bool _isDashedLine; bool _ignoreRayIntersection; bool _drawInFront; + bool _isAA; }; #endif // hifi_Base3DOverlay_h diff --git a/interface/src/ui/overlays/OverlaysPayload.cpp b/interface/src/ui/overlays/OverlaysPayload.cpp index 7cc74d60e0..277a86e93f 100644 --- a/interface/src/ui/overlays/OverlaysPayload.cpp +++ b/interface/src/ui/overlays/OverlaysPayload.cpp @@ -38,6 +38,9 @@ namespace render { if (std::static_pointer_cast(overlay)->getDrawInFront()) { builder.withLayered(); } + if (!std::static_pointer_cast(overlay)->isAA()) { + builder.withLayered(); + } if (overlay->getAlphaPulse() != 0.0f || overlay->getAlpha() != 1.0f) { builder.withTransparent(); } @@ -51,11 +54,17 @@ namespace render { } template <> int payloadGetLayer(const Overlay::Pointer& overlay) { // MAgic number while we are defining the layering mechanism: - const int LAYER_2D = 2; + const int LAYER_NO_AA = 3; + const int LAYER_2D = 2; const int LAYER_3D_FRONT = 1; const int LAYER_3D = 0; + if (overlay->is3D()) { - return (std::dynamic_pointer_cast(overlay)->getDrawInFront() ? LAYER_3D_FRONT : LAYER_3D); + auto overlay3D = std::dynamic_pointer_cast(overlay); + if (overlay3D->isAA()) + return (overlay3D->getDrawInFront() ? LAYER_3D_FRONT : LAYER_3D); + else + return LAYER_NO_AA; } else { return LAYER_2D; } diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index bf708c738d..f33ef24c0d 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -249,9 +249,9 @@ void Web3DOverlay::render(RenderArgs* args) { batch.setModelTransform(transform); auto geometryCache = DependencyManager::get(); if (color.a < OPAQUE_ALPHA_THRESHOLD) { - geometryCache->bindTransparentWebBrowserProgram(batch); + geometryCache->bindTransparentWebBrowserProgram(batch, _isAA); } else { - geometryCache->bindOpaqueWebBrowserProgram(batch); + geometryCache->bindOpaqueWebBrowserProgram(batch, _isAA); } geometryCache->renderQuad(batch, halfSize * -1.0f, halfSize, vec2(0), vec2(1), color, _geometryId); batch.setResourceTexture(0, args->_whiteTexture); // restore default white color after me diff --git a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp index e8353a1595..972c23d534 100644 --- a/libraries/entities-renderer/src/RenderableWebEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableWebEntityItem.cpp @@ -241,10 +241,11 @@ void RenderableWebEntityItem::render(RenderArgs* args) { batch._glColor4f(1.0f, 1.0f, 1.0f, fadeRatio); + const bool IS_AA = true; if (fadeRatio < OPAQUE_ALPHA_THRESHOLD) { - DependencyManager::get()->bindTransparentWebBrowserProgram(batch); + DependencyManager::get()->bindTransparentWebBrowserProgram(batch, IS_AA); } else { - DependencyManager::get()->bindOpaqueWebBrowserProgram(batch); + DependencyManager::get()->bindOpaqueWebBrowserProgram(batch, IS_AA); } DependencyManager::get()->renderQuad(batch, topLeft, bottomRight, texMin, texMax, glm::vec4(1.0f, 1.0f, 1.0f, fadeRatio), _geometryId); } diff --git a/libraries/render-utils/src/GeometryCache.cpp b/libraries/render-utils/src/GeometryCache.cpp index a19f1844f0..c277b9be64 100644 --- a/libraries/render-utils/src/GeometryCache.cpp +++ b/libraries/render-utils/src/GeometryCache.cpp @@ -36,7 +36,9 @@ #include "simple_textured_frag.h" #include "simple_textured_unlit_frag.h" #include "simple_opaque_web_browser_frag.h" +#include "simple_opaque_web_browser_overlay_frag.h" #include "simple_transparent_web_browser_frag.h" +#include "simple_transparent_web_browser_overlay_frag.h" #include "glowLine_vert.h" #include "glowLine_frag.h" @@ -1760,66 +1762,61 @@ inline bool operator==(const SimpleProgramKey& a, const SimpleProgramKey& b) { return a.getRaw() == b.getRaw(); } -void GeometryCache::bindOpaqueWebBrowserProgram(gpu::Batch& batch) { - batch.setPipeline(getOpaqueWebBrowserProgram()); +static void buildWebShader(const std::string& vertShaderText, const std::string& fragShaderText, bool blendEnable, + gpu::ShaderPointer& shaderPointerOut, gpu::PipelinePointer& pipelinePointerOut) { + auto VS = gpu::Shader::createVertex(vertShaderText); + auto PS = gpu::Shader::createPixel(fragShaderText); + + shaderPointerOut = gpu::Shader::createProgram(VS, PS); + + gpu::Shader::BindingSet slotBindings; + slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING)); + gpu::Shader::makeProgram(*shaderPointerOut, slotBindings); + auto state = std::make_shared(); + state->setCullMode(gpu::State::CULL_NONE); + state->setDepthTest(true, true, gpu::LESS_EQUAL); + state->setBlendFunction(blendEnable, + gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, + gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); + + pipelinePointerOut = gpu::Pipeline::create(shaderPointerOut, state); +} + +void GeometryCache::bindOpaqueWebBrowserProgram(gpu::Batch& batch, bool isAA) { + batch.setPipeline(getOpaqueWebBrowserProgram(isAA)); // Set a default normal map batch.setResourceTexture(render::ShapePipeline::Slot::MAP::NORMAL_FITTING, DependencyManager::get()->getNormalFittingTexture()); } -gpu::PipelinePointer GeometryCache::getOpaqueWebBrowserProgram() { +gpu::PipelinePointer GeometryCache::getOpaqueWebBrowserProgram(bool isAA) { static std::once_flag once; std::call_once(once, [&]() { - auto VS = gpu::Shader::createVertex(std::string(simple_vert)); - auto PS = gpu::Shader::createPixel(std::string(simple_opaque_web_browser_frag)); - - _simpleOpaqueWebBrowserShader = gpu::Shader::createProgram(VS, PS); - - gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING)); - gpu::Shader::makeProgram(*_simpleOpaqueWebBrowserShader, slotBindings); - auto state = std::make_shared(); - state->setCullMode(gpu::State::CULL_NONE); - state->setDepthTest(true, true, gpu::LESS_EQUAL); - state->setBlendFunction(false, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - - _simpleOpaqueWebBrowserPipeline = gpu::Pipeline::create(_simpleOpaqueWebBrowserShader, state); + const bool BLEND_ENABLE = false; + buildWebShader(simple_vert, simple_opaque_web_browser_frag, BLEND_ENABLE, _simpleOpaqueWebBrowserShader, _simpleOpaqueWebBrowserPipeline); + buildWebShader(simple_vert, simple_opaque_web_browser_overlay_frag, BLEND_ENABLE, _simpleOpaqueWebBrowserOverlayShader, _simpleOpaqueWebBrowserOverlayPipeline); }); - return _simpleOpaqueWebBrowserPipeline; + return isAA ? _simpleOpaqueWebBrowserPipeline : _simpleOpaqueWebBrowserOverlayPipeline; } -void GeometryCache::bindTransparentWebBrowserProgram(gpu::Batch& batch) { - batch.setPipeline(getTransparentWebBrowserProgram()); +void GeometryCache::bindTransparentWebBrowserProgram(gpu::Batch& batch, bool isAA) { + batch.setPipeline(getTransparentWebBrowserProgram(isAA)); // Set a default normal map batch.setResourceTexture(render::ShapePipeline::Slot::MAP::NORMAL_FITTING, DependencyManager::get()->getNormalFittingTexture()); } -gpu::PipelinePointer GeometryCache::getTransparentWebBrowserProgram() { +gpu::PipelinePointer GeometryCache::getTransparentWebBrowserProgram(bool isAA) { static std::once_flag once; std::call_once(once, [&]() { - auto VS = gpu::Shader::createVertex(std::string(simple_vert)); - auto PS = gpu::Shader::createPixel(std::string(simple_transparent_web_browser_frag)); - _simpleTransparentWebBrowserShader = gpu::Shader::createProgram(VS, PS); - - gpu::Shader::BindingSet slotBindings; - slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), render::ShapePipeline::Slot::MAP::NORMAL_FITTING)); - gpu::Shader::makeProgram(*_simpleTransparentWebBrowserShader, slotBindings); - auto state = std::make_shared(); - state->setCullMode(gpu::State::CULL_NONE); - state->setDepthTest(true, true, gpu::LESS_EQUAL); - state->setBlendFunction(true, - gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, - gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE); - - _simpleTransparentWebBrowserPipeline = gpu::Pipeline::create(_simpleTransparentWebBrowserShader, state); + const bool BLEND_ENABLE = true; + buildWebShader(simple_vert, simple_transparent_web_browser_frag, BLEND_ENABLE, _simpleTransparentWebBrowserShader, _simpleTransparentWebBrowserPipeline); + buildWebShader(simple_vert, simple_transparent_web_browser_overlay_frag, BLEND_ENABLE, _simpleTransparentWebBrowserOverlayShader, _simpleTransparentWebBrowserOverlayPipeline); }); - return _simpleTransparentWebBrowserPipeline; + return isAA ? _simpleTransparentWebBrowserPipeline : _simpleTransparentWebBrowserOverlayPipeline; } void GeometryCache::bindSimpleProgram(gpu::Batch& batch, bool textured, bool transparent, bool culled, bool unlit, bool depthBiased) { diff --git a/libraries/render-utils/src/GeometryCache.h b/libraries/render-utils/src/GeometryCache.h index 84dfd8ccc3..e0a610a095 100644 --- a/libraries/render-utils/src/GeometryCache.h +++ b/libraries/render-utils/src/GeometryCache.h @@ -158,11 +158,11 @@ public: gpu::PipelinePointer getSimplePipeline(bool textured = false, bool transparent = false, bool culled = true, bool unlit = false, bool depthBias = false); - void bindOpaqueWebBrowserProgram(gpu::Batch& batch); - gpu::PipelinePointer getOpaqueWebBrowserProgram(); + void bindOpaqueWebBrowserProgram(gpu::Batch& batch, bool isAA); + gpu::PipelinePointer getOpaqueWebBrowserProgram(bool isAA); - void bindTransparentWebBrowserProgram(gpu::Batch& batch); - gpu::PipelinePointer getTransparentWebBrowserProgram(); + void bindTransparentWebBrowserProgram(gpu::Batch& batch, bool isAA); + gpu::PipelinePointer getTransparentWebBrowserProgram(bool isAA); render::ShapePipelinePointer getOpaqueShapePipeline() { return GeometryCache::_simpleOpaquePipeline; } render::ShapePipelinePointer getTransparentShapePipeline() { return GeometryCache::_simpleTransparentPipeline; } @@ -420,15 +420,21 @@ private: gpu::ShaderPointer _unlitShader; static render::ShapePipelinePointer _simpleOpaquePipeline; static render::ShapePipelinePointer _simpleTransparentPipeline; + static render::ShapePipelinePointer _simpleOpaqueOverlayPipeline; + static render::ShapePipelinePointer _simpleTransparentOverlayPipeline; static render::ShapePipelinePointer _simpleWirePipeline; gpu::PipelinePointer _glowLinePipeline; QHash _simplePrograms; gpu::ShaderPointer _simpleOpaqueWebBrowserShader; gpu::PipelinePointer _simpleOpaqueWebBrowserPipeline; - gpu::ShaderPointer _simpleTransparentWebBrowserShader; gpu::PipelinePointer _simpleTransparentWebBrowserPipeline; + + gpu::ShaderPointer _simpleOpaqueWebBrowserOverlayShader; + gpu::PipelinePointer _simpleOpaqueWebBrowserOverlayPipeline; + gpu::ShaderPointer _simpleTransparentWebBrowserOverlayShader; + gpu::PipelinePointer _simpleTransparentWebBrowserOverlayPipeline; }; #endif // hifi_GeometryCache_h diff --git a/libraries/render-utils/src/RenderDeferredTask.cpp b/libraries/render-utils/src/RenderDeferredTask.cpp index e0192b5f85..55a9c8b9e4 100644 --- a/libraries/render-utils/src/RenderDeferredTask.cpp +++ b/libraries/render-utils/src/RenderDeferredTask.cpp @@ -63,6 +63,10 @@ RenderDeferredTask::RenderDeferredTask(RenderFetchCullSortTask::Output items) { const auto background = items[RenderFetchCullSortTask::BACKGROUND]; const auto spatialSelection = items[RenderFetchCullSortTask::SPATIAL_SELECTION]; + // Filter the non antialiaased overlays + const int LAYER_NO_AA = 3; + const auto nonAAOverlays = addJob("Filter2DWebOverlays", overlayOpaques, LAYER_NO_AA); + // Prepare deferred, generate the shared Deferred Frame Transform const auto deferredFrameTransform = addJob("DeferredFrameTransform"); const auto lightingModel = addJob("LightingModel"); @@ -195,6 +199,10 @@ RenderDeferredTask::RenderDeferredTask(RenderFetchCullSortTask::Output items) { // AA job to be revisited addJob("Antialiasing", primaryFramebuffer); + // Draw 2DWeb non AA + const auto nonAAOverlaysInputs = DrawOverlay3D::Inputs(nonAAOverlays, lightingModel).hasVarying(); + addJob("Draw2DWebSurfaces", nonAAOverlaysInputs, false); + addJob("ToneAndPostRangeTimer", toneAndPostRangeTimer); // Blit! diff --git a/libraries/render-utils/src/simple_opaque_web_browser.slf b/libraries/render-utils/src/simple_opaque_web_browser.slf index 2921d6aea0..3acf104b55 100644 --- a/libraries/render-utils/src/simple_opaque_web_browser.slf +++ b/libraries/render-utils/src/simple_opaque_web_browser.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// simple_opaque_web_browser.frag +// simple_opaque_web_browser.slf // fragment shader // // Created by Anthony Thibault on 7/25/16. diff --git a/libraries/render-utils/src/simple_opaque_web_browser_overlay.slf b/libraries/render-utils/src/simple_opaque_web_browser_overlay.slf new file mode 100644 index 0000000000..6d4d35591f --- /dev/null +++ b/libraries/render-utils/src/simple_opaque_web_browser_overlay.slf @@ -0,0 +1,30 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_opaque_web_browser_overlay.slf +// fragment shader +// +// Created by Anthony Thibault on 1/30/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Same as simple_opaque_web_browser.slf except frame buffer is sRGB, so colorToLinearRGBA is not necessary. + +<@include gpu/Color.slh@> +<@include DeferredBufferWrite.slh@> + +// the albedo texture +uniform sampler2D originalTexture; + +// the interpolated normal +in vec3 _normal; +in vec4 _color; +in vec2 _texCoord0; + +void main(void) { + vec4 texel = texture(originalTexture, _texCoord0.st); + _fragColor0 = vec4(_color.rgb * texel.rgb, 1.0); +} diff --git a/libraries/render-utils/src/simple_transparent_web_browser.slf b/libraries/render-utils/src/simple_transparent_web_browser.slf index b7606985e6..19079f5d92 100644 --- a/libraries/render-utils/src/simple_transparent_web_browser.slf +++ b/libraries/render-utils/src/simple_transparent_web_browser.slf @@ -2,7 +2,7 @@ <$VERSION_HEADER$> // Generated on <$_SCRIBE_DATE$> // -// simple_transparent_web_browser.frag +// simple_transparent_web_browser.slf // fragment shader // // Created by Anthony Thibault on 7/25/16. @@ -33,4 +33,3 @@ void main(void) { DEFAULT_FRESNEL, DEFAULT_ROUGHNESS); } - diff --git a/libraries/render-utils/src/simple_transparent_web_browser_overlay.slf b/libraries/render-utils/src/simple_transparent_web_browser_overlay.slf new file mode 100644 index 0000000000..af52389d5b --- /dev/null +++ b/libraries/render-utils/src/simple_transparent_web_browser_overlay.slf @@ -0,0 +1,31 @@ +<@include gpu/Config.slh@> +<$VERSION_HEADER$> +// Generated on <$_SCRIBE_DATE$> +// +// simple_transparent_web_browser_overlay.slf +// fragment shader +// +// Created by Anthony Thibault on 1/30/17. +// Copyright 2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// +// Same as simple_transparent_web_browser.slf except frame buffer is sRGB, So colorToLinearRGBA is not necessary. +// + +<@include gpu/Color.slh@> +<@include DeferredBufferWrite.slh@> + +// the albedo texture +uniform sampler2D originalTexture; + +// the interpolated normal +in vec3 _normal; +in vec4 _color; +in vec2 _texCoord0; + +void main(void) { + vec4 texel = texture(originalTexture, _texCoord0.st); + _fragColor0 = vec4(_color.rgb * texel.rgb, _color.a); +} diff --git a/libraries/render/src/render/CullTask.cpp b/libraries/render/src/render/CullTask.cpp index e27895352f..42f95f458f 100644 --- a/libraries/render/src/render/CullTask.cpp +++ b/libraries/render/src/render/CullTask.cpp @@ -306,3 +306,19 @@ void CullSpatialSelection::run(const SceneContextPointer& sceneContext, const Re std::static_pointer_cast(renderContext->jobConfig)->numItems = (int)outItems.size(); } + + +void FilterItemLayer::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemBounds& outItems) { + auto& scene = sceneContext->_scene; + + // Clear previous values + outItems.clear(); + + // For each item, filter it into one bucket + for (auto itemBound : inItems) { + auto& item = scene->getItem(itemBound.id); + if (item.getLayer() == _keepLayer) { + outItems.emplace_back(itemBound); + } + } +} \ No newline at end of file diff --git a/libraries/render/src/render/CullTask.h b/libraries/render/src/render/CullTask.h index 1a709ed102..f613faa2e6 100644 --- a/libraries/render/src/render/CullTask.h +++ b/libraries/render/src/render/CullTask.h @@ -175,6 +175,19 @@ namespace render { } } }; + + class FilterItemLayer { + public: + using JobModel = Job::ModelIO; + + FilterItemLayer() {} + FilterItemLayer(int keepLayer) : + _keepLayer(keepLayer) {} + + int _keepLayer { 0 }; + + void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const ItemBounds& inItems, ItemBounds& outItems); + }; } #endif // hifi_render_CullTask_h; \ No newline at end of file diff --git a/libraries/script-engine/src/SoundEffect.cpp b/libraries/script-engine/src/SoundEffect.cpp new file mode 100644 index 0000000000..6833bb1f31 --- /dev/null +++ b/libraries/script-engine/src/SoundEffect.cpp @@ -0,0 +1,39 @@ + +#include "SoundEffect.h" + +#include +#include + +SoundEffect::~SoundEffect() { + if (_sound) { + _sound->deleteLater(); + } + if (_injector) { + // stop will cause the AudioInjector to delete itself. + _injector->stop(); + } +} + +QUrl SoundEffect::getSource() const { + return _url; +} + +void SoundEffect::setSource(QUrl url) { + _url = url; + _sound = DependencyManager::get()->getSound(_url); +} + +void SoundEffect::play(QVariant position) { + AudioInjectorOptions options; + options.position = vec3FromVariant(position); + options.localOnly = true; + if (_injector) { + _injector->setOptions(options); + _injector->restart(); + } else { + QByteArray samples = _sound->getByteArray(); + _injector = AudioInjector::playSound(samples, options); + } +} + +#include "SoundEffect.moc" diff --git a/libraries/script-engine/src/SoundEffect.h b/libraries/script-engine/src/SoundEffect.h new file mode 100644 index 0000000000..5d2a5095c1 --- /dev/null +++ b/libraries/script-engine/src/SoundEffect.h @@ -0,0 +1,39 @@ +// +// Created by Anthony J. Thibault on 2017-01-30 +// Copyright 2013-2017 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_SoundEffect_h +#define hifi_SoundEffect_h + +#include +#include + +#include + +class AudioInjector; + +// SoundEffect object, exposed to qml only, not interface JavaScript. +// This is used to play spatial sound effects on tablets/web entities from within QML. + +class SoundEffect : public QQuickItem { + Q_OBJECT + Q_PROPERTY(QUrl source READ getSource WRITE setSource) +public: + + virtual ~SoundEffect(); + + QUrl getSource() const; + void setSource(QUrl url); + + Q_INVOKABLE void play(QVariant position); +protected: + QUrl _url; + SharedSoundPointer _sound; + AudioInjector* _injector { nullptr }; +}; + +#endif // hifi_SoundEffect_h diff --git a/libraries/script-engine/src/TabletScriptingInterface.cpp b/libraries/script-engine/src/TabletScriptingInterface.cpp index 0e829b6953..d73cb980f6 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.cpp +++ b/libraries/script-engine/src/TabletScriptingInterface.cpp @@ -1,5 +1,5 @@ // -// Created by Bradley Austin Davis on 2016-06-16 +// Created by Anthony J. Thibault on 2016-12-12 // Copyright 2013-2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. @@ -10,13 +10,13 @@ #include -#include #include #include #include #include "ScriptEngineLogging.h" #include "DependencyManager.h" #include "OffscreenUi.h" +#include "SoundEffect.h" TabletScriptingInterface::TabletScriptingInterface() { qmlRegisterType("Hifi", 1, 0, "SoundEffect"); @@ -416,47 +416,5 @@ void TabletButtonProxy::editProperties(QVariantMap properties) { } } -// -// SoundEffect -// - -SoundEffect::~SoundEffect() { - if (_sound) { - _sound->deleteLater(); - } - if (_injector) { - // stop will cause the AudioInjector to delete itself. - _injector->stop(); - } -} - -QUrl SoundEffect::getSource() const { - return _url; -} - -void SoundEffect::setSource(QUrl url) { - _url = url; - _sound = DependencyManager::get()->getSound(_url); -} - -void SoundEffect::play(QVariant position) { - auto tsi = DependencyManager::get(); - if (tsi) { - TabletProxy* tablet = qobject_cast(tsi->getTablet("com.highfidelity.interface.tablet.system")); - if (tablet) { - AudioInjectorOptions options; - options.position = vec3FromVariant(position); - options.localOnly = true; - if (_injector) { - _injector->setOptions(options); - _injector->restart(); - } else { - QByteArray samples = _sound->getByteArray(); - _injector = AudioInjector::playSound(samples, options); - } - } - } -} - #include "TabletScriptingInterface.moc" diff --git a/libraries/script-engine/src/TabletScriptingInterface.h b/libraries/script-engine/src/TabletScriptingInterface.h index 4afb3cad0e..b0b2d00e0f 100644 --- a/libraries/script-engine/src/TabletScriptingInterface.h +++ b/libraries/script-engine/src/TabletScriptingInterface.h @@ -23,11 +23,9 @@ #include #include -#include class TabletProxy; class TabletButtonProxy; -class AudioInjector; /**jsdoc * @namespace Tablet @@ -201,24 +199,4 @@ protected: QVariantMap _properties; }; - -// Exposed to qml only, not java script -class SoundEffect : public QQuickItem { - Q_OBJECT - Q_PROPERTY(QUrl source READ getSource WRITE setSource) -public: - - virtual ~SoundEffect(); - - QUrl getSource() const; - void setSource(QUrl url); - - Q_INVOKABLE void play(QVariant position); -protected: - QUrl _url; - SharedSoundPointer _sound; - AudioInjector* _injector { nullptr }; -}; - - #endif // hifi_TabletScriptingInterface_h diff --git a/scripts/system/libraries/WebTablet.js b/scripts/system/libraries/WebTablet.js index a342597c2d..65551b2140 100644 --- a/scripts/system/libraries/WebTablet.js +++ b/scripts/system/libraries/WebTablet.js @@ -128,7 +128,8 @@ WebTablet = function (url, width, dpi, hand, clientOnly) { alpha: 1.0, parentID: this.tabletEntityID, parentJointIndex: -1, - showKeyboardFocusHighlight: false + showKeyboardFocusHighlight: false, + isAA: HMD.active }); var HOME_BUTTON_Y_OFFSET = (this.height / 2) - 0.035; @@ -222,7 +223,6 @@ WebTablet.prototype.destroy = function () { Overlays.deleteOverlay(this.homeButtonEntity); HMD.displayModeChanged.disconnect(this.myOnHmdChanged); - Controller.mousePressEvent.disconnect(this.myMousePressEvent); Controller.mouseMoveEvent.disconnect(this.myMouseMoveEvent); Controller.mouseReleaseEvent.disconnect(this.myMouseReleaseEvent); @@ -293,6 +293,10 @@ WebTablet.prototype.onHmdChanged = function () { // compute position, rotation & parentJointIndex of the tablet this.calculateTabletAttachmentProperties(NO_HANDS, tabletProperties); Entities.editEntity(this.tabletEntityID, tabletProperties); + + // Full scene FXAA should be disabled on the overlay when the tablet in desktop mode. + // This should make the text more readable. + Overlays.editOverlay(this.webOverlayID, { isAA: HMD.active }); }; WebTablet.prototype.pickle = function () { @@ -357,7 +361,7 @@ WebTablet.prototype.mousePressEvent = function (event) { tablet.gotoHomeScreen(); this.setHomeButtonTexture(); } - } else if (!overlayPickResults.intersects || !overlayPickResults.overlayID === this.webOverlayID) { + } else if (!HMD.active && (!overlayPickResults.intersects || !overlayPickResults.overlayID === this.webOverlayID)) { this.dragging = true; var invCameraXform = new Xform(Camera.orientation, Camera.position).inv(); this.initialLocalIntersectionPoint = invCameraXform.xformPoint(entityPickResults.intersection);