From 781b114d2920868500571d1fc20a0991d25dc9bc Mon Sep 17 00:00:00 2001 From: Adam Rohdin Date: Wed, 31 May 2023 15:45:00 +0200 Subject: [PATCH] Moved bounding sphere calculations for better performance --- .../base/rendering/renderabletrailorbit.cpp | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/modules/base/rendering/renderabletrailorbit.cpp b/modules/base/rendering/renderabletrailorbit.cpp index 722859556d..0c2b552f79 100644 --- a/modules/base/rendering/renderabletrailorbit.cpp +++ b/modules/base/rendering/renderabletrailorbit.cpp @@ -336,24 +336,6 @@ void RenderableTrailOrbit::update(const UpdateData& data) { glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr); glBindVertexArray(0); - - // Updating bounding sphere - glm::vec3 maxVertex(-std::numeric_limits::max()); - glm::vec3 minVertex(std::numeric_limits::max()); - - auto setMax = [&maxVertex, &minVertex](const TrailVBOLayout& vertexData) { - maxVertex.x = std::max(maxVertex.x, vertexData.x); - maxVertex.y = std::max(maxVertex.y, vertexData.y); - maxVertex.z = std::max(maxVertex.z, vertexData.z); - - minVertex.x = std::min(minVertex.x, vertexData.x); - minVertex.y = std::min(minVertex.y, vertexData.y); - minVertex.z = std::min(minVertex.z, vertexData.z); - }; - - std::for_each(_vertexArray.begin(), _vertexArray.end(), setMax); - - setBoundingSphere(glm::distance(maxVertex, minVertex) / 2.f); } RenderableTrailOrbit::UpdateReport RenderableTrailOrbit::updateTrails( @@ -506,6 +488,25 @@ void RenderableTrailOrbit::fullSweep(double time) { _primaryRenderInformation.count = _resolution; _firstPointTime = time + secondsPerPoint; + + // Updating bounding sphere + glm::vec3 maxVertex(-std::numeric_limits::max()); + glm::vec3 minVertex(std::numeric_limits::max()); + + auto setMax = [&maxVertex, &minVertex](const TrailVBOLayout& vertexData) { + maxVertex.x = std::max(maxVertex.x, vertexData.x); + maxVertex.y = std::max(maxVertex.y, vertexData.y); + maxVertex.z = std::max(maxVertex.z, vertexData.z); + + minVertex.x = std::min(minVertex.x, vertexData.x); + minVertex.y = std::min(minVertex.y, vertexData.y); + minVertex.z = std::min(minVertex.z, vertexData.z); + }; + + std::for_each(_vertexArray.begin(), _vertexArray.end(), setMax); + + setBoundingSphere(glm::distance(maxVertex, minVertex) / 2.f); + _needsFullSweep = false; }