Make all material names and path lowercase upon loading them, moving several string allocations and modifications outside of hot loops
This commit is contained in:
parent
adfa8f30f9
commit
571832fbbc
@ -73,6 +73,18 @@ Material::Material(const XMLNode *node, bool deprecated)
|
||||
Log::warn("Material", "Cannot determine texture full path : <%s>", m_texname.c_str());
|
||||
else
|
||||
m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str();
|
||||
|
||||
core::stringc texfname(m_texname.c_str());
|
||||
texfname.make_lower();
|
||||
m_texname = texfname.c_str();
|
||||
|
||||
if (m_full_path.size() > 0)
|
||||
{
|
||||
core::stringc texfname2(m_full_path.c_str());
|
||||
texfname2.make_lower();
|
||||
m_full_path = texfname2.c_str();
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
bool b = false;
|
||||
@ -432,6 +444,14 @@ Material::Material(const std::string& fname, bool is_full_path,
|
||||
file_manager->searchTexture(m_texname).c_str()).c_str();
|
||||
}
|
||||
|
||||
core::stringc texfname(m_texname.c_str());
|
||||
texfname.make_lower();
|
||||
m_texname = texfname.c_str();
|
||||
|
||||
core::stringc texfname2(m_full_path.c_str());
|
||||
texfname2.make_lower();
|
||||
m_full_path = texfname2.c_str();
|
||||
|
||||
m_complain_if_not_found = complain_if_not_found;
|
||||
|
||||
if (load_texture)
|
||||
@ -516,6 +536,10 @@ void Material::install(bool srgb, bool premul_alpha)
|
||||
// now set the name to the basename, so that all tests work as expected
|
||||
m_texname = StringUtils::getBasename(m_texname);
|
||||
|
||||
core::stringc texfname(m_texname.c_str());
|
||||
texfname.make_lower();
|
||||
m_texname = texfname.c_str();
|
||||
|
||||
m_texture->grab();
|
||||
} // install
|
||||
|
||||
|
@ -81,16 +81,14 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t,
|
||||
Material* MaterialManager::getMaterialFor(video::ITexture* t)
|
||||
{
|
||||
core::stringc img_path = core::stringc(t->getName());
|
||||
img_path.make_lower();
|
||||
img_path.make_lower();
|
||||
|
||||
if (!img_path.empty() && (img_path.findFirst('/') != -1 || img_path.findFirst('\\') != -1))
|
||||
{
|
||||
// Search backward so that temporary (track) textures are found first
|
||||
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||
{
|
||||
core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str());
|
||||
fullpath.make_lower();
|
||||
if (fullpath == img_path.c_str())
|
||||
if (m_materials[i]->getTexFullPath() == img_path.c_str())
|
||||
{
|
||||
return m_materials[i];
|
||||
}
|
||||
@ -103,9 +101,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t)
|
||||
|
||||
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||
{
|
||||
core::stringc texfname(m_materials[i]->getTexFname().c_str());
|
||||
texfname.make_lower();
|
||||
if (texfname == image)
|
||||
if (m_materials[i]->getTexFname() == image.c_str())
|
||||
{
|
||||
return m_materials[i];
|
||||
}
|
||||
@ -361,9 +357,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
|
||||
// Search backward so that temporary (track) textures are found first
|
||||
for (int i = (int)m_materials.size()-1; i>=0; i-- )
|
||||
{
|
||||
core::stringc fname(m_materials[i]->getTexFname().c_str());
|
||||
fname.make_lower();
|
||||
if (fname == basename_lower)
|
||||
if (m_materials[i]->getTexFname() == basename_lower.c_str())
|
||||
return m_materials[i];
|
||||
}
|
||||
|
||||
|
@ -470,8 +470,12 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
||||
|
||||
if (m_is_glsl)
|
||||
{
|
||||
bool additive = (type->getMaterial()->getShaderType() == Material::SHADERTYPE_ADDITIVE);
|
||||
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
|
||||
Material* material = type->getMaterial();
|
||||
if (material != nullptr)
|
||||
{
|
||||
bool additive = (material->getShaderType() == Material::SHADERTYPE_ADDITIVE);
|
||||
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,6 +130,10 @@ ParticleKind::ParticleKind(const std::string &file)
|
||||
{
|
||||
material->get("file", &m_material_file);
|
||||
|
||||
core::stringc tmp(m_material_file.c_str());
|
||||
tmp.make_lower();
|
||||
m_material_file = tmp.c_str();
|
||||
|
||||
if (m_material_file.size() == 0)
|
||||
{
|
||||
delete xml;
|
||||
@ -257,7 +261,7 @@ Material* ParticleKind::getMaterial() const
|
||||
if (material_manager->hasMaterial(m_material_file))
|
||||
{
|
||||
Material* material = material_manager->getMaterial(m_material_file);
|
||||
if (material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL)
|
||||
if (material == NULL || material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL)
|
||||
{
|
||||
throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user