1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Refactor ITextureSource use in main menu (#16135)

This commit is contained in:
sfan5 2025-05-24 22:49:29 +02:00 committed by GitHub
parent 452160cd00
commit 1214a1d4a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 21 deletions

View file

@ -172,7 +172,7 @@ public:
\return Pointer to the texture, or 0 if the texture \return Pointer to the texture, or 0 if the texture
could not be loaded. This pointer should not be dropped. See could not be loaded. This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */ IReferenceCounted::drop() for more information. */
virtual ITexture *getTexture(const io::path &filename) = 0; [[deprecated]] virtual ITexture *getTexture(const io::path &filename) = 0;
//! Get access to a named texture. //! Get access to a named texture.
/** Loads the texture from disk if it is not /** Loads the texture from disk if it is not
@ -184,7 +184,7 @@ public:
\return Pointer to the texture, or 0 if the texture \return Pointer to the texture, or 0 if the texture
could not be loaded. This pointer should not be dropped. See could not be loaded. This pointer should not be dropped. See
IReferenceCounted::drop() for more information. */ IReferenceCounted::drop() for more information. */
virtual ITexture *getTexture(io::IReadFile *file) = 0; [[deprecated]] virtual ITexture *getTexture(io::IReadFile *file) = 0;
//! Returns amount of textures currently loaded //! Returns amount of textures currently loaded
/** \return Amount of textures currently loaded */ /** \return Amount of textures currently loaded */

View file

@ -326,6 +326,18 @@ void ClientLauncher::setting_changed_callback(const std::string &name, void *dat
static_cast<ClientLauncher*>(data)->config_guienv(); static_cast<ClientLauncher*>(data)->config_guienv();
} }
static video::ITexture *loadTexture(video::IVideoDriver *driver, const char *path)
{
// FIXME?: it would be cleaner to do this through a ITextureSource, but we don't have one
video::ITexture *texture = nullptr;
verbosestream << "Loading texture " << path << std::endl;
if (auto *image = driver->createImageFromFile(path); image) {
texture = driver->addTexture(fs::GetFilenameFromPath(path), image);
image->drop();
}
return texture;
}
void ClientLauncher::config_guienv() void ClientLauncher::config_guienv()
{ {
gui::IGUISkin *skin = guienv->getSkin(); gui::IGUISkin *skin = guienv->getSkin();
@ -364,10 +376,9 @@ void ClientLauncher::config_guienv()
if (cached_id != sprite_ids.end()) { if (cached_id != sprite_ids.end()) {
skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, cached_id->second); skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, cached_id->second);
} else { } else {
gui::IGUISpriteBank *sprites = skin->getSpriteBank(); auto *driver = m_rendering_engine->get_video_driver();
video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); auto *texture = loadTexture(driver, path.c_str());
video::ITexture *texture = driver->getTexture(path.c_str()); s32 id = skin->getSpriteBank()->addTextureAsSprite(texture);
s32 id = sprites->addTextureAsSprite(texture);
if (id != -1) { if (id != -1) {
skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, id); skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, id);
sprite_ids.emplace(path, id); sprite_ids.emplace(path, id);

View file

@ -410,7 +410,7 @@ video::ITexture *ShadowRenderer::getSMTexture(const std::string &shadow_map_name
shadow_map_name.c_str(), texture_format); shadow_map_name.c_str(), texture_format);
} }
return m_driver->getTexture(shadow_map_name.c_str()); return m_driver->findTexture(shadow_map_name.c_str());
} }
void ShadowRenderer::renderShadowMap(video::ITexture *target, void ShadowRenderer::renderShadowMap(video::ITexture *target,

View file

@ -74,6 +74,7 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
if (retval) if (retval)
return retval; return retval;
verbosestream << "MenuTextureSource: loading " << name << std::endl;
video::IImage *image = m_driver->createImageFromFile(name.c_str()); video::IImage *image = m_driver->createImageFromFile(name.c_str());
if (!image) if (!image)
return NULL; return NULL;
@ -597,26 +598,16 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver)
bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath, bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath,
bool tile_image, unsigned int minsize) bool tile_image, unsigned int minsize)
{ {
video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); m_textures[layer].texture = nullptr;
if (m_textures[layer].texture) { if (texturepath.empty() || !fs::PathExists(texturepath))
driver->removeTexture(m_textures[layer].texture);
m_textures[layer].texture = NULL;
}
if (texturepath.empty() || !fs::PathExists(texturepath)) {
return false; return false;
}
m_textures[layer].texture = driver->getTexture(texturepath.c_str()); m_textures[layer].texture = m_texture_source->getTexture(texturepath);
m_textures[layer].tile = tile_image; m_textures[layer].tile = tile_image;
m_textures[layer].minsize = minsize; m_textures[layer].minsize = minsize;
if (!m_textures[layer].texture) { return m_textures[layer].texture != nullptr;
return false;
}
return true;
} }
/******************************************************************************/ /******************************************************************************/