diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp index aa1233ce22..73bc1d0aad 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.cpp @@ -593,9 +593,10 @@ std::function OpenGL hudEyeViewports[eye] = eyeViewport(eye); }); return [=](gpu::Batch& batch, const gpu::TexturePointer& hudTexture, bool mirror) { - if (hudPipeline && hudTexture) { + auto pipeline = mirror ? hudMirrorPipeline : hudPipeline; + if (pipeline && hudTexture) { batch.enableStereo(false); - batch.setPipeline(mirror ? hudMirrorPipeline : hudPipeline); + batch.setPipeline(pipeline); batch.setResourceTexture(0, hudTexture); if (hudStereo) { for_each_eye([&](Eye eye) { @@ -661,17 +662,6 @@ void OpenGLDisplayPlugin::compositeLayers() { compositeScene(); } -#ifdef HIFI_ENABLE_NSIGHT_DEBUG - if (false) // do not draw the HUD if running nsight debug -#endif - { - PROFILE_RANGE_EX(render_detail, "handleHUDBatch", 0xff0077ff, (uint64_t)presentCount()) - auto hudOperator = getHUDOperator(); - withPresentThreadLock([&] { - _hudOperator = hudOperator; - }); - } - { PROFILE_RANGE_EX(render_detail, "compositeExtra", 0xff0077ff, (uint64_t)presentCount()) compositeExtra(); diff --git a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h index 672d9a4beb..eae9f86710 100644 --- a/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/OpenGLDisplayPlugin.h @@ -86,6 +86,8 @@ public: void copyTextureToQuickFramebuffer(NetworkTexturePointer source, QOpenGLFramebufferObject* target, GLsync* fenceSync) override; + virtual std::function getHUDOperator() override; + protected: friend class PresentThread; @@ -102,7 +104,6 @@ protected: virtual QThread::Priority getPresentPriority() { return QThread::HighPriority; } virtual void compositeLayers(); virtual void compositeScene(); - virtual std::function getHUDOperator(); virtual void compositePointer(); virtual void compositeExtra() {}; diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp index 874454b391..3952c2c90e 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.cpp @@ -1,4 +1,4 @@ -// +// // Created by Bradley Austin Davis on 2016/02/15 // Copyright 2016 High Fidelity, Inc. // @@ -402,25 +402,18 @@ void HmdDisplayPlugin::HUDRenderer::build() { format->setAttribute(gpu::Stream::POSITION, gpu::Stream::POSITION, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0); format->setAttribute(gpu::Stream::TEXCOORD, gpu::Stream::TEXCOORD, gpu::Element(gpu::VEC2, gpu::FLOAT, gpu::UV)); uniformsBuffer = std::make_shared(sizeof(Uniforms), nullptr); - updatePipeline(); + + auto program = gpu::Shader::createProgram(shader::render_utils::program::hmd_ui); + gpu::StatePointer state = gpu::StatePointer(new gpu::State()); + state->setDepthTest(gpu::State::DepthTest(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); + + pipeline = gpu::Pipeline::create(program, state); } -void HmdDisplayPlugin::HUDRenderer::updatePipeline() { - if (!pipeline) { - auto program = gpu::Shader::createProgram(shader::render_utils::program::hmd_ui); - gpu::StatePointer state = gpu::StatePointer(new gpu::State()); - state->setDepthTest(gpu::State::DepthTest(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); - - pipeline = gpu::Pipeline::create(program, state); - } -} - -std::function HmdDisplayPlugin::HUDRenderer::render(HmdDisplayPlugin& plugin) { - updatePipeline(); - +std::function HmdDisplayPlugin::HUDRenderer::render() { auto hudPipeline = pipeline; auto hudFormat = format; auto hudVertices = vertices; @@ -479,7 +472,7 @@ void HmdDisplayPlugin::compositePointer() { } std::function HmdDisplayPlugin::getHUDOperator() { - return _hudRenderer.render(*this); + return _hudRenderer.render(); } HmdDisplayPlugin::~HmdDisplayPlugin() { diff --git a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h index e952b1e8db..9942222f48 100644 --- a/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h +++ b/libraries/display-plugins/src/display-plugins/hmd/HmdDisplayPlugin.h @@ -48,6 +48,7 @@ public: void pluginUpdate() override {}; + std::function getHUDOperator() override; virtual StencilMaskMode getStencilMaskMode() const override { return StencilMaskMode::PAINT; } signals: @@ -62,7 +63,6 @@ protected: bool internalActivate() override; void internalDeactivate() override; - std::function getHUDOperator() override; void compositePointer() override; void internalPresent() override; void customizeContext() override; @@ -105,7 +105,7 @@ private: gpu::BufferPointer vertices; gpu::BufferPointer indices; uint32_t indexCount { 0 }; - gpu::PipelinePointer pipeline; + gpu::PipelinePointer pipeline { nullptr }; gpu::BufferPointer uniformsBuffer; @@ -123,7 +123,6 @@ private: static const int VERTEX_STRIDE { sizeof(Vertex) }; void build(); - void updatePipeline(); - std::function render(HmdDisplayPlugin& plugin); + std::function render(); } _hudRenderer; }; diff --git a/libraries/physics/src/PhysicalEntitySimulation.cpp b/libraries/physics/src/PhysicalEntitySimulation.cpp index f532d5209f..0a08aaa28d 100644 --- a/libraries/physics/src/PhysicalEntitySimulation.cpp +++ b/libraries/physics/src/PhysicalEntitySimulation.cpp @@ -309,20 +309,28 @@ void PhysicalEntitySimulation::buildMotionStatesForEntitiesThatNeedThem() { SetOfEntities::iterator entityItr = _entitiesToAddToPhysics.begin(); while (entityItr != _entitiesToAddToPhysics.end()) { EntityItemPointer entity = (*entityItr); - assert(!entity->getPhysicsInfo()); if (entity->isDead()) { prepareEntityForDelete(entity); entityItr = _entitiesToAddToPhysics.erase(entityItr); - } else if (!entity->shouldBePhysical()) { - // this entity should no longer be on _entitiesToAddToPhysics + continue; + } + if (entity->getPhysicsInfo()) { entityItr = _entitiesToAddToPhysics.erase(entityItr); + continue; + } + if (!entity->shouldBePhysical()) { + // this entity should no longer be on _entitiesToAddToPhysics if (entity->isMovingRelativeToParent()) { SetOfEntities::iterator itr = _simpleKinematicEntities.find(entity); if (itr == _simpleKinematicEntities.end()) { _simpleKinematicEntities.insert(entity); } } - } else if (entity->isReadyToComputeShape()) { + entityItr = _entitiesToAddToPhysics.erase(entityItr); + continue; + } + + if (entity->isReadyToComputeShape()) { ShapeRequest shapeRequest(entity); ShapeRequests::iterator requestItr = _shapeRequests.find(shapeRequest); if (requestItr == _shapeRequests.end()) { @@ -332,18 +340,7 @@ void PhysicalEntitySimulation::buildMotionStatesForEntitiesThatNeedThem() { uint32_t requestCount = ObjectMotionState::getShapeManager()->getWorkRequestCount(); btCollisionShape* shape = const_cast(ObjectMotionState::getShapeManager()->getShape(shapeInfo)); if (shape) { - EntityMotionState* motionState = static_cast(entity->getPhysicsInfo()); - if (!motionState) { - buildMotionState(shape, entity); - } else { - // Is it possible to fall in here? - // entity shouldn't be on _entitiesToAddToPhysics list if it already has a motionState. - // but just in case... - motionState->setShape(shape); - motionState->setRegion(_space->getRegion(entity->getSpaceIndex())); - _physicalObjects.insert(motionState); - _incomingChanges.insert(motionState); - } + buildMotionState(shape, entity); } else if (requestCount != ObjectMotionState::getShapeManager()->getWorkRequestCount()) { // shape doesn't exist but a new worker has been spawned to build it --> add to shapeRequests and wait shapeRequest.shapeHash = shapeInfo.getHash(); @@ -354,6 +351,7 @@ void PhysicalEntitySimulation::buildMotionStatesForEntitiesThatNeedThem() { } entityItr = _entitiesToAddToPhysics.erase(entityItr); } else { + // skip for later ++entityItr; } } diff --git a/libraries/physics/src/ThreadSafeDynamicsWorld.cpp b/libraries/physics/src/ThreadSafeDynamicsWorld.cpp index f6189121a9..00b8a71831 100644 --- a/libraries/physics/src/ThreadSafeDynamicsWorld.cpp +++ b/libraries/physics/src/ThreadSafeDynamicsWorld.cpp @@ -181,7 +181,7 @@ void ThreadSafeDynamicsWorld::drawConnectedSpheres(btIDebugDraw* drawer, btScala btVector3 xAxis = direction.cross(btVector3(0.0f, 1.0f, 0.0f)); xAxis = xAxis.length() < EPSILON ? btVector3(1.0f, 0.0f, 0.0f) : xAxis.normalize(); btVector3 zAxis = xAxis.cross(btVector3(0.0f, 1.0f, 0.0f)); - zAxis = (direction.normalize().getY() < EPSILON) ? btVector3(0.0f, 1.0f, 0.0f) : zAxis.normalize(); + zAxis = (direction.length2() < EPSILON || direction.normalize().getY() < EPSILON) ? btVector3(0.0f, 1.0f, 0.0f) : zAxis.normalize(); float fullCircle = 2.0f * PI; for (float i = 0; i < fullCircle; i += stepRadians) { float x1 = btSin(btScalar(i)) * radius1; diff --git a/libraries/plugins/src/plugins/DisplayPlugin.cpp b/libraries/plugins/src/plugins/DisplayPlugin.cpp index 47503e8f85..2fe3d5fbea 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.cpp +++ b/libraries/plugins/src/plugins/DisplayPlugin.cpp @@ -35,15 +35,6 @@ void DisplayPlugin::waitForPresent() { } } -std::function DisplayPlugin::getHUDOperator() { - std::function hudOperator; - { - QMutexLocker locker(&_presentMutex); - hudOperator = _hudOperator; - } - return hudOperator; -} - glm::mat4 HmdDisplay::getEyeToHeadTransform(Eye eye) const { static const glm::mat4 xform; return xform; diff --git a/libraries/plugins/src/plugins/DisplayPlugin.h b/libraries/plugins/src/plugins/DisplayPlugin.h index 9dc1d7002d..1cad9b1e11 100644 --- a/libraries/plugins/src/plugins/DisplayPlugin.h +++ b/libraries/plugins/src/plugins/DisplayPlugin.h @@ -213,13 +213,12 @@ public: void waitForPresent(); float getAveragePresentTime() { return _movingAveragePresent.average / (float)USECS_PER_MSEC; } // in msec - std::function getHUDOperator(); - static const QString& MENU_PATH(); // for updating plugin-related commands. Mimics the input plugin. virtual void pluginUpdate() = 0; + virtual std::function getHUDOperator() { return nullptr; } virtual StencilMaskMode getStencilMaskMode() const { return StencilMaskMode::NONE; } using StencilMaskMeshOperator = std::function; virtual StencilMaskMeshOperator getStencilMaskMeshOperator() { return nullptr; } @@ -234,8 +233,6 @@ protected: gpu::ContextPointer _gpuContext; - std::function _hudOperator { std::function() }; - MovingAverage _movingAveragePresent; float _renderResolutionScale { 1.0f }; diff --git a/libraries/render-utils/src/RenderCommonTask.cpp b/libraries/render-utils/src/RenderCommonTask.cpp index 18532b7a66..ae53539770 100644 --- a/libraries/render-utils/src/RenderCommonTask.cpp +++ b/libraries/render-utils/src/RenderCommonTask.cpp @@ -111,7 +111,7 @@ void CompositeHUD::run(const RenderContextPointer& renderContext, const gpu::Fra assert(renderContext->args->_context); // We do not want to render HUD elements in secondary camera - if (renderContext->args->_renderMode == RenderArgs::RenderMode::SECONDARY_CAMERA_RENDER_MODE) { + if (nsightActive() || renderContext->args->_renderMode == RenderArgs::RenderMode::SECONDARY_CAMERA_RENDER_MODE) { return; } diff --git a/libraries/render/src/render/Args.h b/libraries/render/src/render/Args.h index 7821692a60..1798208981 100644 --- a/libraries/render/src/render/Args.h +++ b/libraries/render/src/render/Args.h @@ -124,20 +124,20 @@ namespace render { DebugFlags _debugFlags { RENDER_DEBUG_NONE }; gpu::Batch* _batch = nullptr; - uint32_t _globalShapeKey{ 0 }; - uint32_t _itemShapeKey{ 0 }; - bool _enableTexturing{ true }; - bool _enableBlendshape{ true }; - bool _enableSkinning{ true }; + uint32_t _globalShapeKey { 0 }; + uint32_t _itemShapeKey { 0 }; + bool _enableTexturing { true }; + bool _enableBlendshape { true }; + bool _enableSkinning { true }; - bool _enableFade{ false }; + bool _enableFade { false }; RenderDetails _details; render::ScenePointer _scene; int8_t _cameraMode { -1 }; - std::function _hudOperator; - gpu::TexturePointer _hudTexture; + std::function _hudOperator { nullptr }; + gpu::TexturePointer _hudTexture { nullptr }; bool _takingSnapshot { false }; StencilMaskMode _stencilMaskMode { StencilMaskMode::NONE };