Allow mesh textures to be reloaded
This commit is contained in:
parent
281b30dd5d
commit
0d74b1739b
@ -169,14 +169,68 @@ void SPTextureManager::removeUnusedTextures()
|
||||
} // removeUnusedTextures
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void SPTextureManager::dumpAllTexture()
|
||||
void SPTextureManager::dumpAllTextures()
|
||||
{
|
||||
for (auto p : m_textures)
|
||||
{
|
||||
Log::info("STKTexManager", "%s size: %0.2fK", p.first.c_str(),
|
||||
(p.second->getWidth() * p.second->getHeight() * 4) / 1024.0f);
|
||||
Log::info("SPTextureManager", "%s", p.first.c_str());
|
||||
}
|
||||
} // dumpAllTexture
|
||||
} // dumpAllTextures
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
core::stringw SPTextureManager::reloadTexture(const core::stringw& name)
|
||||
{
|
||||
core::stringw result;
|
||||
#ifndef SERVER_ONLY
|
||||
if (name.empty())
|
||||
{
|
||||
for (auto p : m_textures)
|
||||
{
|
||||
if (p.second->getPath().empty() ||
|
||||
p.second->getPath() == "unicolor_white")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
addThreadedFunction(std::bind(&SPTexture::threadedLoad, p.second));
|
||||
Log::info("SPTextureManager", "%s reloaded",
|
||||
p.second->getPath().c_str());
|
||||
}
|
||||
return L"All textures reloaded.";
|
||||
}
|
||||
|
||||
core::stringw list = name;
|
||||
list.make_lower().replace(L'\u005C', L'\u002F');
|
||||
std::vector<std::string> names =
|
||||
StringUtils::split(StringUtils::wideToUtf8(list), ';');
|
||||
for (const std::string& fname : names)
|
||||
{
|
||||
for (auto p : m_textures)
|
||||
{
|
||||
if (p.second->getPath().empty() ||
|
||||
p.second->getPath() == "unicolor_white")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
std::string tex_path =
|
||||
StringUtils::toLowerCase(p.second->getPath());
|
||||
std::string tex_name = StringUtils::getBasename(tex_path);
|
||||
if (fname == tex_name || fname == tex_path)
|
||||
{
|
||||
addThreadedFunction(std::bind(&SPTexture::threadedLoad,
|
||||
p.second));
|
||||
result += tex_name.c_str();
|
||||
result += L" ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.empty())
|
||||
{
|
||||
return L"Texture(s) not found!";
|
||||
}
|
||||
#endif // !SERVER_ONLY
|
||||
return result + "reloaded.";
|
||||
} // reloadTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
}
|
||||
|
@ -31,11 +31,12 @@
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "irrString.h"
|
||||
|
||||
class Material;
|
||||
|
||||
namespace SP
|
||||
@ -108,9 +109,9 @@ public:
|
||||
Material* m, bool undo_srgb,
|
||||
const std::string& container_id);
|
||||
// ------------------------------------------------------------------------
|
||||
int dumpTextureUsage();
|
||||
void dumpAllTextures();
|
||||
// ------------------------------------------------------------------------
|
||||
void dumpAllTexture();
|
||||
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
||||
|
||||
};
|
||||
|
||||
|
@ -152,81 +152,6 @@ void STKTexManager::removeTexture(STKTexture* texture, bool remove_all)
|
||||
#endif
|
||||
} // removeTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
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 size: %0.2fK", p.first.c_str(),
|
||||
float(p.second->getTextureSize()) / 1024);
|
||||
}
|
||||
} // dumpAllTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int STKTexManager::dumpTextureUsage()
|
||||
{
|
||||
int size = 0;
|
||||
for (auto p : m_all_textures)
|
||||
{
|
||||
if (p.second == NULL)
|
||||
continue;
|
||||
size += p.second->getTextureSize() / 1024 / 1024;
|
||||
}
|
||||
Log::info("STKTexManager", "Total %dMB", size);
|
||||
return size;
|
||||
} // dumpAllTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
core::stringw STKTexManager::reloadTexture(const irr::core::stringw& name)
|
||||
{
|
||||
core::stringw result;
|
||||
#ifndef SERVER_ONLY
|
||||
if (CVS->isTextureCompressionEnabled())
|
||||
return L"Please disable texture compression for reloading textures.";
|
||||
|
||||
if (name.empty())
|
||||
{
|
||||
for (auto p : m_all_textures)
|
||||
{
|
||||
if (p.second == NULL || !p.second->isMeshTexture())
|
||||
continue;
|
||||
p.second->reload();
|
||||
Log::info("STKTexManager", "%s reloaded",
|
||||
p.second->getName().getPtr());
|
||||
}
|
||||
return L"All textures reloaded.";
|
||||
}
|
||||
|
||||
core::stringw list = name;
|
||||
list.make_lower().replace(L'\u005C', L'\u002F');
|
||||
std::vector<std::string> names =
|
||||
StringUtils::split(StringUtils::wideToUtf8(list), ';');
|
||||
for (const std::string& fname : names)
|
||||
{
|
||||
for (auto p : m_all_textures)
|
||||
{
|
||||
if (p.second == NULL || !p.second->isMeshTexture())
|
||||
continue;
|
||||
std::string tex_path =
|
||||
StringUtils::toLowerCase(p.second->getName().getPtr());
|
||||
std::string tex_name = StringUtils::getBasename(tex_path);
|
||||
if (fname == tex_name || fname == tex_path)
|
||||
{
|
||||
p.second->reload();
|
||||
result += tex_name.c_str();
|
||||
result += L" ";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.empty())
|
||||
return L"Texture(s) not found!";
|
||||
#endif // !SERVER_ONLY
|
||||
return result + "reloaded.";
|
||||
} // reloadTexture
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Sets an error message to be displayed when a texture is not found. This
|
||||
* error message is shown before the "Texture %s not found or invalid"
|
||||
@ -244,3 +169,17 @@ void STKTexManager::setTextureErrorMessage(const std::string &error,
|
||||
else
|
||||
m_texture_error_message = StringUtils::insertValues(error, detail);
|
||||
} // setTextureErrorMessage
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
int STKTexManager::dumpTextureUsage()
|
||||
{
|
||||
int size = 0;
|
||||
for (auto p : m_all_textures)
|
||||
{
|
||||
if (p.second == NULL)
|
||||
continue;
|
||||
size += p.second->getTextureSize() / 1024 / 1024;
|
||||
}
|
||||
Log::info("STKTexManager", "Total %dMB", size);
|
||||
return size;
|
||||
} // dumpTextureUsage
|
||||
|
@ -83,12 +83,8 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
void removeTexture(STKTexture* texture, bool remove_all = false);
|
||||
// ------------------------------------------------------------------------
|
||||
void dumpAllTexture(bool mesh_texture);
|
||||
// ------------------------------------------------------------------------
|
||||
int dumpTextureUsage();
|
||||
// ------------------------------------------------------------------------
|
||||
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the currently defined texture error message, which is used
|
||||
* by event_handler.cpp to print additional info about irrlicht
|
||||
* internal errors or warnings. If no error message is currently
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "graphics/light.hpp"
|
||||
#include "graphics/shader.hpp"
|
||||
#include "graphics/stk_tex_manager.hpp"
|
||||
#include "graphics/sp/sp_base.hpp"
|
||||
#include "graphics/sp/sp_texture_manager.hpp"
|
||||
#include "guiengine/widgets/label_widget.hpp"
|
||||
@ -697,20 +696,19 @@ bool handleContextMenuAction(s32 cmd_id)
|
||||
new GeneralTextFieldDialog(
|
||||
L"Enter the texture filename(s) (separate names by ;)"
|
||||
" to be reloaded (empty to reload all)\n"
|
||||
"Press tus; for texture usage stats (shown in console)", []
|
||||
"Press tus; for showing all mesh textures (shown in console)", []
|
||||
(const irr::core::stringw& text) {},
|
||||
[] (GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
core::stringw t = tb->getText();
|
||||
STKTexManager* stktm = STKTexManager::getInstance();
|
||||
SP::SPTextureManager* sptm = SP::SPTextureManager::get();
|
||||
if (t == "tus;")
|
||||
{
|
||||
SP::SPTextureManager::get()->dumpAllTexture();
|
||||
stktm->dumpTextureUsage();
|
||||
sptm->dumpAllTextures();
|
||||
return false;
|
||||
}
|
||||
lw->setText(stktm->reloadTexture(t), true);
|
||||
lw->setText(sptm->reloadTexture(t), true);
|
||||
#endif
|
||||
// Don't close the dialog after each run
|
||||
return false;
|
||||
@ -888,7 +886,7 @@ bool handleStaticAction(int key)
|
||||
}
|
||||
else if (key == IRR_KEY_F3)
|
||||
{
|
||||
STKTexManager::getInstance()->reloadTexture("");
|
||||
SP::SPTextureManager::get()->reloadTexture("");
|
||||
return true;
|
||||
}
|
||||
// TODO: create more keyboard shortcuts
|
||||
|
Loading…
Reference in New Issue
Block a user