|
lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
|
Manages loading and caching of textures. More...
#include <texture_library.hpp>
Public Member Functions | |
| std::shared_ptr< renderer::Texture > | load (const std::string &fpath) |
| Load a texture from a file path. | |
| bool | exists (const std::string &fpath) const |
| Check if a texture exists in the cache. | |
| std::shared_ptr< renderer::Texture > | get (const std::string &fpath) const |
| Retrieve a cached texture. | |
| void | clear () |
| Clear the texture cache. | |
| size_t | size () const |
| Get the number of cached textures. | |
Static Public Member Functions | |
| static TextureLibrary & | get_instance () |
| Get the singleton instance of the TextureLibrary. | |
Manages loading and caching of textures.
The TextureLibrary class provides methods to load textures from files, check for their existence in the cache, retrieve cached textures, and clear the cache. It uses a singleton pattern to ensure a single instance throughout the application.
| void lmgl::assets::TextureLibrary::clear | ( | ) |
Clear the texture cache.
Removes all cached textures from the library.
| bool lmgl::assets::TextureLibrary::exists | ( | const std::string & | fpath | ) | const |
Check if a texture exists in the cache.
Checks if the texture corresponding to the given file path is already loaded and cached.
| path | The file path of the texture |
| std::shared_ptr< renderer::Texture > lmgl::assets::TextureLibrary::get | ( | const std::string & | fpath | ) | const |
Retrieve a cached texture.
Retrieves the texture corresponding to the given file path from the cache. Returns nullptr if the texture is not found.
| path | The file path of the texture |
|
static |
Get the singleton instance of the TextureLibrary.
| std::shared_ptr< renderer::Texture > lmgl::assets::TextureLibrary::load | ( | const std::string & | fpath | ) |
Load a texture from a file path.
If the texture has already been loaded, it returns the cached version.
| path | The file path of the texture |
| srgb | Whether to load the texture in sRGB color space |
|
inline |
Get the number of cached textures.
Returns the total number of textures currently stored in the cache.