diff --git a/src/client/imagefilters.cpp b/src/client/imagefilters.cpp index cd7205ff9..1277ea426 100644 --- a/src/client/imagefilters.cpp +++ b/src/client/imagefilters.cpp @@ -344,38 +344,3 @@ void imageScaleNNAA(video::IImage *src, const core::rect &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 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(width, height)); - - if (targetimage != nullptr) - image->copyToScaling(targetimage); - image->drop(); - return targetimage; -} diff --git a/src/client/imagefilters.h b/src/client/imagefilters.h index f46f71940..ff8905ba0 100644 --- a/src/client/imagefilters.h +++ b/src/client/imagefilters.h @@ -39,11 +39,3 @@ video::SColor imageAverageColor(const video::IImage *img); * and downscaling. */ void imageScaleNNAA(video::IImage *src, const core::rect &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); - diff --git a/src/client/texturesource.cpp b/src/client/texturesource.cpp index fd06fcc91..ecd5d1c74 100644 --- a/src/client/texturesource.cpp +++ b/src/client/texturesource.cpp @@ -147,7 +147,7 @@ private: // The first position contains a NULL texture. std::vector m_textureinfo_cache; // Maps a texture name to an index in the former. - std::map m_name_to_id; + std::unordered_map 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 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) { diff --git a/src/client/texturesource.h b/src/client/texturesource.h index 1297329dd..7c1a73192 100644 --- a/src/client/texturesource.h +++ b/src/client/texturesource.h @@ -25,10 +25,10 @@ class ISimpleTextureSource { public: ISimpleTextureSource() = default; - virtual ~ISimpleTextureSource() = default; - virtual video::ITexture* getTexture( + /// @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; - virtual video::ITexture* getTexture(u32 id)=0; - virtual video::ITexture* getTexture( - const std::string &name, u32 *id = nullptr)=0; - virtual video::ITexture* getTextureForMesh( + + /// @brief Returns existing texture by ID + virtual video::ITexture *getTexture(u32 id)=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; + 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(); diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 860fce665..b25214864 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -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();