Nameless Engine
Loading...
Searching...
No Matches
TextureManager.h
1#pragma once
2
3// Standard.
4#include <unordered_map>
5#include <string>
6#include <mutex>
7#include <memory>
8#include <variant>
9
10// Custom.
11#include "misc/Error.h"
12#include "render/general/resource/GpuResource.h"
13#include "material/TextureHandle.h"
14
15namespace ne {
16 class TextureManager;
17 class GpuResourceManager;
18
21 // Texture handles will notify texture manager in destructor to mark referenced texture resource
22 // as not used so that texture manager can release the texture resource from memory
23 // if no texture handle is referencing it.
24 friend class TextureHandle;
25
26 public:
27 TextureManager(const TextureManager&) = delete;
28 TextureManager& operator=(const TextureManager&) = delete;
29
30 TextureManager() = delete;
31
38
41
48
62 std::variant<std::unique_ptr<TextureHandle>, Error>
63 getTexture(const std::string& sPathToResourceRelativeRes);
64
65 private:
69 std::unique_ptr<GpuResource> pTexture;
70
73 };
74
82 void releaseTextureResourceIfNotUsed(const std::string& sPathToResourceRelativeRes);
83
86
96 std::unique_ptr<TextureHandle> createNewTextureHandle(const std::string& sPathToResourceRelativeRes);
97
106 std::variant<std::unique_ptr<TextureHandle>, Error>
107 loadTextureAndCreateNewTextureHandle(const std::string& sPathToResourceRelativeRes);
108
113 std::pair<std::recursive_mutex, std::unordered_map<std::string, TextureResource>> mtxTextureResources;
114
117
120 };
121}
Definition: Error.h:27
Definition: GpuResourceManager.h:43
Definition: TextureHandle.h:15
Definition: TextureManager.h:20
std::pair< std::recursive_mutex, std::unordered_map< std::string, TextureResource > > mtxTextureResources
Definition: TextureManager.h:113
std::variant< std::unique_ptr< TextureHandle >, Error > loadTextureAndCreateNewTextureHandle(const std::string &sPathToResourceRelativeRes)
Definition: TextureManager.cpp:161
size_t getTextureInMemoryCount()
Definition: TextureManager.cpp:48
~TextureManager()
Definition: TextureManager.cpp:22
GpuResourceManager *const pResourceManager
Definition: TextureManager.h:119
std::string sTextureFormatExtension
Definition: TextureManager.h:116
std::variant< std::unique_ptr< TextureHandle >, Error > getTexture(const std::string &sPathToResourceRelativeRes)
Definition: TextureManager.cpp:55
std::unique_ptr< TextureHandle > createNewTextureHandle(const std::string &sPathToResourceRelativeRes)
Definition: TextureManager.cpp:129
void determineTextureFormatExtension()
Definition: TextureManager.cpp:120
void releaseTextureResourceIfNotUsed(const std::string &sPathToResourceRelativeRes)
Definition: TextureManager.cpp:77
Definition: TextureManager.h:67
std::unique_ptr< GpuResource > pTexture
Definition: TextureManager.h:69
size_t iActiveTextureHandleCount
Definition: TextureManager.h:72