diff --git a/lib/ivis_opengl/culling.cpp b/lib/ivis_opengl/culling.cpp index 1c75831584e..a2b48d29c2e 100644 --- a/lib/ivis_opengl/culling.cpp +++ b/lib/ivis_opengl/culling.cpp @@ -1,9 +1,7 @@ - - /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2020 Warzone 2100 Project + Copyright (C) 2005-2024 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,7 +26,7 @@ BoundingBox transformBoundingBox(const glm::mat4& worldViewProjectionMatrix, const BoundingBox& worldSpaceBoundingBox) { BoundingBox bboxInClipSpace; - for (int i = 0; i < 8; i++) + for (size_t i = 0, end = bboxInClipSpace.size(); i < end; i++) { glm::vec4 tmp = worldViewProjectionMatrix * glm::vec4(worldSpaceBoundingBox[i], 1.0); tmp = (tmp / tmp.w); diff --git a/lib/ivis_opengl/culling.h b/lib/ivis_opengl/culling.h index bf1c466e57c..e1ce70f895c 100644 --- a/lib/ivis_opengl/culling.h +++ b/lib/ivis_opengl/culling.h @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2020 Warzone 2100 Project + Copyright (C) 2005-2024 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ using BoundingBox = std::array; BoundingBox transformBoundingBox(const glm::mat4& worldViewProjectionMatrix, const BoundingBox& worldSpaceBoundingBox); /// Define a half space -using HalfSpaceCheck = std::function; -/// Define a view frustrum (as an intersection of half space +using HalfSpaceCheck = std::function; +/// Define a view frustum (as an intersection of half space using IntersectionOfHalfSpace = std::array< HalfSpaceCheck, 6>; bool isBBoxInClipSpace(const IntersectionOfHalfSpace& intersectionOfHalfSpace, const BoundingBox& points); diff --git a/lib/ivis_opengl/pielighting.cpp b/lib/ivis_opengl/pielighting.cpp index 39247857eb4..1e374657dc4 100644 --- a/lib/ivis_opengl/pielighting.cpp +++ b/lib/ivis_opengl/pielighting.cpp @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2020 Warzone 2100 Project + Copyright (C) 2005-2024 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,7 +65,6 @@ void LightMap::reset(size_t width, size_t height) mapWidth = static_cast(width); mapHeight = static_cast(height); data = std::make_unique(width * height); - ASSERT(data != nullptr, "Out of memory"); } @@ -109,22 +108,26 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, L { PointLightBuckets result; - // Pick the first lights inside the view frustrum - auto viewFrustrum = IntersectionOfHalfSpace{ - [](glm::vec3 in) { return in.x >= -1.f; }, - [](glm::vec3 in) { return in.x <= 1.f; }, - [](glm::vec3 in) { + // Pick the first lights inside the view frustum + auto viewFrustum = IntersectionOfHalfSpace{ + [](const glm::vec3& in) { return in.x >= -1.f; }, + [](const glm::vec3& in) { return in.x <= 1.f; }, + [](const glm::vec3& in) { if (gfx_api::context::get().isYAxisInverted()) - return -in.y >= -1.f ; - return in.y >= -1.f ; + { + return -in.y >= -1.f; + } + return in.y >= -1.f; }, - [](glm::vec3 in) { + [](const glm::vec3& in) { if (gfx_api::context::get().isYAxisInverted()) + { return -in.y <= 1.f; + } return in.y <= 1.f; }, - [](glm::vec3 in) { return in.z >= 0; }, - [](glm::vec3 in) { return in.z <= 1; } + [](const glm::vec3& in) { return in.z >= 0; }, + [](const glm::vec3& in) { return in.z <= 1; } }; std::vector culledLights; @@ -135,7 +138,7 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, L break; } auto clipSpaceBoundingBox = transformBoundingBox(worldViewProjectionMatrix, getLightBoundingBox(light)); - if (!isBBoxInClipSpace(viewFrustrum, clipSpaceBoundingBox)) + if (!isBBoxInClipSpace(viewFrustum, clipSpaceBoundingBox)) { continue; } @@ -143,7 +146,7 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, L } - for (size_t lightIndex = 0; lightIndex < culledLights.size(); lightIndex++) + for (size_t lightIndex = 0, end = culledLights.size(); lightIndex < end; lightIndex++) { const auto& light = culledLights[lightIndex]; result.positions[lightIndex].x = light.position.x; @@ -159,36 +162,38 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, L size_t overallId = 0; size_t bucketId = 0; std::array lightList; - for (int i = 0; i < gfx_api::bucket_dimension; i++) + for (size_t i = 0; i < gfx_api::bucket_dimension; i++) { - for (int j = 0; j < gfx_api::bucket_dimension; j++) + for (size_t j = 0; j < gfx_api::bucket_dimension; j++) { - auto frustrum = IntersectionOfHalfSpace{ - [i](glm::vec3 in) { return in.x >= -1.f + 2 * static_cast(i) / gfx_api::bucket_dimension; }, - [i](glm::vec3 in) { return in.x <= -1.f + 2 * static_cast(i + 1) / gfx_api::bucket_dimension; }, - [j](glm::vec3 in) { + auto frustum = IntersectionOfHalfSpace{ + [i](const glm::vec3& in) { return in.x >= -1.f + 2 * static_cast(i) / gfx_api::bucket_dimension; }, + [i](const glm::vec3& in) { return in.x <= -1.f + 2 * static_cast(i + 1) / gfx_api::bucket_dimension; }, + [j](const glm::vec3& in) { if (gfx_api::context::get().isYAxisInverted()) return -in.y >= -1.f + 2 * static_cast(j) / gfx_api::bucket_dimension; return in.y >= -1.f + 2 * static_cast(j) / gfx_api::bucket_dimension; }, - [j](glm::vec3 in) { + [j](const glm::vec3& in) { if (gfx_api::context::get().isYAxisInverted()) return -in.y <= -1.f + 2 * static_cast(j + 1) / gfx_api::bucket_dimension; return in.y <= -1.f + 2 * static_cast(j + 1) / gfx_api::bucket_dimension; }, - [](glm::vec3 in) { return in.z >= 0; }, - [](glm::vec3 in) { return in.z <= 1; } + [](const glm::vec3& in) { return in.z >= 0; }, + [](const glm::vec3& in) { return in.z <= 1; } }; size_t bucketSize = 0; for (size_t lightIndex = 0; lightIndex < culledLights.size(); lightIndex++) { if (overallId + bucketSize >= lightList.size()) + { continue; + } const LIGHT& light = culledLights[lightIndex]; BoundingBox clipSpaceBoundingBox = transformBoundingBox(worldViewProjectionMatrix, getLightBoundingBox(light)); - if (isBBoxInClipSpace(frustrum, clipSpaceBoundingBox)) + if (isBBoxInClipSpace(frustum, clipSpaceBoundingBox)) { lightList[overallId + bucketSize] = lightIndex; @@ -208,7 +213,7 @@ void renderingNew::LightingManager::ComputeFrameData(const LightingData& data, L result.light_index[i / 4][i % 4] = static_cast(lightList[i]); } - currentPointLightBuckets = result; + currentPointLightBuckets = std::move(result); } static std::unique_ptr lightingManager; diff --git a/lib/ivis_opengl/pielighting.h b/lib/ivis_opengl/pielighting.h index 094048b98b8..d7047f791f4 100644 --- a/lib/ivis_opengl/pielighting.h +++ b/lib/ivis_opengl/pielighting.h @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2020 Warzone 2100 Project + Copyright (C) 2005-2024 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/src/display3d.cpp b/src/display3d.cpp index 638fd68dc34..28f6716a439 100644 --- a/src/display3d.cpp +++ b/src/display3d.cpp @@ -1004,9 +1004,13 @@ void draw3DScene() // Set light manager { if (war_getPointLightPerPixelLighting() && getTerrainShaderQuality() == TerrainShaderQuality::NORMAL_MAPPING) + { setLightingManager(std::make_unique()); + } else + { setLightingManager(std::make_unique()); + } } /* Now, draw the terrain */