lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::assets::TextureLibrary Class Reference

Manages loading and caching of textures. More...

#include <texture_library.hpp>

Public Member Functions

std::shared_ptr< renderer::Textureload (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::Textureget (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 TextureLibraryget_instance ()
 Get the singleton instance of the TextureLibrary.
 

Detailed Description

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.

Member Function Documentation

◆ clear()

void lmgl::assets::TextureLibrary::clear ( )

Clear the texture cache.

Removes all cached textures from the library.

◆ exists()

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.

Parameters
pathThe file path of the texture
Returns
True if the texture is cached, false otherwise

◆ get()

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.

Parameters
pathThe file path of the texture
Returns
Shared pointer to the cached texture, or nullptr if not found

◆ get_instance()

TextureLibrary & lmgl::assets::TextureLibrary::get_instance ( )
static

Get the singleton instance of the TextureLibrary.

Returns
Reference to the TextureLibrary instance

◆ load()

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.

Parameters
pathThe file path of the texture
srgbWhether to load the texture in sRGB color space
Returns
Shared pointer to the loaded texture

◆ size()

size_t lmgl::assets::TextureLibrary::size ( ) const
inline

Get the number of cached textures.

Returns the total number of textures currently stored in the cache.

Returns
The size of the texture cache

The documentation for this class was generated from the following files: