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());
|
Log::warn("Material", "Cannot determine texture full path : <%s>", m_texname.c_str());
|
||||||
else
|
else
|
||||||
m_full_path = file_manager->getFileSystem()->getAbsolutePath(relativePath.c_str()).c_str();
|
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();
|
init();
|
||||||
|
|
||||||
bool b = false;
|
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();
|
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;
|
m_complain_if_not_found = complain_if_not_found;
|
||||||
|
|
||||||
if (load_texture)
|
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
|
// now set the name to the basename, so that all tests work as expected
|
||||||
m_texname = StringUtils::getBasename(m_texname);
|
m_texname = StringUtils::getBasename(m_texname);
|
||||||
|
|
||||||
|
core::stringc texfname(m_texname.c_str());
|
||||||
|
texfname.make_lower();
|
||||||
|
m_texname = texfname.c_str();
|
||||||
|
|
||||||
m_texture->grab();
|
m_texture->grab();
|
||||||
} // install
|
} // install
|
||||||
|
|
||||||
|
@ -88,9 +88,7 @@ Material* MaterialManager::getMaterialFor(video::ITexture* t)
|
|||||||
// Search backward so that temporary (track) textures are found first
|
// Search backward so that temporary (track) textures are found first
|
||||||
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
core::stringc fullpath = core::stringc(m_materials[i]->getTexFullPath().c_str());
|
if (m_materials[i]->getTexFullPath() == img_path.c_str())
|
||||||
fullpath.make_lower();
|
|
||||||
if (fullpath == img_path.c_str())
|
|
||||||
{
|
{
|
||||||
return m_materials[i];
|
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--)
|
for (int i = (int)m_materials.size() - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
core::stringc texfname(m_materials[i]->getTexFname().c_str());
|
if (m_materials[i]->getTexFname() == image.c_str())
|
||||||
texfname.make_lower();
|
|
||||||
if (texfname == image)
|
|
||||||
{
|
{
|
||||||
return m_materials[i];
|
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
|
// Search backward so that temporary (track) textures are found first
|
||||||
for (int i = (int)m_materials.size()-1; i>=0; i-- )
|
for (int i = (int)m_materials.size()-1; i>=0; i-- )
|
||||||
{
|
{
|
||||||
core::stringc fname(m_materials[i]->getTexFname().c_str());
|
if (m_materials[i]->getTexFname() == basename_lower.c_str())
|
||||||
fname.make_lower();
|
|
||||||
if (fname == basename_lower)
|
|
||||||
return m_materials[i];
|
return m_materials[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,10 +470,14 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
|
|||||||
|
|
||||||
if (m_is_glsl)
|
if (m_is_glsl)
|
||||||
{
|
{
|
||||||
bool additive = (type->getMaterial()->getShaderType() == Material::SHADERTYPE_ADDITIVE);
|
Material* material = type->getMaterial();
|
||||||
|
if (material != nullptr)
|
||||||
|
{
|
||||||
|
bool additive = (material->getShaderType() == Material::SHADERTYPE_ADDITIVE);
|
||||||
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
|
static_cast<ParticleSystemProxy *>(m_node)->setAlphaAdditive(additive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (m_parent != NULL)
|
if (m_parent != NULL)
|
||||||
{
|
{
|
||||||
|
@ -130,6 +130,10 @@ ParticleKind::ParticleKind(const std::string &file)
|
|||||||
{
|
{
|
||||||
material->get("file", &m_material_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)
|
if (m_material_file.size() == 0)
|
||||||
{
|
{
|
||||||
delete xml;
|
delete xml;
|
||||||
@ -257,7 +261,7 @@ Material* ParticleKind::getMaterial() const
|
|||||||
if (material_manager->hasMaterial(m_material_file))
|
if (material_manager->hasMaterial(m_material_file))
|
||||||
{
|
{
|
||||||
Material* material = material_manager->getMaterial(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);
|
throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user