Nameless Engine
Loading...
Searching...
No Matches
ne::TextureManager Class Reference

#include <TextureManager.h>

Classes

struct  TextureResource
 

Public Member Functions

 TextureManager (const TextureManager &)=delete
 
TextureManageroperator= (const TextureManager &)=delete
 
 TextureManager (GpuResourceManager *pResourceManager)
 
 ~TextureManager ()
 
size_t getTextureInMemoryCount ()
 
std::variant< std::unique_ptr< TextureHandle >, ErrorgetTexture (const std::string &sPathToResourceRelativeRes)
 

Private Member Functions

void releaseTextureResourceIfNotUsed (const std::string &sPathToResourceRelativeRes)
 
void determineTextureFormatExtension ()
 
std::unique_ptr< TextureHandlecreateNewTextureHandle (const std::string &sPathToResourceRelativeRes)
 
std::variant< std::unique_ptr< TextureHandle >, ErrorloadTextureAndCreateNewTextureHandle (const std::string &sPathToResourceRelativeRes)
 

Private Attributes

std::pair< std::recursive_mutex, std::unordered_map< std::string, TextureResource > > mtxTextureResources
 
std::string sTextureFormatExtension
 
GpuResourceManager *const pResourceManager = nullptr
 

Friends

class TextureHandle
 

Detailed Description

Controls texture loading and owns all textures.

Constructor & Destructor Documentation

◆ TextureManager()

ne::TextureManager::TextureManager ( GpuResourceManager pResourceManager)

Creates a new texture manager.

Parameters
pResourceManagerResource manager that owns this object.

◆ ~TextureManager()

ne::TextureManager::~TextureManager ( )

Makes sure that no resource is loaded in the memory.

Member Function Documentation

◆ createNewTextureHandle()

std::unique_ptr< TextureHandle > ne::TextureManager::createNewTextureHandle ( const std::string &  sPathToResourceRelativeRes)
private

Creates a new texture handle for the specified path by using mtxTextureResources.

Remarks
Increment handle counter.
Parameters
sPathToResourceRelativeResPath to texture (file/directory) relative to res directory.
Returns
New texture handle.

◆ determineTextureFormatExtension()

void ne::TextureManager::determineTextureFormatExtension ( )
private

Initializes sTextureFormatExtension depending on the current renderer.

◆ getTexture()

std::variant< std::unique_ptr< TextureHandle >, Error > ne::TextureManager::getTexture ( const std::string &  sPathToResourceRelativeRes)

Looks if the specified texture is loaded in the GPU memory or not and if not loads it in the GPU memory and returns a new handle that references this texture (if the texture is already loaded just returns a new handle).

Parameters
sPathToResourceRelativeResPath to texture (file/directory) relative to res directory.
Returns
Error if something went wrong, otherwise RAII-style object that tells the manager to not release the texture from the memory while it's being used. A texture resource will be released from the memory when no texture handle that references this path will exist. Returning std::unique_ptr so that the handle can be "moved" and "reset" and we don't need to care about implementing this functionality for the handle class.

◆ getTextureInMemoryCount()

size_t ne::TextureManager::getTextureInMemoryCount ( )

Returns the current number of textures loaded in the memory.

Returns
Textures in memory.

◆ loadTextureAndCreateNewTextureHandle()

std::variant< std::unique_ptr< TextureHandle >, Error > ne::TextureManager::loadTextureAndCreateNewTextureHandle ( const std::string &  sPathToResourceRelativeRes)
private

Loads the texture from the specified path and creates a new handle using createNewTextureHandle.

Parameters
sPathToResourceRelativeResPath to texture (file/directory) relative to res directory.
Returns
Error if something went wrong, otherwise created texture handle.

◆ releaseTextureResourceIfNotUsed()

void ne::TextureManager::releaseTextureResourceIfNotUsed ( const std::string &  sPathToResourceRelativeRes)
private

Called by texture handles in their destructor to notify the manager about a texture handle no longer referencing a texture resource so that the manager can release the texture resource if no other texture handle is referencing it.

Parameters
sPathToResourceRelativeResPath to texture (file/directory) relative to res directory.

Member Data Documentation

◆ mtxTextureResources

std::pair<std::recursive_mutex, std::unordered_map<std::string, TextureResource> > ne::TextureManager::mtxTextureResources
private

Stores pairs of "path to texture (file/directory) relative to `res` directory" - "loaded texture resource".

◆ pResourceManager

GpuResourceManager* const ne::TextureManager::pResourceManager = nullptr
private

Do not delete (free) this pointer. Resource manager that owns this object.

◆ sTextureFormatExtension

std::string ne::TextureManager::sTextureFormatExtension
private

Either ".dds" or ".ktx" depending on the current renderer.


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