Fixed ground spots not working after changing texture params; use UpdateTexture instead of destroy and recreate
parent
bfdce26721
commit
d812db19f8
|
@ -374,6 +374,7 @@ void CEngine::ReloadAllTextures()
|
|||
m_text->FlushCache();
|
||||
|
||||
CRobotMain::GetInstancePointer()->ReloadAllTextures(); //TODO: Remove cross-reference to CRobotMain
|
||||
UpdateGroundSpotTextures();
|
||||
LoadAllTextures();
|
||||
}
|
||||
|
||||
|
@ -1503,12 +1504,7 @@ void CEngine::DeleteAllGroundSpots()
|
|||
str << "shadow" << std::setfill('0') << std::setw(2) << s << ".png";
|
||||
std::string texName = str.str();
|
||||
|
||||
DeleteTexture(texName);
|
||||
|
||||
Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams);
|
||||
|
||||
m_texNameMap[texName] = tex;
|
||||
m_revTexNameMap[tex] = texName;
|
||||
CreateOrUpdateTexture(texName, &shadowImg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2367,8 +2363,6 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
|
|||
Math::Point ts, Math::Point ti,
|
||||
Math::Point *exclude, float shift, bool hsv)
|
||||
{
|
||||
DeleteTexture(texName);
|
||||
|
||||
CImage img;
|
||||
if (!img.Load(srcName))
|
||||
{
|
||||
|
@ -2474,18 +2468,7 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Texture tex = m_device->CreateTexture(&img, m_defaultTexParams);
|
||||
|
||||
if (! tex.Valid())
|
||||
{
|
||||
GetLogger()->Error("Couldn't load texture '%s', blacklisting\n", texName.c_str());
|
||||
m_texBlacklist.insert(texName);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_texNameMap[texName] = tex;
|
||||
m_revTexNameMap[tex] = texName;
|
||||
CreateOrUpdateTexture(texName, &img);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2531,6 +2514,19 @@ void CEngine::DeleteTexture(const Texture& tex)
|
|||
m_texNameMap.erase(it);
|
||||
}
|
||||
|
||||
void CEngine::CreateOrUpdateTexture(const std::string& texName, CImage* img)
|
||||
{
|
||||
auto it = m_texNameMap.find(texName);
|
||||
if (it == m_texNameMap.end())
|
||||
{
|
||||
LoadTexture(texName, img);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_device->UpdateTexture((*it).second, Math::IntPoint(0, 0), img->GetData(), m_defaultTexParams.format);
|
||||
}
|
||||
}
|
||||
|
||||
void CEngine::FlushTextureCache()
|
||||
{
|
||||
m_device->DestroyAllTextures();
|
||||
|
@ -4135,12 +4131,7 @@ void CEngine::UpdateGroundSpotTextures()
|
|||
str << "textures/shadow" << std::setfill('0') << std::setw(2) << s << ".png";
|
||||
std::string texName = str.str();
|
||||
|
||||
DeleteTexture(texName);
|
||||
|
||||
Gfx::Texture tex = m_device->CreateTexture(&shadowImg, m_defaultTexParams);
|
||||
|
||||
m_texNameMap[texName] = tex;
|
||||
m_revTexNameMap[tex] = texName;
|
||||
CreateOrUpdateTexture(texName, &shadowImg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -946,6 +946,9 @@ public:
|
|||
//! Deletes the given texture, unloading it and removing from cache
|
||||
void DeleteTexture(const Texture& tex);
|
||||
|
||||
//! Creates or updates the given texture with given image data
|
||||
void CreateOrUpdateTexture(const std::string& texName, CImage* img);
|
||||
|
||||
//! Empties the texture cache
|
||||
void FlushTextureCache();
|
||||
|
||||
|
|
|
@ -3398,7 +3398,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
|
|||
InitEye();
|
||||
SetMovieLock(false);
|
||||
|
||||
if(!resetObject)
|
||||
if (!resetObject)
|
||||
ChangeColor(); // changes the colors of texture
|
||||
|
||||
if (!m_sceneReadPath.empty()) // loading file ?
|
||||
|
@ -4011,9 +4011,6 @@ void CRobotMain::ChangeColor()
|
|||
ts = Math::Point(0.00f, 0.75f);
|
||||
ti = Math::Point(0.25f, 1.00f);
|
||||
m_engine->ChangeTextureColor("textures/effect02.png", m_colorRefWater, m_colorNewWater, colorRef2, colorNew2, 0.20f, -1.0f, ts, ti, nullptr, m_colorShiftWater, true);
|
||||
|
||||
// This loads the newly recolored textures to objects
|
||||
m_engine->LoadAllTextures();
|
||||
}
|
||||
|
||||
//! Calculates the distance to the nearest object
|
||||
|
|
Loading…
Reference in New Issue