1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-03 18:15:35 +00:00

Merge branch 'lightmanager_format' into 'master'

Format LightManager code

See merge request OpenMW/openmw!2111
This commit is contained in:
jvoisin 2022-07-08 20:50:23 +00:00
commit 39916524d7
2 changed files with 20 additions and 18 deletions

View file

@ -24,6 +24,10 @@
namespace namespace
{ {
constexpr int maxLightsLowerLimit = 2;
constexpr int maxLightsUpperLimit = 64;
constexpr int ffpMaxLights = 8;
bool sortLights(const SceneUtil::LightManager::LightSourceViewBound* left, const SceneUtil::LightManager::LightSourceViewBound* right) bool sortLights(const SceneUtil::LightManager::LightSourceViewBound* left, const SceneUtil::LightManager::LightSourceViewBound* right)
{ {
static auto constexpr illuminationBias = 81.f; static auto constexpr illuminationBias = 81.f;
@ -70,6 +74,15 @@ namespace
namespace SceneUtil namespace SceneUtil
{ {
namespace
{
const std::unordered_map<std::string, LightingMethod> lightingMethodSettingMap = {
{"legacy", LightingMethod::FFP},
{"shaders compatibility", LightingMethod::PerObjectUniform},
{"shaders", LightingMethod::SingleUBO},
};
}
static int sLightId = 0; static int sLightId = 0;
// Handles a GLSL shared layout by using configured offsets and strides to fill a continuous buffer, making the data upload to GPU simpler. // Handles a GLSL shared layout by using configured offsets and strides to fill a continuous buffer, making the data upload to GPU simpler.
@ -756,16 +769,10 @@ namespace SceneUtil
mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride); mTemplate->configureLayout(offsets[0], offsets[1], offsets[2], totalBlockSize, stride);
} }
const std::unordered_map<std::string, LightingMethod> LightManager::mLightingMethodSettingMap = {
{"legacy", LightingMethod::FFP}
,{"shaders compatibility", LightingMethod::PerObjectUniform}
,{"shaders", LightingMethod::SingleUBO}
};
LightingMethod LightManager::getLightingMethodFromString(const std::string& value) LightingMethod LightManager::getLightingMethodFromString(const std::string& value)
{ {
auto it = LightManager::mLightingMethodSettingMap.find(value); auto it = lightingMethodSettingMap.find(value);
if (it != LightManager::mLightingMethodSettingMap.end()) if (it != lightingMethodSettingMap.end())
return it->second; return it->second;
constexpr const char* fallback = "shaders compatibility"; constexpr const char* fallback = "shaders compatibility";
@ -775,7 +782,7 @@ namespace SceneUtil
std::string LightManager::getLightingMethodString(LightingMethod method) std::string LightManager::getLightingMethodString(LightingMethod method)
{ {
for (const auto& p : LightManager::mLightingMethodSettingMap) for (const auto& p : lightingMethodSettingMap)
if (p.second == method) if (p.second == method)
return p.first; return p.first;
return ""; return "";
@ -801,7 +808,7 @@ namespace SceneUtil
if (ffp) if (ffp)
{ {
initFFP(mFFPMaxLights); initFFP(ffpMaxLights);
return; return;
} }
@ -819,7 +826,8 @@ namespace SceneUtil
hasLoggedWarnings = true; hasLoggedWarnings = true;
} }
int targetLights = std::clamp(Settings::Manager::getInt("max lights", "Shaders"), mMaxLightsLowerLimit, mMaxLightsUpperLimit); const int targetLights = std::clamp(Settings::Manager::getInt("max lights", "Shaders"),
maxLightsLowerLimit, maxLightsUpperLimit);
if (!supportsUBO || !supportsGPU4 || lightingMethod == LightingMethod::PerObjectUniform) if (!supportsUBO || !supportsGPU4 || lightingMethod == LightingMethod::PerObjectUniform)
initPerObjectUniform(targetLights); initPerObjectUniform(targetLights);
@ -902,7 +910,7 @@ namespace SceneUtil
if (usingFFP()) if (usingFFP())
return; return;
setMaxLights(std::clamp(Settings::Manager::getInt("max lights", "Shaders"), mMaxLightsLowerLimit, mMaxLightsUpperLimit)); setMaxLights(std::clamp(Settings::Manager::getInt("max lights", "Shaders"), maxLightsLowerLimit, maxLightsUpperLimit));
if (getLightingMethod() == LightingMethod::PerObjectUniform) if (getLightingMethod() == LightingMethod::PerObjectUniform)
{ {

View file

@ -360,12 +360,6 @@ namespace SceneUtil
SupportedMethods mSupported; SupportedMethods mSupported;
static constexpr auto mMaxLightsLowerLimit = 2;
static constexpr auto mMaxLightsUpperLimit = 64;
static constexpr auto mFFPMaxLights = 8;
static const std::unordered_map<std::string, LightingMethod> mLightingMethodSettingMap;
std::shared_ptr<PPLightBuffer> mPPLightBuffer; std::shared_ptr<PPLightBuffer> mPPLightBuffer;
}; };