Allow to reload textures on the fly
Enter texture filename(s) (full path is optional) separating by ";" in the artist debug mode "Reload texture" dialog Notice: premultiplied alpha texture reloading is not supported, because it was done on STK side.
This commit is contained in:
parent
b9b8ab3e5f
commit
67b6c3bf05
@ -66,6 +66,10 @@ struct SNamedPath
|
|||||||
{
|
{
|
||||||
return core::stringw(getPath());
|
return core::stringw(getPath());
|
||||||
}
|
}
|
||||||
|
const c8* getPtr() const
|
||||||
|
{
|
||||||
|
return getPath().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// convert the given path string to a name string.
|
// convert the given path string to a name string.
|
||||||
|
@ -1838,7 +1838,7 @@ void IrrDriver::applyMask(video::ITexture* texture,
|
|||||||
if (img == NULL || mask == NULL)
|
if (img == NULL || mask == NULL)
|
||||||
{
|
{
|
||||||
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
||||||
core::stringc(texture->getName()).c_str());
|
texture->getName().getPtr());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1887,7 +1887,7 @@ void IrrDriver::applyMask(video::ITexture* texture,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
Log::warn("irr_driver", "Applying mask failed for '%s'!",
|
||||||
core::stringc(texture->getName()).c_str());
|
texture->getName().getPtr());
|
||||||
img->drop();
|
img->drop();
|
||||||
mask->drop();
|
mask->drop();
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "graphics/central_settings.hpp"
|
#include "graphics/central_settings.hpp"
|
||||||
#include "graphics/irr_driver.hpp"
|
#include "graphics/irr_driver.hpp"
|
||||||
#include "graphics/materials.hpp"
|
#include "graphics/materials.hpp"
|
||||||
|
#include "utils/string_utils.hpp"
|
||||||
|
|
||||||
#if defined(USE_GLES2)
|
#if defined(USE_GLES2)
|
||||||
#define _IRR_COMPILE_WITH_OGLES2_
|
#define _IRR_COMPILE_WITH_OGLES2_
|
||||||
@ -280,5 +281,75 @@ video::ITexture* getUnicolorTexture(const video::SColor &c)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
std::vector<std::string> names =
|
||||||
|
StringUtils::split(StringUtils::wideToUtf8(name), ';');
|
||||||
|
for (const std::string& fname : names)
|
||||||
|
{
|
||||||
|
for (video::ITexture* tex : AlreadyTransformedTexture)
|
||||||
|
{
|
||||||
|
std::string tex_path = tex->getName().getPtr();
|
||||||
|
std::string tex_name = StringUtils::getBasename(tex_path).c_str();
|
||||||
|
if (fname == tex_name || fname == tex_path)
|
||||||
|
{
|
||||||
|
if (reloadSingleTexture(tex))
|
||||||
|
{
|
||||||
|
result += tex_name.c_str();
|
||||||
|
result += L" ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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
|
||||||
|
|
||||||
|
@ -34,5 +34,7 @@ bool loadCompressedTexture(const std::string& compressed_tex);
|
|||||||
void saveCompressedTexture(const std::string& compressed_tex);
|
void saveCompressedTexture(const std::string& compressed_tex);
|
||||||
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);
|
irr::video::ITexture* getUnicolorTexture(const irr::video::SColor &c);
|
||||||
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,6 +29,8 @@
|
|||||||
#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 "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"
|
||||||
#include "items/attachment.hpp"
|
#include "items/attachment.hpp"
|
||||||
@ -131,6 +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,
|
||||||
}; // DebugMenuCommand
|
}; // DebugMenuCommand
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@ -684,6 +687,18 @@ bool handleContextMenuAction(s32 cmd_id)
|
|||||||
((CutsceneWorld*)World::getWorld())->setParts(parts);
|
((CutsceneWorld*)World::getWorld())->setParts(parts);
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case DEBUG_RELOAD_TEXTURE:
|
||||||
|
new GeneralTextFieldDialog(
|
||||||
|
L"Enter the texture filename(s) (separate names by ;)"
|
||||||
|
" to be reloaded (empty to reload all)", []
|
||||||
|
(const irr::core::stringw& text) {},
|
||||||
|
[] (GUIEngine::LabelWidget* lw, GUIEngine::TextBoxWidget* tb)->bool
|
||||||
|
{
|
||||||
|
lw->setText(reloadTexture(tb->getText()), true);
|
||||||
|
// Don't close the dialog after each run
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
break;
|
||||||
} // switch
|
} // switch
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -792,6 +807,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);
|
||||||
|
|
||||||
g_debug_menu_visible = true;
|
g_debug_menu_visible = true;
|
||||||
irr_driver->showPointer();
|
irr_driver->showPointer();
|
||||||
|
Loading…
Reference in New Issue
Block a user