Add unicolor texture loading

This commit is contained in:
Benau 2017-01-05 14:51:38 +08:00
parent 6e4d7da487
commit 513f1e2edf
3 changed files with 25 additions and 1 deletions

View File

@ -17,6 +17,7 @@
#include "graphics/stk_tex_manager.hpp"
#include "graphics/central_settings.hpp"
#include "graphics/irr_driver.hpp"
#include "graphics/stk_texture.hpp"
#include "io/file_manager.hpp"
#include "utils/string_utils.hpp"
@ -131,3 +132,21 @@ int STKTexManager::dumpTextureUsage()
Log::info("STKTexManager", "Total %dMB", size);
return size;
} // dumpAllTexture
// ----------------------------------------------------------------------------
STKTexture* STKTexManager::getUnicolorTexture(const irr::video::SColor &c)
{
std::string name = StringUtils::toString(c.color) + "unic";
auto ret = m_all_textures.find(name);
if (ret != m_all_textures.end())
return ret->second;
uint32_t color[4] = { c.color, c.color, c.color, c.color };
video::IImage* image = irr_driver->getVideoDriver()
->createImageFromData(video::ECF_A8R8G8B8,
core::dimension2d<u32>(2, 2), color);
STKTexture* texture = new STKTexture(image, name);
addTexture(texture);
return texture;
} // getUnicolorTexture

View File

@ -27,6 +27,10 @@
#include <unordered_map>
class STKTexture;
namespace irr
{
namespace video { class SColor; }
}
class STKTexManager : public Singleton<STKTexManager>, NoCopy
{
@ -49,6 +53,8 @@ public:
bool set_material = false,
bool mesh_tex = false, bool no_upload = false);
// ------------------------------------------------------------------------
STKTexture* getUnicolorTexture(const irr::video::SColor &c);
// ------------------------------------------------------------------------
void addTexture(STKTexture* t);
// ------------------------------------------------------------------------
void removeTexture(STKTexture* t);

View File

@ -25,7 +25,6 @@
#include <fstream>
#include <functional>
#include <sstream>
// ----------------------------------------------------------------------------
STKTexture::STKTexture(const std::string& path, bool srgb, bool premul_alpha,