Port reload texture to use new STKTexManager
This commit is contained in:
parent
827a483e85
commit
4bcf03e296
@ -50,24 +50,6 @@ STKTexture* STKTexManager::findTextureInFileSystem(const std::string& filename,
|
|||||||
return NULL;
|
return NULL;
|
||||||
} // findTextureInFileSystem
|
} // findTextureInFileSystem
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
STKTexture* STKTexManager::findTexturePathless(const std::string& filename)
|
|
||||||
{
|
|
||||||
for (auto p : m_all_textures)
|
|
||||||
{
|
|
||||||
if (p.second == NULL)
|
|
||||||
continue;
|
|
||||||
std::string lc_name = StringUtils::toLowerCase(filename);
|
|
||||||
std::string lc_path =
|
|
||||||
StringUtils::toLowerCase(p.first);
|
|
||||||
std::string tex_name = StringUtils::getBasename(lc_path);
|
|
||||||
if (lc_name == tex_name || lc_name == lc_path)
|
|
||||||
return p.second;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
} // findTexturePathless
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
video::ITexture* STKTexManager::getTexture(const std::string& path, bool srgb,
|
||||||
bool premul_alpha,
|
bool premul_alpha,
|
||||||
@ -151,3 +133,51 @@ video::ITexture* STKTexManager::getUnicolorTexture(const irr::video::SColor &c)
|
|||||||
return texture;
|
return texture;
|
||||||
|
|
||||||
} // getUnicolorTexture
|
} // getUnicolorTexture
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
core::stringw STKTexManager::reloadTexture(const irr::core::stringw& name)
|
||||||
|
{
|
||||||
|
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 result;
|
||||||
|
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!";
|
||||||
|
return result + "reloaded.";
|
||||||
|
|
||||||
|
} // reloadTexture
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
#include "utils/no_copy.hpp"
|
#include "utils/no_copy.hpp"
|
||||||
#include "utils/singleton.hpp"
|
#include "utils/singleton.hpp"
|
||||||
|
|
||||||
|
#include "irrString.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
@ -37,8 +39,6 @@ class STKTexManager : public Singleton<STKTexManager>, NoCopy
|
|||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, STKTexture*> m_all_textures;
|
std::unordered_map<std::string, STKTexture*> m_all_textures;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------
|
|
||||||
STKTexture* findTexturePathless(const std::string& filename);
|
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
STKTexture* findTextureInFileSystem(const std::string& filename,
|
STKTexture* findTextureInFileSystem(const std::string& filename,
|
||||||
std::string* full_path);
|
std::string* full_path);
|
||||||
@ -66,6 +66,8 @@ public:
|
|||||||
int dumpTextureUsage();
|
int dumpTextureUsage();
|
||||||
// ------------------------------------------------------------------------
|
// ------------------------------------------------------------------------
|
||||||
void clean();
|
void clean();
|
||||||
|
// ------------------------------------------------------------------------
|
||||||
|
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
||||||
|
|
||||||
}; // STKTexManager
|
}; // STKTexManager
|
||||||
|
|
||||||
|
@ -245,79 +245,5 @@ void saveCompressedTexture(const std::string& compressed_tex)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
core::stringw reloadTexture(const core::stringw& name)
|
|
||||||
{
|
|
||||||
if (!CVS->isGLSL())
|
|
||||||
return L"Use shader based renderer to reload textures.";
|
|
||||||
if (CVS->isTextureCompressionEnabled())
|
|
||||||
return L"Please disable texture compression for reloading textures.";
|
|
||||||
|
|
||||||
if (name.empty())
|
|
||||||
{
|
|
||||||
for (video::ITexture* tex : AlreadyTransformedTexture)
|
|
||||||
reloadSingleTexture(tex);
|
|
||||||
return L"All textures reloaded.";
|
|
||||||
}
|
|
||||||
|
|
||||||
core::stringw result;
|
|
||||||
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 (video::ITexture* tex : AlreadyTransformedTexture)
|
|
||||||
{
|
|
||||||
std::string tex_path =
|
|
||||||
StringUtils::toLowerCase(tex->getName().getPtr());
|
|
||||||
std::string tex_name = StringUtils::getBasename(tex_path);
|
|
||||||
if (fname == tex_name || fname == tex_path)
|
|
||||||
{
|
|
||||||
if (reloadSingleTexture(tex))
|
|
||||||
{
|
|
||||||
result += tex_name.c_str();
|
|
||||||
result += L" ";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result.empty())
|
|
||||||
return L"Texture(s) not found!";
|
|
||||||
return result + "reloaded.";
|
|
||||||
}
|
|
||||||
|
|
||||||
bool reloadSingleTexture(video::ITexture* tex)
|
|
||||||
{
|
|
||||||
video::IImage* tmp =
|
|
||||||
irr_driver->getVideoDriver()->createImageFromFile(tex->getName());
|
|
||||||
if (tmp == NULL) return false;
|
|
||||||
|
|
||||||
const bool scaling = tmp->getDimension() != tex->getSize();
|
|
||||||
video::IImage* new_texture =
|
|
||||||
irr_driver->getVideoDriver()->createImage(video::ECF_A8R8G8B8,
|
|
||||||
scaling ? tex->getSize() : tmp->getDimension());
|
|
||||||
if (scaling)
|
|
||||||
tmp->copyToScaling(new_texture);
|
|
||||||
else
|
|
||||||
tmp->copyTo(new_texture);
|
|
||||||
tmp->drop();
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, getTextureGLuint(tex));
|
|
||||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, new_texture->getDimension().Width,
|
|
||||||
new_texture->getDimension().Height, GL_BGRA, GL_UNSIGNED_BYTE,
|
|
||||||
new_texture->lock());
|
|
||||||
new_texture->unlock();
|
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
#if defined(USE_GLES2)
|
|
||||||
static_cast<irr::video::COGLES2Texture*>(tex)->setImage(new_texture);
|
|
||||||
#else
|
|
||||||
static_cast<irr::video::COpenGLTexture*>(tex)->setImage(new_texture);
|
|
||||||
#endif
|
|
||||||
Log::info("TextureManager", "%s reloaded", tex->getName().getPtr());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // !SERVER_ONLY
|
#endif // !SERVER_ONLY
|
||||||
|
|
||||||
|
@ -26,14 +26,11 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
GLuint getTextureGLuint(irr::video::ITexture *tex);
|
GLuint getTextureGLuint(irr::video::ITexture *tex);
|
||||||
|
|
||||||
void resetTextureTable();
|
void resetTextureTable();
|
||||||
void cleanUnicolorTextures();
|
void cleanUnicolorTextures();
|
||||||
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = false);
|
void compressTexture(irr::video::ITexture *tex, bool srgb, bool premul_alpha = false);
|
||||||
bool loadCompressedTexture(const std::string& compressed_tex);
|
bool loadCompressedTexture(const std::string& compressed_tex);
|
||||||
void saveCompressedTexture(const std::string& compressed_tex);
|
void saveCompressedTexture(const std::string& compressed_tex);
|
||||||
void insertTextureHandle(uint64_t handle);
|
void insertTextureHandle(uint64_t handle);
|
||||||
bool reloadSingleTexture(irr::video::ITexture *tex);
|
|
||||||
irr::core::stringw reloadTexture(const irr::core::stringw& name);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "graphics/light.hpp"
|
#include "graphics/light.hpp"
|
||||||
#include "graphics/shaders.hpp"
|
#include "graphics/shaders.hpp"
|
||||||
#include "graphics/texture_manager.hpp"
|
#include "graphics/stk_tex_manager.hpp"
|
||||||
#include "guiengine/widgets/label_widget.hpp"
|
#include "guiengine/widgets/label_widget.hpp"
|
||||||
#include "guiengine/widgets/text_box_widget.hpp"
|
#include "guiengine/widgets/text_box_widget.hpp"
|
||||||
#include "items/powerup_manager.hpp"
|
#include "items/powerup_manager.hpp"
|
||||||
@ -133,7 +133,7 @@ enum DebugMenuCommand
|
|||||||
DEBUG_ADJUST_LIGHTS,
|
DEBUG_ADJUST_LIGHTS,
|
||||||
DEBUG_SCRIPT_CONSOLE,
|
DEBUG_SCRIPT_CONSOLE,
|
||||||
DEBUG_RUN_CUTSCENE,
|
DEBUG_RUN_CUTSCENE,
|
||||||
DEBUG_RELOAD_TEXTURE,
|
DEBUG_TEXTURE_CONSOLE,
|
||||||
}; // DebugMenuCommand
|
}; // DebugMenuCommand
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -687,15 +687,24 @@ bool handleContextMenuAction(s32 cmd_id)
|
|||||||
((CutsceneWorld*)World::getWorld())->setParts(parts);
|
((CutsceneWorld*)World::getWorld())->setParts(parts);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case DEBUG_RELOAD_TEXTURE:
|
case DEBUG_TEXTURE_CONSOLE:
|
||||||
new GeneralTextFieldDialog(
|
new GeneralTextFieldDialog(
|
||||||
L"Enter the texture filename(s) (separate names by ;)"
|
L"Enter the texture filename(s) (separate names by ;)"
|
||||||
" to be reloaded (empty to reload all)", []
|
" to be reloaded (empty to reload all)\n"
|
||||||
|
"Press tus; for texture usage stats (shown in console)", []
|
||||||
(const irr::core::stringw& text) {},
|
(const irr::core::stringw& text) {},
|
||||||
[] (GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
|
[] (GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
|
||||||
{
|
{
|
||||||
#ifndef SERVER_ONLY
|
#ifndef SERVER_ONLY
|
||||||
lw->setText(reloadTexture(tb->getText()), true);
|
core::stringw t = tb->getText();
|
||||||
|
STKTexManager* stktm = STKTexManager::getInstance();
|
||||||
|
if (t == "tus;")
|
||||||
|
{
|
||||||
|
stktm->dumpAllTexture(false/*mesh_texture*/);
|
||||||
|
stktm->dumpTextureUsage();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
lw->setText(stktm->reloadTexture(t), true);
|
||||||
#endif
|
#endif
|
||||||
// Don't close the dialog after each run
|
// Don't close the dialog after each run
|
||||||
return false;
|
return false;
|
||||||
@ -809,7 +818,7 @@ bool onEvent(const SEvent &event)
|
|||||||
mnu->addItem(L"Adjust Lights", DEBUG_ADJUST_LIGHTS);
|
mnu->addItem(L"Adjust Lights", DEBUG_ADJUST_LIGHTS);
|
||||||
mnu->addItem(L"Scripting console", DEBUG_SCRIPT_CONSOLE);
|
mnu->addItem(L"Scripting console", DEBUG_SCRIPT_CONSOLE);
|
||||||
mnu->addItem(L"Run cutscene(s)", DEBUG_RUN_CUTSCENE);
|
mnu->addItem(L"Run cutscene(s)", DEBUG_RUN_CUTSCENE);
|
||||||
mnu->addItem(L"Reload texture", DEBUG_RELOAD_TEXTURE);
|
mnu->addItem(L"Texture console", DEBUG_TEXTURE_CONSOLE);
|
||||||
|
|
||||||
g_debug_menu_visible = true;
|
g_debug_menu_visible = true;
|
||||||
irr_driver->showPointer();
|
irr_driver->showPointer();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user