Simplify particle texture loading

This commit is contained in:
Benau 2017-01-04 13:43:14 +08:00
parent 63f57d6a9c
commit c98e4f2bac
7 changed files with 22 additions and 29 deletions

View File

@ -62,7 +62,6 @@ Material::Material(const XMLNode *node, bool deprecated)
m_shader_type = SHADERTYPE_SOLID;
m_deprecated = deprecated;
m_installed = false;
m_srgb_texture = true;
node->get("name", &m_texname);
if (m_texname=="")
@ -402,11 +401,11 @@ Material::Material(const XMLNode *node, bool deprecated)
m_high_tire_adhesion = true;
} // Material
//-----------------------------------------------------------------------------
video::ITexture* Material::getTexture()
video::ITexture* Material::getTexture(bool srgb, bool premul_alpha)
{
if (!m_installed)
{
install();
install(srgb, premul_alpha);
}
return m_texture;
} // getTexture
@ -417,12 +416,10 @@ video::ITexture* Material::getTexture()
* \param is_full_path If the fname contains the full path.
*/
Material::Material(const std::string& fname, bool is_full_path,
bool complain_if_not_found, bool load_texture,
bool srgb)
bool complain_if_not_found, bool load_texture)
{
m_deprecated = false;
m_installed = false;
m_srgb_texture = srgb;
init();
if (is_full_path)
@ -493,30 +490,30 @@ void Material::init()
} // init
//-----------------------------------------------------------------------------
void Material::install()
void Material::install(bool srgb, bool premul_alpha)
{
// Don't load a texture that are not supposed to be loaded automatically
if (m_installed) return;
m_installed = true;
if (m_complain_if_not_found && m_full_path.size() == 0)
if (StringUtils::getPath(m_full_path).empty())
{
Log::error("material", "Cannot find texture '%s'.", m_texname.c_str());
if (m_complain_if_not_found)
{
Log::error("material", "Cannot find texture '%s'.",
m_texname.c_str());
}
m_texture = NULL;
}
else
{
#ifndef SERVER_ONLY
if (CVS->isGLSL())
{
m_texture = STKTexManager::getInstance()->getTexture
(m_full_path, m_srgb_texture,
m_shader_type == SHADERTYPE_ALPHA_BLEND ||
m_shader_type == SHADERTYPE_ADDITIVE ?
true : false/*premul_alpha*/,
false/*set_material*/, m_srgb_texture/*mesh_tex*/);
(m_full_path, srgb, premul_alpha, false/*set_material*/,
srgb/*mesh_tex*/);
}
else
#endif

View File

@ -266,11 +266,8 @@ private:
bool m_installed;
/** If Layer 1 texture is srgb. */
bool m_srgb_texture;
void init ();
void install ();
void install (bool srgb = false, bool premul_alpha = false);
void initCustomSFX(const XMLNode *sfx);
void initParticlesEffect(const XMLNode *node);
@ -279,8 +276,7 @@ public:
Material(const std::string& fname,
bool is_full_path=false,
bool complain_if_not_found=true,
bool load_texture = true,
bool srgb = false);
bool load_texture = true);
~Material ();
void unloadTexture();
@ -294,7 +290,7 @@ public:
void isInitiallyHidden(scene::IMeshBuffer* who);
/** Returns the ITexture associated with this material. */
video::ITexture *getTexture();
video::ITexture *getTexture(bool srgb = true, bool premul_alpha = false);
// ------------------------------------------------------------------------
bool isIgnore () const { return m_ignore; }
// ------------------------------------------------------------------------

View File

@ -335,8 +335,7 @@ Material *MaterialManager::getMaterial(const std::string& fname,
bool is_full_path,
bool make_permanent,
bool complain_if_not_found,
bool strip_path,
bool srgb)
bool strip_path)
{
if(fname=="")
{

View File

@ -76,8 +76,7 @@ public:
bool is_full_path=false,
bool make_permanent=false,
bool complain_if_not_found=true,
bool strip_path=true,
bool srgb=false);
bool strip_path=true);
void addSharedMaterial(const std::string& filename, bool deprecated = false);
bool pushTempMaterial (const std::string& filename, bool deprecated = false);
bool pushTempMaterial (const XMLNode *root, const std::string& filename, bool deprecated = false);

View File

@ -257,7 +257,7 @@ Material* ParticleKind::getMaterial() const
if (material_manager->hasMaterial(m_material_file))
{
Material* material = material_manager->getMaterial(m_material_file);
if (material->getTexture() == NULL)
if (material->getTexture(true/*srgb*/, true/*premul_alpha*/) == NULL)
{
throw std::runtime_error("[ParticleKind] Cannot locate file " + m_material_file);
}

View File

@ -108,10 +108,12 @@ void STKTexManager::addTexture(STKTexture* t)
} // addTexture
// ----------------------------------------------------------------------------
void STKTexManager::dumpAllTexture()
void STKTexManager::dumpAllTexture(bool mesh_texture)
{
for (auto p : m_all_textures)
{
if (!p.second || (mesh_texture && !p.second->isMeshTexture()))
continue;
Log::info("STKTexManager", "%s loc: %p", p.first.c_str(), p.second);
}
} // dumpAllTexture

View File

@ -53,7 +53,7 @@ public:
// ------------------------------------------------------------------------
void removeTexture(STKTexture* t);
// ------------------------------------------------------------------------
void dumpAllTexture();
void dumpAllTexture(bool mesh_texture);
// ------------------------------------------------------------------------
int dumpTextureUsage();
// ------------------------------------------------------------------------