mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-13 21:40:11 +00:00
Replace unordered_map by switch statement
Add handling for missing Nif::BSLightingShaderType::ShaderType_SkinTint. Use string_view instead of string to avoid lifetime issues for returning value. osg::Object::setUserValue will anyway copy string.
This commit is contained in:
parent
e1fe501013
commit
2a87cf1720
@ -1,6 +1,7 @@
|
|||||||
#include "nifloader.hpp"
|
#include "nifloader.hpp"
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
#include <osg/Matrixf>
|
#include <osg/Matrixf>
|
||||||
#include <osg/Geometry>
|
#include <osg/Geometry>
|
||||||
@ -1743,64 +1744,55 @@ namespace NifOsg
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getBSShaderPrefix(unsigned int type) const
|
std::string_view getBSShaderPrefix(unsigned int type) const
|
||||||
{
|
{
|
||||||
static const std::unordered_map<Nif::BSShaderType, std::string> mapping =
|
switch (static_cast<Nif::BSShaderType>(type))
|
||||||
{
|
{
|
||||||
{Nif::BSShaderType::ShaderType_TallGrass, std::string()},
|
case Nif::BSShaderType::ShaderType_Default: return "nv_default";
|
||||||
{Nif::BSShaderType::ShaderType_Default, "nv_default"},
|
case Nif::BSShaderType::ShaderType_NoLighting: return "nv_nolighting";
|
||||||
{Nif::BSShaderType::ShaderType_Sky, std::string()},
|
case Nif::BSShaderType::ShaderType_TallGrass:
|
||||||
{Nif::BSShaderType::ShaderType_Skin, std::string()},
|
case Nif::BSShaderType::ShaderType_Sky:
|
||||||
{Nif::BSShaderType::ShaderType_Water, std::string()},
|
case Nif::BSShaderType::ShaderType_Skin:
|
||||||
{Nif::BSShaderType::ShaderType_Lighting30, std::string()},
|
case Nif::BSShaderType::ShaderType_Water:
|
||||||
{Nif::BSShaderType::ShaderType_Tile, std::string()},
|
case Nif::BSShaderType::ShaderType_Lighting30:
|
||||||
{Nif::BSShaderType::ShaderType_NoLighting, "nv_nolighting"},
|
case Nif::BSShaderType::ShaderType_Tile:
|
||||||
};
|
Log(Debug::Warning) << "Unhandled BSShaderType " << type << " in " << mFilename;
|
||||||
auto prefix = mapping.find(static_cast<Nif::BSShaderType>(type));
|
return std::string_view();
|
||||||
if (prefix == mapping.end())
|
}
|
||||||
Log(Debug::Warning) << "Unknown BSShaderType " << type << " in " << mFilename;
|
Log(Debug::Warning) << "Unknown BSShaderType " << type << " in " << mFilename;
|
||||||
else if (prefix->second.empty())
|
return std::string_view();
|
||||||
Log(Debug::Warning) << "Unhandled BSShaderType " << type << " in " << mFilename;
|
|
||||||
else
|
|
||||||
return prefix->second;
|
|
||||||
|
|
||||||
return mapping.at(Nif::BSShaderType::ShaderType_Default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& getBSLightingShaderPrefix(unsigned int type) const
|
std::string_view getBSLightingShaderPrefix(unsigned int type) const
|
||||||
{
|
{
|
||||||
static const std::unordered_map<Nif::BSLightingShaderType, std::string> mapping =
|
switch (static_cast<Nif::BSLightingShaderType>(type))
|
||||||
{
|
{
|
||||||
{Nif::BSLightingShaderType::ShaderType_Default, "nv_default"},
|
case Nif::BSLightingShaderType::ShaderType_Default: return "nv_default";
|
||||||
{Nif::BSLightingShaderType::ShaderType_EnvMap, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_EnvMap:
|
||||||
{Nif::BSLightingShaderType::ShaderType_Glow, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_Glow:
|
||||||
{Nif::BSLightingShaderType::ShaderType_Parallax, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_Parallax:
|
||||||
{Nif::BSLightingShaderType::ShaderType_FaceTint, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_FaceTint:
|
||||||
{Nif::BSLightingShaderType::ShaderType_HairTint, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_SkinTint:
|
||||||
{Nif::BSLightingShaderType::ShaderType_ParallaxOcc, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_HairTint:
|
||||||
{Nif::BSLightingShaderType::ShaderType_MultitexLand, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_ParallaxOcc:
|
||||||
{Nif::BSLightingShaderType::ShaderType_LODLand, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_MultitexLand:
|
||||||
{Nif::BSLightingShaderType::ShaderType_Snow, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_LODLand:
|
||||||
{Nif::BSLightingShaderType::ShaderType_MultiLayerParallax, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_Snow:
|
||||||
{Nif::BSLightingShaderType::ShaderType_TreeAnim, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_MultiLayerParallax:
|
||||||
{Nif::BSLightingShaderType::ShaderType_LODObjects, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_TreeAnim:
|
||||||
{Nif::BSLightingShaderType::ShaderType_SparkleSnow, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_LODObjects:
|
||||||
{Nif::BSLightingShaderType::ShaderType_LODObjectsHD, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_SparkleSnow:
|
||||||
{Nif::BSLightingShaderType::ShaderType_EyeEnvmap, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_LODObjectsHD:
|
||||||
{Nif::BSLightingShaderType::ShaderType_Cloud, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_EyeEnvmap:
|
||||||
{Nif::BSLightingShaderType::ShaderType_LODNoise, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_Cloud:
|
||||||
{Nif::BSLightingShaderType::ShaderType_MultitexLandLODBlend, std::string()},
|
case Nif::BSLightingShaderType::ShaderType_LODNoise:
|
||||||
{Nif::BSLightingShaderType::ShaderType_Dismemberment, std::string()}
|
case Nif::BSLightingShaderType::ShaderType_MultitexLandLODBlend:
|
||||||
};
|
case Nif::BSLightingShaderType::ShaderType_Dismemberment:
|
||||||
auto prefix = mapping.find(static_cast<Nif::BSLightingShaderType>(type));
|
Log(Debug::Warning) << "Unhandled BSLightingShaderType " << type << " in " << mFilename;
|
||||||
if (prefix == mapping.end())
|
return std::string_view();
|
||||||
Log(Debug::Warning) << "Unknown BSLightingShaderType " << type << " in " << mFilename;
|
}
|
||||||
else if (prefix->second.empty())
|
Log(Debug::Warning) << "Unknown BSLightingShaderType " << type << " in " << mFilename;
|
||||||
Log(Debug::Warning) << "Unhandled BSLightingShaderType " << type << " in " << mFilename;
|
return std::string_view();
|
||||||
else
|
|
||||||
return prefix->second;
|
|
||||||
|
|
||||||
return mapping.at(Nif::BSLightingShaderType::ShaderType_Default);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleProperty(const Nif::Property *property,
|
void handleProperty(const Nif::Property *property,
|
||||||
@ -1895,7 +1887,7 @@ namespace NifOsg
|
|||||||
{
|
{
|
||||||
auto texprop = static_cast<const Nif::BSShaderPPLightingProperty*>(property);
|
auto texprop = static_cast<const Nif::BSShaderPPLightingProperty*>(property);
|
||||||
bool shaderRequired = true;
|
bool shaderRequired = true;
|
||||||
node->setUserValue("shaderPrefix", getBSShaderPrefix(texprop->type));
|
node->setUserValue("shaderPrefix", std::string(getBSShaderPrefix(texprop->type)));
|
||||||
node->setUserValue("shaderRequired", shaderRequired);
|
node->setUserValue("shaderRequired", shaderRequired);
|
||||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
osg::StateSet* stateset = node->getOrCreateStateSet();
|
||||||
if (!texprop->textureSet.empty())
|
if (!texprop->textureSet.empty())
|
||||||
@ -1910,7 +1902,7 @@ namespace NifOsg
|
|||||||
{
|
{
|
||||||
auto texprop = static_cast<const Nif::BSShaderNoLightingProperty*>(property);
|
auto texprop = static_cast<const Nif::BSShaderNoLightingProperty*>(property);
|
||||||
bool shaderRequired = true;
|
bool shaderRequired = true;
|
||||||
node->setUserValue("shaderPrefix", getBSShaderPrefix(texprop->type));
|
node->setUserValue("shaderPrefix", std::string(getBSShaderPrefix(texprop->type)));
|
||||||
node->setUserValue("shaderRequired", shaderRequired);
|
node->setUserValue("shaderRequired", shaderRequired);
|
||||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
osg::StateSet* stateset = node->getOrCreateStateSet();
|
||||||
if (!texprop->filename.empty())
|
if (!texprop->filename.empty())
|
||||||
@ -1952,7 +1944,7 @@ namespace NifOsg
|
|||||||
{
|
{
|
||||||
auto texprop = static_cast<const Nif::BSLightingShaderProperty*>(property);
|
auto texprop = static_cast<const Nif::BSLightingShaderProperty*>(property);
|
||||||
bool shaderRequired = true;
|
bool shaderRequired = true;
|
||||||
node->setUserValue("shaderPrefix", getBSLightingShaderPrefix(texprop->type));
|
node->setUserValue("shaderPrefix", std::string(getBSLightingShaderPrefix(texprop->type)));
|
||||||
node->setUserValue("shaderRequired", shaderRequired);
|
node->setUserValue("shaderRequired", shaderRequired);
|
||||||
osg::StateSet* stateset = node->getOrCreateStateSet();
|
osg::StateSet* stateset = node->getOrCreateStateSet();
|
||||||
if (!texprop->mTextureSet.empty())
|
if (!texprop->mTextureSet.empty())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user