Showing the changes to interface/src/Application.cpp (1 of 11 files). Show all
Unified · Split
| @@ -1511,12 +1511,17 @@ void Application::paintGL() { · 1510 unmodified lines | ||
| 1511 | 1511 | |
| 1512 | 1512 | auto lodManager = DependencyManager::get<LODManager>(); |
| 1513 | 1513 | |
| 1514 | − | |
| 1515 | − _viewFrustum.calculate(); | |
| 1514 | + { | |
| 1515 | + QMutexLocker viewLocker(&_viewMutex); | |
| 1516 | + _viewFrustum.calculate(); | |
| 1517 | + } | |
| 1516 | 1518 | RenderArgs renderArgs(_gpuContext, getEntities(), lodManager->getOctreeSizeScale(), |
| 1517 | 1519 | lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE, |
| 1518 | 1520 | RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); |
| 1519 | − renderArgs.setViewFrustum(getViewFrustum()); | |
| 1521 | + { | |
| 1522 | + QMutexLocker viewLocker(&_viewMutex); | |
| 1523 | + renderArgs.setViewFrustum(_viewFrustum); | |
| 1524 | + } | |
| 1520 | 1525 | |
| 1521 | 1526 | PerformanceWarning::setSuppressShortTimings(Menu::getInstance()->isOptionChecked(MenuOption::SuppressShortTimings)); |
| 1522 | 1527 | bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); |
| @@ -1813,7 +1818,10 @@ void Application::resizeGL() { · 290 unmodified lines | ||
| 1813 | 1818 | _myCamera.setProjection(glm::perspective(glm::radians(_fieldOfView.get()), aspectRatio, |
| 1814 | 1819 | DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP)); |
| 1815 | 1820 | // Possible change in aspect ratio |
| 1816 | − loadViewFrustum(_myCamera, _viewFrustum); | |
| 1821 | + { | |
| 1822 | + QMutexLocker viewLocker(&_viewMutex); | |
| 1823 | + loadViewFrustum(_myCamera, _viewFrustum); | |
| 1824 | + } | |
| 1817 | 1825 | |
| 1818 | 1826 | auto offscreenUi = DependencyManager::get<OffscreenUi>(); |
| 1819 | 1827 | auto uiSize = displayPlugin->getRecommendedUiSize(); |
| @@ -2140,6 +2148,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 320 unmodified lines | ||
| 2140 | 2148 | |
| 2141 | 2149 | case Qt::Key_J: |
| 2142 | 2150 | if (isShifted) { |
| 2151 | + QMutexLocker viewLocker(&_viewMutex); | |
| 2143 | 2152 | _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() - 0.1f); |
| 2144 | 2153 | } else { |
| 2145 | 2154 | _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(-0.001, 0, 0)); |
| @@ -2149,6 +2158,7 @@ void Application::keyPressEvent(QKeyEvent* event) { · 3 unmodified lines | ||
| 2149 | 2158 | |
| 2150 | 2159 | case Qt::Key_M: |
| 2151 | 2160 | if (isShifted) { |
| 2161 | + QMutexLocker viewLocker(&_viewMutex); | |
| 2152 | 2162 | _viewFrustum.setFocalLength(_viewFrustum.getFocalLength() + 0.1f); |
| 2153 | 2163 | } else { |
| 2154 | 2164 | _myCamera.setEyeOffsetPosition(_myCamera.getEyeOffsetPosition() + glm::vec3(0.001, 0, 0)); |
| @@ -2997,7 +3007,10 @@ void Application::init() { · 842 unmodified lines | ||
| 2997 | 3007 | DependencyManager::get<NodeList>()->sendDomainServerCheckIn(); |
| 2998 | 3008 | |
| 2999 | 3009 | getEntities()->init(); |
| 3000 | − getEntities()->setViewFrustum(getViewFrustum()); | |
| 3010 | + { | |
| 3011 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3012 | + getEntities()->setViewFrustum(_viewFrustum); | |
| 3013 | + } | |
| 3001 | 3014 | |
| 3002 | 3015 | ObjectMotionState::setShapeManager(&_shapeManager); |
| 3003 | 3016 | _physicsEngine->init(); |
| @@ -3017,7 +3030,10 @@ void Application::init() { · 13 unmodified lines | ||
| 3017 | 3030 | getEntities()->connectSignalsToSlots(entityScriptingInterface.data()); |
| 3018 | 3031 | |
| 3019 | 3032 | _entityClipboardRenderer.init(); |
| 3020 | − _entityClipboardRenderer.setViewFrustum(getViewFrustum()); | |
| 3033 | + { | |
| 3034 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3035 | + _entityClipboardRenderer.setViewFrustum(_viewFrustum); | |
| 3036 | + } | |
| 3021 | 3037 | _entityClipboardRenderer.setTree(_entityClipboard); |
| 3022 | 3038 | |
| 3023 | 3039 | // Make sure any new sounds are loaded as soon as know about them. |
| @@ -3220,9 +3236,12 @@ void Application::resetPhysicsReadyInformation() { · 196 unmodified lines | ||
| 3220 | 3236 | |
| 3221 | 3237 | void Application::reloadResourceCaches() { |
| 3222 | 3238 | resetPhysicsReadyInformation(); |
| 3239 | + { | |
| 3240 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3241 | + _viewFrustum.setPosition(glm::vec3(0.0f, 0.0f, TREE_SCALE)); | |
| 3242 | + _viewFrustum.setOrientation(glm::quat()); | |
| 3243 | + } | |
| 3223 | 3244 | // Clear entities out of view frustum |
| 3224 | − _viewFrustum.setPosition(glm::vec3(0.0f, 0.0f, TREE_SCALE)); | |
| 3225 | − _viewFrustum.setOrientation(glm::quat()); | |
| 3226 | 3245 | queryOctree(NodeType::EntityServer, PacketType::EntityQuery, _entityServerJurisdictions); |
| 3227 | 3246 | |
| 3228 | 3247 | DependencyManager::get<AssetClient>()->clearCache(); |
| @@ -3511,7 +3530,7 @@ void Application::update(float deltaTime) { · 282 unmodified lines | ||
| 3511 | 3530 | // actually need to calculate the view frustum planes to send these details |
| 3512 | 3531 | // to the server. |
| 3513 | 3532 | { |
| 3514 | − PerformanceTimer perfTimer("loadViewFrustum"); | |
| 3533 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3515 | 3534 | loadViewFrustum(_myCamera, _viewFrustum); |
| 3516 | 3535 | } |
| 3517 | 3536 | |
| @@ -3520,6 +3539,7 @@ void Application::update(float deltaTime) { · 2 unmodified lines | ||
| 3520 | 3539 | // Update my voxel servers with my current voxel query... |
| 3521 | 3540 | { |
| 3522 | 3541 | PROFILE_RANGE_EX("QueryOctree", 0xffff0000, (uint64_t)getActiveDisplayPlugin()->presentCount()); |
| 3542 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3523 | 3543 | PerformanceTimer perfTimer("queryOctree"); |
| 3524 | 3544 | quint64 sinceLastQuery = now - _lastQueriedTime; |
| 3525 | 3545 | const quint64 TOO_LONG_SINCE_LAST_QUERY = 3 * USECS_PER_SECOND; |
| @@ -3631,14 +3651,19 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 105 unmodified lines | ||
| 3631 | 3651 | //qCDebug(interfaceapp) << ">>> inside... queryOctree()... _viewFrustum.getFieldOfView()=" << _viewFrustum.getFieldOfView(); |
| 3632 | 3652 | bool wantExtraDebugging = getLogger()->extraDebugging(); |
| 3633 | 3653 | |
| 3634 | − _octreeQuery.setCameraPosition(_viewFrustum.getPosition()); | |
| 3635 | − _octreeQuery.setCameraOrientation(_viewFrustum.getOrientation()); | |
| 3636 | − _octreeQuery.setCameraFov(_viewFrustum.getFieldOfView()); | |
| 3637 | − _octreeQuery.setCameraAspectRatio(_viewFrustum.getAspectRatio()); | |
| 3638 | − _octreeQuery.setCameraNearClip(_viewFrustum.getNearClip()); | |
| 3639 | − _octreeQuery.setCameraFarClip(_viewFrustum.getFarClip()); | |
| 3654 | + ViewFrustum viewFrustumCopy; | |
| 3655 | + { | |
| 3656 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3657 | + viewFrustumCopy = _viewFrustum; | |
| 3658 | + } | |
| 3659 | + _octreeQuery.setCameraPosition(viewFrustumCopy.getPosition()); | |
| 3660 | + _octreeQuery.setCameraOrientation(viewFrustumCopy.getOrientation()); | |
| 3661 | + _octreeQuery.setCameraFov(viewFrustumCopy.getFieldOfView()); | |
| 3662 | + _octreeQuery.setCameraAspectRatio(viewFrustumCopy.getAspectRatio()); | |
| 3663 | + _octreeQuery.setCameraNearClip(viewFrustumCopy.getNearClip()); | |
| 3664 | + _octreeQuery.setCameraFarClip(viewFrustumCopy.getFarClip()); | |
| 3640 | 3665 | _octreeQuery.setCameraEyeOffsetPosition(glm::vec3()); |
| 3641 | − _octreeQuery.setCameraCenterRadius(_viewFrustum.getCenterRadius()); | |
| 3666 | + _octreeQuery.setCameraCenterRadius(viewFrustumCopy.getCenterRadius()); | |
| 3642 | 3667 | auto lodManager = DependencyManager::get<LODManager>(); |
| 3643 | 3668 | _octreeQuery.setOctreeSizeScale(lodManager->getOctreeSizeScale()); |
| 3644 | 3669 | _octreeQuery.setBoundaryLevelAdjust(lodManager->getBoundaryLevelAdjust()); |
| @@ -3674,7 +3699,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 29 unmodified lines | ||
| 3674 | 3699 | rootDetails.y * TREE_SCALE, |
| 3675 | 3700 | rootDetails.z * TREE_SCALE) - glm::vec3(HALF_TREE_SCALE), |
| 3676 | 3701 | rootDetails.s * TREE_SCALE); |
| 3677 | − if (_viewFrustum.cubeIntersectsKeyhole(serverBounds)) { | |
| 3702 | + if (viewFrustumCopy.cubeIntersectsKeyhole(serverBounds)) { | |
| 3678 | 3703 | inViewServers++; |
| 3679 | 3704 | } |
| 3680 | 3705 | } |
| @@ -3740,7 +3765,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node · 59 unmodified lines | ||
| 3740 | 3765 | rootDetails.s * TREE_SCALE); |
| 3741 | 3766 | |
| 3742 | 3767 | |
| 3743 | − inView = _viewFrustum.cubeIntersectsKeyhole(serverBounds); | |
| 3768 | + inView = viewFrustumCopy.cubeIntersectsKeyhole(serverBounds); | |
| 3744 | 3769 | } else { |
| 3745 | 3770 | if (wantExtraDebugging) { |
| 3746 | 3771 | qCDebug(interfaceapp) << "Jurisdiction without RootCode for node " << *node << ". That's unusual!"; |
| @@ -3835,6 +3860,7 @@ QRect Application::getDesirableApplicationGeometry() const { · 88 unmodified lines | ||
| 3835 | 3860 | // or the "myCamera". |
| 3836 | 3861 | // |
| 3837 | 3862 | void Application::loadViewFrustum(Camera& camera, ViewFrustum& viewFrustum) { |
| 3863 | + PerformanceTimer perfTimer("loadViewFrustum"); | |
| 3838 | 3864 | PROFILE_RANGE(__FUNCTION__); |
| 3839 | 3865 | // We will use these below, from either the camera or head vectors calculated above |
| 3840 | 3866 | viewFrustum.setProjection(camera.getProjection()); |
| @@ -3863,7 +3889,8 @@ PickRay Application::computePickRay(float x, float y) const { · 22 unmodified lines | ||
| 3863 | 3889 | getApplicationCompositor().computeHmdPickRay(pickPoint, result.origin, result.direction); |
| 3864 | 3890 | } else { |
| 3865 | 3891 | pickPoint /= getCanvasSize(); |
| 3866 | − getViewFrustum().computePickRay(pickPoint.x, pickPoint.y, result.origin, result.direction); | |
| 3892 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3893 | + _viewFrustum.computePickRay(pickPoint.x, pickPoint.y, result.origin, result.direction); | |
| 3867 | 3894 | } |
| 3868 | 3895 | return result; |
| 3869 | 3896 | } |
| @@ -3876,24 +3903,19 @@ glm::vec3 Application::getAvatarPosition() const { · 6 unmodified lines | ||
| 3876 | 3903 | return getMyAvatar()->getPosition(); |
| 3877 | 3904 | } |
| 3878 | 3905 | |
| 3879 | −const ViewFrustum& Application::getViewFrustum() const { | |
| 3880 | −#ifdef DEBUG | |
| 3881 | − if (QThread::currentThread() == activeRenderingThread) { | |
| 3882 | − // FIXME, figure out a better way to do this | |
| 3883 | − //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; | |
| 3884 | − } | |
| 3885 | −#endif | |
| 3886 | − return _viewFrustum; | |
| 3906 | +void Application::copyViewFrustum(ViewFrustum& viewOut) const { | |
| 3907 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3908 | + viewOut = _viewFrustum; | |
| 3887 | 3909 | } |
| 3888 | 3910 | |
| 3889 | −const ViewFrustum& Application::getDisplayViewFrustum() const { | |
| 3890 | −#ifdef DEBUG | |
| 3891 | − if (QThread::currentThread() != activeRenderingThread) { | |
| 3892 | − // FIXME, figure out a better way to do this | |
| 3893 | − // qWarning() << "Calling Application::getDisplayViewFrustum() from outside the active rendering thread or outside rendering, did you mean Application::getViewFrustum()?"; | |
| 3894 | − } | |
| 3895 | −#endif | |
| 3896 | − return _displayViewFrustum; | |
| 3911 | +void Application::copyDisplayViewFrustum(ViewFrustum& viewOut) const { | |
| 3912 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3913 | + viewOut = _displayViewFrustum; | |
| 3914 | +} | |
| 3915 | + | |
| 3916 | +void Application::copyShadowViewFrustum(ViewFrustum& viewOut) const { | |
| 3917 | + QMutexLocker viewLocker(&_viewMutex); | |
| 3918 | + viewOut = _shadowViewFrustum; | |
| 3897 | 3919 | } |
| 3898 | 3920 | |
| 3899 | 3921 | // WorldBox Render Data & rendering functions |
| @@ -4002,7 +4024,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 102 unmodified lines | ||
| 4002 | 4024 | PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), "Application::displaySide()"); |
| 4003 | 4025 | |
| 4004 | 4026 | // load the view frustum |
| 4005 | − loadViewFrustum(theCamera, _displayViewFrustum); | |
| 4027 | + { | |
| 4028 | + QMutexLocker viewLocker(&_viewMutex); | |
| 4029 | + loadViewFrustum(theCamera, _displayViewFrustum); | |
| 4030 | + } | |
| 4006 | 4031 | |
| 4007 | 4032 | // TODO fix shadows and make them use the GPU library |
| 4008 | 4033 | |
| @@ -4070,7 +4095,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se · 61 unmodified lines | ||
| 4070 | 4095 | { |
| 4071 | 4096 | PerformanceTimer perfTimer("EngineRun"); |
| 4072 | 4097 | |
| 4073 | − renderArgs->setViewFrustum(getDisplayViewFrustum()); | |
| 4098 | + { | |
| 4099 | + QMutexLocker viewLocker(&_viewMutex); | |
| 4100 | + renderArgs->setViewFrustum(_displayViewFrustum); | |
| 4101 | + } | |
| 4074 | 4102 | _renderEngine->getRenderContext()->args = renderArgs; |
| 4075 | 4103 | |
| 4076 | 4104 | // Before the deferred pass, let's try to use the render engine |
| @@ -4496,6 +4524,11 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri · 419 unmodified lines | ||
| 4496 | 4524 | scriptEngine->registerGlobalObject("Reticle", getApplicationCompositor().getReticleInterface()); |
| 4497 | 4525 | } |
| 4498 | 4526 | |
| 4527 | +void Application::copyCurrentViewFrustum(ViewFrustum& viewOut) const { | |
| 4528 | + QMutexLocker viewLocker(&_viewMutex); | |
| 4529 | + viewOut = _displayViewFrustum; | |
| 4530 | +} | |
| 4531 | + | |
| 4499 | 4532 | bool Application::canAcceptURL(const QString& urlString) const { |
| 4500 | 4533 | QUrl url(urlString); |
| 4501 | 4534 | if (urlString.startsWith(HIFI_URL_SCHEME)) { |
| @@ -5200,10 +5233,10 @@ void Application::updateInputModes() { · 698 unmodified lines | ||
| 5200 | 5233 | } |
| 5201 | 5234 | |
| 5202 | 5235 | mat4 Application::getEyeProjection(int eye) const { |
| 5236 | + QMutexLocker viewLocker(&_viewMutex); | |
| 5203 | 5237 | if (isHMDMode()) { |
| 5204 | 5238 | return getActiveDisplayPlugin()->getEyeProjection((Eye)eye, _viewFrustum.getProjection()); |
| 5205 | 5239 | } |
| 5206 | − | |
| 5207 | 5240 | return _viewFrustum.getProjection(); |
| 5208 | 5241 | } |
| 5209 | 5242 | |