mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Clean up TextureSource and related code
This commit is contained in:
parent
0bdd5f294e
commit
b841c23701
5 changed files with 43 additions and 67 deletions
|
@ -344,38 +344,3 @@ void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::I
|
|||
dest->setPixel(dx, dy, pxl);
|
||||
}
|
||||
}
|
||||
|
||||
/* Check and align image to npot2 if required by hardware
|
||||
* @param image image to check for npot2 alignment
|
||||
* @param driver driver to use for image operations
|
||||
* @return image or copy of image aligned to npot2
|
||||
*/
|
||||
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver)
|
||||
{
|
||||
if (image == nullptr)
|
||||
return image;
|
||||
|
||||
if (driver->queryFeature(video::EVDF_TEXTURE_NPOT))
|
||||
return image;
|
||||
|
||||
core::dimension2d<u32> dim = image->getDimension();
|
||||
unsigned int height = npot2(dim.Height);
|
||||
unsigned int width = npot2(dim.Width);
|
||||
|
||||
if (dim.Height == height && dim.Width == width)
|
||||
return image;
|
||||
|
||||
if (dim.Height > height)
|
||||
height *= 2;
|
||||
if (dim.Width > width)
|
||||
width *= 2;
|
||||
|
||||
video::IImage *targetimage =
|
||||
driver->createImage(video::ECF_A8R8G8B8,
|
||||
core::dimension2d<u32>(width, height));
|
||||
|
||||
if (targetimage != nullptr)
|
||||
image->copyToScaling(targetimage);
|
||||
image->drop();
|
||||
return targetimage;
|
||||
}
|
||||
|
|
|
@ -39,11 +39,3 @@ video::SColor imageAverageColor(const video::IImage *img);
|
|||
* and downscaling.
|
||||
*/
|
||||
void imageScaleNNAA(video::IImage *src, const core::rect<s32> &srcrect, video::IImage *dest);
|
||||
|
||||
/* Check and align image to npot2 if required by hardware
|
||||
* @param image image to check for npot2 alignment
|
||||
* @param driver driver to use for image operations
|
||||
* @return image or copy of image aligned to npot2
|
||||
*/
|
||||
video::IImage *Align2Npot2(video::IImage *image, video::IVideoDriver *driver);
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ private:
|
|||
// The first position contains a NULL texture.
|
||||
std::vector<TextureInfo> m_textureinfo_cache;
|
||||
// Maps a texture name to an index in the former.
|
||||
std::map<std::string, u32> m_name_to_id;
|
||||
std::unordered_map<std::string, u32> m_name_to_id;
|
||||
// The two former containers are behind this mutex
|
||||
std::mutex m_textureinfo_cache_mutex;
|
||||
|
||||
|
@ -286,7 +286,6 @@ u32 TextureSource::generateTexture(const std::string &name)
|
|||
video::ITexture *tex = nullptr;
|
||||
|
||||
if (img) {
|
||||
img = Align2Npot2(img, driver);
|
||||
// Create texture from resulting image
|
||||
tex = driver->addTexture(name.c_str(), img);
|
||||
guiScalingCache(io::path(name.c_str()), driver, img);
|
||||
|
@ -447,6 +446,13 @@ void TextureSource::rebuildImagesAndTextures()
|
|||
{
|
||||
MutexAutoLock lock(m_textureinfo_cache_mutex);
|
||||
|
||||
/*
|
||||
* Note: While it may become useful in the future, it's not clear what the
|
||||
* current purpose of this function is. The client loads all media into a
|
||||
* freshly created texture source, so the only two textures that will ever be
|
||||
* rebuilt are 'progress_bar.png' and 'progress_bar_bg.png'.
|
||||
*/
|
||||
|
||||
video::IVideoDriver *driver = RenderingEngine::get_video_driver();
|
||||
sanity_check(driver);
|
||||
|
||||
|
@ -459,6 +465,8 @@ void TextureSource::rebuildImagesAndTextures()
|
|||
continue; // Skip dummy entry
|
||||
rebuildTexture(driver, ti);
|
||||
}
|
||||
|
||||
// FIXME: we should rebuild palettes too
|
||||
}
|
||||
|
||||
void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti)
|
||||
|
@ -470,7 +478,6 @@ void TextureSource::rebuildTexture(video::IVideoDriver *driver, TextureInfo &ti)
|
|||
// Shouldn't really need to be done, but can't hurt.
|
||||
std::set<std::string> source_image_names;
|
||||
video::IImage *img = m_imagesource.generateImage(ti.name, source_image_names);
|
||||
img = Align2Npot2(img, driver);
|
||||
// Create texture from resulting image
|
||||
video::ITexture *t = nullptr;
|
||||
if (img) {
|
||||
|
|
|
@ -25,9 +25,9 @@ class ISimpleTextureSource
|
|||
{
|
||||
public:
|
||||
ISimpleTextureSource() = default;
|
||||
|
||||
virtual ~ISimpleTextureSource() = default;
|
||||
|
||||
/// @brief Generates and gets a texture
|
||||
virtual video::ITexture *getTexture(
|
||||
const std::string &name, u32 *id = nullptr) = 0;
|
||||
};
|
||||
|
@ -36,24 +36,38 @@ class ITextureSource : public ISimpleTextureSource
|
|||
{
|
||||
public:
|
||||
ITextureSource() = default;
|
||||
|
||||
virtual ~ITextureSource() = default;
|
||||
|
||||
using ISimpleTextureSource::getTexture;
|
||||
|
||||
/// @brief Generates and gets ID of a texture
|
||||
virtual u32 getTextureId(const std::string &name)=0;
|
||||
|
||||
/// @brief Returns name of existing texture by ID
|
||||
virtual std::string getTextureName(u32 id)=0;
|
||||
|
||||
/// @brief Returns existing texture by ID
|
||||
virtual video::ITexture *getTexture(u32 id)=0;
|
||||
virtual video::ITexture* getTexture(
|
||||
const std::string &name, u32 *id = nullptr)=0;
|
||||
|
||||
/**
|
||||
* @brief Generates and gets a texture
|
||||
* Filters will be applied to make the texture suitable for mipmapping and
|
||||
* linear filtering during rendering.
|
||||
*/
|
||||
virtual video::ITexture *getTextureForMesh(
|
||||
const std::string &name, u32 *id = nullptr) = 0;
|
||||
/*!
|
||||
/**
|
||||
* Returns a palette from the given texture name.
|
||||
* The pointer is valid until the texture source is
|
||||
* destructed.
|
||||
* Should be called from the main thread.
|
||||
* Must be called from the main thread.
|
||||
*/
|
||||
virtual Palette *getPalette(const std::string &name) = 0;
|
||||
|
||||
/// @brief Check if given image name exists
|
||||
virtual bool isKnownSourceImage(const std::string &name)=0;
|
||||
|
||||
/// @brief Return average color of a texture string
|
||||
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
|
||||
};
|
||||
|
||||
|
@ -61,20 +75,19 @@ class IWritableTextureSource : public ITextureSource
|
|||
{
|
||||
public:
|
||||
IWritableTextureSource() = default;
|
||||
|
||||
virtual ~IWritableTextureSource() = default;
|
||||
|
||||
virtual u32 getTextureId(const std::string &name)=0;
|
||||
virtual std::string getTextureName(u32 id)=0;
|
||||
virtual video::ITexture* getTexture(u32 id)=0;
|
||||
virtual video::ITexture* getTexture(
|
||||
const std::string &name, u32 *id = nullptr)=0;
|
||||
virtual bool isKnownSourceImage(const std::string &name)=0;
|
||||
|
||||
/// @brief Fulfil texture requests from other threads
|
||||
virtual void processQueue()=0;
|
||||
|
||||
/**
|
||||
* @brief Inserts a source image. Must be called from the main thread.
|
||||
* Takes ownership of @p img
|
||||
*/
|
||||
virtual void insertSourceImage(const std::string &name, video::IImage *img)=0;
|
||||
|
||||
/// @brief rebuilds all textures (in case-source images have changed)
|
||||
virtual void rebuildImagesAndTextures()=0;
|
||||
virtual video::SColor getTextureAverageColor(const std::string &name)=0;
|
||||
};
|
||||
|
||||
IWritableTextureSource *createTextureSource();
|
||||
|
|
|
@ -64,7 +64,7 @@ MenuTextureSource::~MenuTextureSource()
|
|||
video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
|
||||
{
|
||||
if (id)
|
||||
*id = 0;
|
||||
*id = 1;
|
||||
|
||||
if (name.empty())
|
||||
return NULL;
|
||||
|
@ -78,7 +78,6 @@ video::ITexture *MenuTextureSource::getTexture(const std::string &name, u32 *id)
|
|||
if (!image)
|
||||
return NULL;
|
||||
|
||||
image = Align2Npot2(image, m_driver);
|
||||
retval = m_driver->addTexture(name.c_str(), image);
|
||||
image->drop();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue