mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 01:05:48 +01:00 
			
		
		
		
	Refactor ITextureSource use in main menu (#16135)
This commit is contained in:
		@@ -172,7 +172,7 @@ public:
 | 
			
		||||
	\return Pointer to the texture, or 0 if the texture
 | 
			
		||||
	could not be loaded. This pointer should not be dropped. See
 | 
			
		||||
	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.
 | 
			
		||||
	/** Loads the texture from disk if it is not
 | 
			
		||||
@@ -184,7 +184,7 @@ public:
 | 
			
		||||
	\return Pointer to the texture, or 0 if the texture
 | 
			
		||||
	could not be loaded. This pointer should not be dropped. See
 | 
			
		||||
	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
 | 
			
		||||
	/** \return Amount of textures currently loaded */
 | 
			
		||||
 
 | 
			
		||||
@@ -326,6 +326,18 @@ void ClientLauncher::setting_changed_callback(const std::string &name, void *dat
 | 
			
		||||
	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()
 | 
			
		||||
{
 | 
			
		||||
	gui::IGUISkin *skin = guienv->getSkin();
 | 
			
		||||
@@ -364,10 +376,9 @@ void ClientLauncher::config_guienv()
 | 
			
		||||
		if (cached_id != sprite_ids.end()) {
 | 
			
		||||
			skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, cached_id->second);
 | 
			
		||||
		} else {
 | 
			
		||||
			gui::IGUISpriteBank *sprites = skin->getSpriteBank();
 | 
			
		||||
			video::IVideoDriver *driver = m_rendering_engine->get_video_driver();
 | 
			
		||||
			video::ITexture *texture = driver->getTexture(path.c_str());
 | 
			
		||||
			s32 id = sprites->addTextureAsSprite(texture);
 | 
			
		||||
			auto *driver = m_rendering_engine->get_video_driver();
 | 
			
		||||
			auto *texture = loadTexture(driver, path.c_str());
 | 
			
		||||
			s32 id = skin->getSpriteBank()->addTextureAsSprite(texture);
 | 
			
		||||
			if (id != -1) {
 | 
			
		||||
				skin->setIcon(gui::EGDI_CHECK_BOX_CHECKED, id);
 | 
			
		||||
				sprite_ids.emplace(path, id);
 | 
			
		||||
 
 | 
			
		||||
@@ -410,7 +410,7 @@ video::ITexture *ShadowRenderer::getSMTexture(const std::string &shadow_map_name
 | 
			
		||||
				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,
 | 
			
		||||
 
 | 
			
		||||
@@ -74,6 +74,7 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
 | 
			
		||||
	if (retval)
 | 
			
		||||
		return retval;
 | 
			
		||||
 | 
			
		||||
	verbosestream << "MenuTextureSource: loading " << name << std::endl;
 | 
			
		||||
	video::IImage *image = m_driver->createImageFromFile(name.c_str());
 | 
			
		||||
	if (!image)
 | 
			
		||||
		return NULL;
 | 
			
		||||
@@ -597,26 +598,16 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver)
 | 
			
		||||
bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath,
 | 
			
		||||
		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) {
 | 
			
		||||
		driver->removeTexture(m_textures[layer].texture);
 | 
			
		||||
		m_textures[layer].texture = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (texturepath.empty() || !fs::PathExists(texturepath)) {
 | 
			
		||||
	if (texturepath.empty() || !fs::PathExists(texturepath))
 | 
			
		||||
		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].minsize = minsize;
 | 
			
		||||
 | 
			
		||||
	if (!m_textures[layer].texture) {
 | 
			
		||||
		return false;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return true;
 | 
			
		||||
	return m_textures[layer].texture != nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/******************************************************************************/
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user