mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-11 20:35:25 +01:00
Refactor texture source to prepare for array textures
This commit is contained in:
@@ -18,7 +18,15 @@ namespace video
|
||||
typedef std::vector<video::SColor> Palette;
|
||||
|
||||
/*
|
||||
TextureSource creates and caches textures.
|
||||
TextureSource creates and caches textures, which are created from images.
|
||||
|
||||
Terminology:
|
||||
texture string = e.g. "dirt.png^grass_side.png"
|
||||
texture name = can be the same as the texture string
|
||||
or something abstract like "<texture12>"
|
||||
texture ID = unique numeric identifier for a texture
|
||||
standard texture = refers to a normal 2D texture as you would expect.
|
||||
depending on the support, 2D array textures can exist too.
|
||||
*/
|
||||
|
||||
class ISimpleTextureSource
|
||||
@@ -27,7 +35,7 @@ public:
|
||||
ISimpleTextureSource() = default;
|
||||
virtual ~ISimpleTextureSource() = default;
|
||||
|
||||
/// @brief Generates and gets a texture
|
||||
/// @brief Generates a texture string into a standard texture
|
||||
virtual video::ITexture *getTexture(
|
||||
const std::string &name, u32 *id = nullptr) = 0;
|
||||
};
|
||||
@@ -40,35 +48,50 @@ public:
|
||||
|
||||
using ISimpleTextureSource::getTexture;
|
||||
|
||||
/// @brief Generates and gets ID of a texture
|
||||
virtual u32 getTextureId(const std::string &name)=0;
|
||||
/// @brief Generates a texture string into a standard texture
|
||||
/// @return its ID
|
||||
virtual u32 getTextureId(const std::string &image)=0;
|
||||
|
||||
/// @brief Returns name of existing texture by ID
|
||||
/// @warning Use sparingly. Mostly useful for debugging.
|
||||
virtual std::string getTextureName(u32 id)=0;
|
||||
|
||||
/// @brief Returns existing texture by ID
|
||||
virtual video::ITexture *getTexture(u32 id)=0;
|
||||
|
||||
/// @return true if getTextureForMesh will apply a filter
|
||||
virtual bool needFilterForMesh() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Generates and gets a texture
|
||||
* @brief Generates a texture string into a standard texture
|
||||
* Filters will be applied to make the texture suitable for mipmapping and
|
||||
* linear filtering during rendering.
|
||||
* @return its ID
|
||||
*/
|
||||
virtual video::ITexture *getTextureForMesh(
|
||||
const std::string &name, u32 *id = nullptr) = 0;
|
||||
inline video::ITexture *getTextureForMesh(
|
||||
const std::string &image, u32 *id = nullptr)
|
||||
{
|
||||
if (needFilterForMesh() && !image.empty())
|
||||
return getTexture(image + FILTER_FOR_MESH, id);
|
||||
return getTexture(image, id);
|
||||
}
|
||||
|
||||
/// Filter needed for mesh-suitable textures, including leading ^
|
||||
static constexpr const char *FILTER_FOR_MESH = "^[applyfiltersformesh";
|
||||
|
||||
/**
|
||||
* Returns a palette from the given texture name.
|
||||
* Returns a palette from the given texture string.
|
||||
* The pointer is valid until the texture source is
|
||||
* destructed.
|
||||
* Must be called from the main thread.
|
||||
*/
|
||||
virtual Palette *getPalette(const std::string &name) = 0;
|
||||
virtual Palette *getPalette(const std::string &image) = 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;
|
||||
virtual video::SColor getTextureAverageColor(const std::string &image)=0;
|
||||
|
||||
// Note: this method is here because caching is the decision of the
|
||||
// API user, even if his access is read-only.
|
||||
|
||||
Reference in New Issue
Block a user