MochiEngine
Loading...
Searching...
No Matches
Mochi::Graphics::AbstractTextureFactory Class Referenceabstract

This class must be inherited to generate textures of a compatible type with its own renderer. More...

#include <AbstractTextureFactory.h>

Inheritance diagram for Mochi::Graphics::AbstractTextureFactory:
Mochi::Graphics::DummyTextureFactory Mochi::Graphics::SDLTextureFactory

Public Member Functions

std::shared_ptr< ITextureGetTexture (const std::string &texturePath)
 Gets the texture on the specified path on the file system. If the texture is in the cache it returns that one, otherwise it loads the texture from the system.
void DeleteCache ()
 Deletes the texture cache from the factory.
void DeleteTexture (const std::string &texturePath)
 Deletes a single texture from the cache.

Protected Member Functions

virtual std::shared_ptr< ITextureLoadTexture (const std::string &texturePath)=0
 Implement this method to actually load the selected texture from memory onto a format that is compatible with the current renderer.

Protected Attributes

std::unordered_map< std::string, std::shared_ptr< ITexture > > mTexturesMap

Detailed Description

This class must be inherited to generate textures of a compatible type with its own renderer.

Ownership:

  • It maintains a cache of the loaded textures as a map.
  • Clearing the cache is safe anytime, as all the created textures are shared pointers and will only be destroyed when all references are lost.

Guarantees:

  • Valid textures will be only loaded once.
  • Cache will priorize loading from the file system.
  • Deleting a texture or the full cache is safe

Member Function Documentation

◆ DeleteCache()

void Mochi::Graphics::AbstractTextureFactory::DeleteCache ( )

Deletes the texture cache from the factory.

Clears the textures map, releasing all textures that don't have a reference in any other place. Is safe to call whenever.

◆ DeleteTexture()

void Mochi::Graphics::AbstractTextureFactory::DeleteTexture ( const std::string & texturePath)

Deletes a single texture from the cache.

Removes a texture from the cache, releasing it if it doesn't have any reference in any other place. Is safe to call whenever.

Parameters
texturePathThe texture to remove from the cache.
texturePathPath to the texture inside the catalog.

◆ GetTexture()

std::shared_ptr< ITexture > Mochi::Graphics::AbstractTextureFactory::GetTexture ( const std::string & texturePath)

Gets the texture on the specified path on the file system. If the texture is in the cache it returns that one, otherwise it loads the texture from the system.

Parameters
texturePathThe path or unique identifier.
Returns
A shared pointer to the texture.

◆ LoadTexture()

virtual std::shared_ptr< ITexture > Mochi::Graphics::AbstractTextureFactory::LoadTexture ( const std::string & texturePath)
protectedpure virtual

Implement this method to actually load the selected texture from memory onto a format that is compatible with the current renderer.

Parameters
texturePathThe path of the texture in the virtual file system.
Returns
A shared pointer to the texture.

Implemented in Mochi::Graphics::DummyTextureFactory, and Mochi::Graphics::SDLTextureFactory.


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