diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index c2a4088dcc..5c6f0ff7ab 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1512,6 +1512,7 @@ void Application::paintGL() { auto lodManager = DependencyManager::get(); + _viewFrustum.calculate(); RenderArgs renderArgs(_gpuContext, getEntities(), getViewFrustum(), lodManager->getOctreeSizeScale(), lodManager->getBoundaryLevelAdjust(), RenderArgs::DEFAULT_RENDER_MODE, RenderArgs::MONO, RenderArgs::RENDER_DEBUG_NONE); @@ -3874,16 +3875,6 @@ glm::vec3 Application::getAvatarPosition() const { return getMyAvatar()->getPosition(); } -ViewFrustum* Application::getViewFrustum() { -#ifdef DEBUG - if (QThread::currentThread() == activeRenderingThread) { - // FIXME, figure out a better way to do this - //qWarning() << "Calling Application::getViewFrustum() from the active rendering thread, did you mean Application::getDisplayViewFrustum()?"; - } -#endif - return &_viewFrustum; -} - const ViewFrustum* Application::getViewFrustum() const { #ifdef DEBUG if (QThread::currentThread() == activeRenderingThread) { diff --git a/interface/src/Application.h b/interface/src/Application.h index 2911d42b65..2dde8f5371 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -128,7 +128,6 @@ public: Camera* getCamera() { return &_myCamera; } const Camera* getCamera() const { return &_myCamera; } // Represents the current view frustum of the avatar. - ViewFrustum* getViewFrustum(); const ViewFrustum* getViewFrustum() const; // Represents the view frustum of the current rendering pass, // which might be different from the viewFrustum, i.e. shadowmap diff --git a/libraries/octree/src/OctreeRenderer.h b/libraries/octree/src/OctreeRenderer.h index 198de7ceed..2058fa982a 100644 --- a/libraries/octree/src/OctreeRenderer.h +++ b/libraries/octree/src/OctreeRenderer.h @@ -51,8 +51,8 @@ public: /// render the content of the octree virtual void render(RenderArgs* renderArgs); - ViewFrustum* getViewFrustum() const { return _viewFrustum; } - void setViewFrustum(ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; } + const ViewFrustum* getViewFrustum() const { return _viewFrustum; } + void setViewFrustum(const ViewFrustum* viewFrustum) { _viewFrustum = viewFrustum; } static bool renderOperation(OctreeElementPointer element, void* extraData); @@ -75,7 +75,7 @@ protected: OctreePointer _tree; bool _managedTree; - ViewFrustum* _viewFrustum; + const ViewFrustum* _viewFrustum; SimpleMovingAverage _elementsPerPacket; SimpleMovingAverage _entitiesPerPacket; diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index 228e4c7d35..202d4ac773 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -630,7 +630,7 @@ void ViewFrustum::getFurthestPointFromCamera(const AACube& box, glm::vec3& furth } } -const ViewFrustum::Corners ViewFrustum::getCorners(const float& depth) { +const ViewFrustum::Corners ViewFrustum::getCorners(const float& depth) const { glm::vec3 normal = glm::normalize(_direction); auto getCorner = [&](enum::BoxVertex nearCorner, enum::BoxVertex farCorner) { diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index 412d0f82f2..531956dd62 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -74,7 +74,7 @@ public: glm::vec3 bottomRight; // Get the corners depth units from frustum position, along frustum orientation }; - const Corners getCorners(const float& depth); + const Corners getCorners(const float& depth) const; // getters for corners const glm::vec3& getFarTopLeft() const { return _cornersWorld[TOP_LEFT_FAR]; } diff --git a/libraries/render-utils/src/LightStage.cpp b/libraries/render-utils/src/LightStage.cpp index 0f1f396471..5e28bea4a6 100644 --- a/libraries/render-utils/src/LightStage.cpp +++ b/libraries/render-utils/src/LightStage.cpp @@ -20,7 +20,7 @@ LightStage::Shadow::Shadow(model::LightPointer light) : _light{ light}, _frustum _schemaBuffer = std::make_shared(sizeof(Schema), (const gpu::Byte*) &schema); } -void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float nearDepth, float farDepth) { +void LightStage::Shadow::setKeylightFrustum(const ViewFrustum* viewFrustum, float nearDepth, float farDepth) { assert(nearDepth < farDepth); // Orient the keylight frustum @@ -43,7 +43,6 @@ void LightStage::Shadow::setKeylightFrustum(ViewFrustum* viewFrustum, float near const Transform view{ _frustum->getView()}; const Transform viewInverse{ view.getInverseMatrix() }; - viewFrustum->calculate(); auto nearCorners = viewFrustum->getCorners(nearDepth); auto farCorners = viewFrustum->getCorners(farDepth); diff --git a/libraries/render-utils/src/LightStage.h b/libraries/render-utils/src/LightStage.h index f776d8d817..14af861e35 100644 --- a/libraries/render-utils/src/LightStage.h +++ b/libraries/render-utils/src/LightStage.h @@ -28,7 +28,7 @@ public: Shadow(model::LightPointer light); - void setKeylightFrustum(ViewFrustum* viewFrustum, float nearDepth, float farDepth); + void setKeylightFrustum(const ViewFrustum* viewFrustum, float nearDepth, float farDepth); const std::shared_ptr getFrustum() const { return _frustum; } diff --git a/libraries/render-utils/src/RenderShadowTask.cpp b/libraries/render-utils/src/RenderShadowTask.cpp index d9e0c06a90..e2e543cc3e 100644 --- a/libraries/render-utils/src/RenderShadowTask.cpp +++ b/libraries/render-utils/src/RenderShadowTask.cpp @@ -146,7 +146,7 @@ void RenderShadowTask::run(const SceneContextPointer& sceneContext, const render } // Cache old render args - ViewFrustum* viewFrustum = args->_viewFrustum; + const ViewFrustum* viewFrustum = args->_viewFrustum; RenderArgs::RenderMode mode = args->_renderMode; auto nearClip = viewFrustum->getNearClip(); diff --git a/libraries/render/src/render/CullTask.cpp b/libraries/render/src/render/CullTask.cpp index 56805e8f83..33096f9b5f 100644 --- a/libraries/render/src/render/CullTask.cpp +++ b/libraries/render/src/render/CullTask.cpp @@ -26,7 +26,7 @@ void render::cullItems(const RenderContextPointer& renderContext, const CullFunc assert(renderContext->args->_viewFrustum); RenderArgs* args = renderContext->args; - ViewFrustum* frustum = args->_viewFrustum; + const ViewFrustum* frustum = args->_viewFrustum; details._considered += (int)inItems.size(); diff --git a/libraries/shared/src/RenderArgs.h b/libraries/shared/src/RenderArgs.h index 341553b743..a08b15886a 100644 --- a/libraries/shared/src/RenderArgs.h +++ b/libraries/shared/src/RenderArgs.h @@ -77,7 +77,7 @@ public: RenderArgs(std::shared_ptr context = nullptr, OctreeRenderer* renderer = nullptr, - ViewFrustum* viewFrustum = nullptr, + const ViewFrustum* viewFrustum = nullptr, float sizeScale = 1.0f, int boundaryLevelAdjust = 0, RenderMode renderMode = DEFAULT_RENDER_MODE, @@ -99,7 +99,7 @@ public: std::shared_ptr _blitFramebuffer = nullptr; std::shared_ptr _pipeline = nullptr; OctreeRenderer* _renderer = nullptr; - ViewFrustum* _viewFrustum = nullptr; + const ViewFrustum* _viewFrustum = nullptr; glm::ivec4 _viewport{ 0.0f, 0.0f, 1.0f, 1.0f }; glm::vec3 _boomOffset{ 0.0f, 0.0f, 1.0f }; float _sizeScale = 1.0f;