Fix #1780
This commit is contained in:
parent
2641f0b067
commit
9af219f691
@ -56,7 +56,8 @@ STKTexture* STKTexManager::findTextureInFileSystem(const std::string& filename,
|
||||
video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
||||
bool premul_alpha,
|
||||
bool set_material, bool mesh_tex,
|
||||
bool no_upload, bool single_channel)
|
||||
bool no_upload, bool single_channel,
|
||||
bool create_if_unfound)
|
||||
{
|
||||
auto ret = m_all_textures.find(path);
|
||||
if (!no_upload && ret != m_all_textures.end())
|
||||
@ -73,24 +74,29 @@ video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
||||
return new_texture;
|
||||
}
|
||||
|
||||
new_texture = new STKTexture(full_path.empty() ? path : full_path, srgb,
|
||||
premul_alpha, set_material, mesh_tex, no_upload, single_channel);
|
||||
if (new_texture->getOpenGLTextureName() == 0 && !no_upload)
|
||||
if (create_if_unfound)
|
||||
{
|
||||
m_all_textures[new_texture->getName().getPtr()] = NULL;
|
||||
delete new_texture;
|
||||
return NULL;
|
||||
new_texture = new STKTexture(full_path.empty() ? path : full_path,
|
||||
srgb, premul_alpha, set_material, mesh_tex, no_upload,
|
||||
single_channel);
|
||||
if (new_texture->getOpenGLTextureName() == 0 && !no_upload)
|
||||
{
|
||||
m_all_textures[new_texture->getName().getPtr()] = NULL;
|
||||
delete new_texture;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!no_upload)
|
||||
if (create_if_unfound && !no_upload)
|
||||
addTexture(new_texture);
|
||||
return new_texture;
|
||||
} // getTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void STKTexManager::addTexture(STKTexture* texture)
|
||||
video::ITexture* STKTexManager::addTexture(STKTexture* texture)
|
||||
{
|
||||
m_all_textures[texture->getName().getPtr()] = texture;
|
||||
return texture;
|
||||
} // addTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -54,11 +54,12 @@ public:
|
||||
bool set_material = false,
|
||||
bool mesh_tex = false,
|
||||
bool no_upload = false,
|
||||
bool single_channel = false);
|
||||
bool single_channel = false,
|
||||
bool create_if_unfound = true);
|
||||
// ------------------------------------------------------------------------
|
||||
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);
|
||||
// ------------------------------------------------------------------------
|
||||
void addTexture(STKTexture* texture);
|
||||
irr::video::ITexture* addTexture(STKTexture* texture);
|
||||
// ------------------------------------------------------------------------
|
||||
void removeTexture(STKTexture* texture, bool remove_all = false);
|
||||
// ------------------------------------------------------------------------
|
||||
|
@ -15,10 +15,13 @@
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "graphics/central_settings.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/stk_texture.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
#include "guiengine/widgets/icon_button_widget.hpp"
|
||||
#include "io/file_manager.hpp"
|
||||
#include "utils/log.hpp"
|
||||
#include "utils/translation.hpp"
|
||||
@ -329,21 +332,28 @@ const video::ITexture* IconButtonWidget::getTexture()
|
||||
// -----------------------------------------------------------------------------
|
||||
video::ITexture* IconButtonWidget::getDeactivatedTexture(video::ITexture* texture)
|
||||
{
|
||||
#ifdef DO_NOT_USE_IT_CAUSES_BUG_1780_FONT_CORRUPTION
|
||||
video::ITexture* t;
|
||||
STKTexture* stk_tex = static_cast<STKTexture*>(texture);
|
||||
#ifndef SERVER_ONLY
|
||||
// Compressed texture can't be turned into greyscale
|
||||
if (stk_tex->isMeshTexture() && CVS->isTextureCompressionEnabled())
|
||||
return stk_tex;
|
||||
|
||||
std::string name = texture->getName().getPath().c_str();
|
||||
std::string name = stk_tex->getName().getPtr();
|
||||
name += "_disabled";
|
||||
t = irr_driver->getTexture(name, /*premul*/false, /*prediv*/false,
|
||||
/*compain_if_not_found*/false);
|
||||
if (t == NULL)
|
||||
STKTexManager* stkm = STKTexManager::getInstance();
|
||||
STKTexture* disabled_stk_tex = static_cast<STKTexture*>(stkm->getTexture
|
||||
(name, false/*srgb*/, false/*premul_alpha*/, false/*set_material*/,
|
||||
false/*mesh_tex*/, false /*no_upload*/, false/*single_channel*/,
|
||||
false/*create_if_unfound*/));
|
||||
if (disabled_stk_tex == NULL)
|
||||
{
|
||||
SColor c;
|
||||
u32 g;
|
||||
|
||||
video::IVideoDriver* driver = irr_driver->getVideoDriver();
|
||||
std::unique_ptr<video::IImage> image (driver->createImageFromData (texture->getColorFormat(),
|
||||
texture->getSize(), texture->lock(), false));
|
||||
video::IImage* image = driver->createImageFromData
|
||||
(video::ECF_A8R8G8B8, stk_tex->getSize(), stk_tex->lock(),
|
||||
stk_tex->getTextureImage() == NULL/*ownForeignMemory*/);
|
||||
texture->unlock();
|
||||
|
||||
//Turn the image into grayscale
|
||||
@ -357,13 +367,10 @@ video::ITexture* IconButtonWidget::getDeactivatedTexture(video::ITexture* textur
|
||||
image->setPixel(x, y, c);
|
||||
}
|
||||
}
|
||||
|
||||
t = driver->addTexture(name.c_str(), image.get ());
|
||||
return stkm->addTexture(new STKTexture(image, name));
|
||||
}
|
||||
|
||||
return t;
|
||||
#endif
|
||||
return texture;
|
||||
#endif // !SERVER_ONLY
|
||||
return disabled_stk_tex;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user