-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextureManager.hpp
More file actions
95 lines (74 loc) · 2.33 KB
/
TextureManager.hpp
File metadata and controls
95 lines (74 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#pragma once
#ifndef Texture_MANAGER_H_
#define Texture_MANAGER_H_
#include "Texture.h"
#include <string>
#include <unordered_map>
#include "IO.h"
#define _ERROR_Texture "./rcs/_EngineGui/#HIDE#InvisibleRsources/Engine_AssetGUI_Grey_Texture.jpg"
namespace Engine
{
class TextureManager
{
public:
//Methods-------------------------------------
static TextureManager* Instance() {
static TextureManager* instance;
if (!instance)
instance = new TextureManager();
return instance;
}
void Init(bool loadTextures = false) {
std::vector< std::pair<std::string, std::string>>* textures = IO::getTexturesPaths();
for (std::pair<std::string, std::string> texturePath : *(textures))
AddTexture(texturePath.first, texturePath.second, loadTextures);
}
void AddTexture(const std::string& textureName, const std::string& texturePath, bool loadTexture = false) {
texturesPath[textureName] = texturePath;
if (loadTexture)
textures[textureName] = new Texture_Asset(texturesPath[textureName].c_str());//load texture
}
Texture_Asset* getTexture(const std::string& textureName, bool flipY = false) {
if (textures.find(textureName) == textures.end())
{//Texture not found
//Trying to load the texture
if (texturesPath.find(textureName) == texturesPath.end()) {
//texture path not found
log_error("ERROR::TEXTURE_MANAGER::Texture file not found.");
texturesPath[textureName] = _ERROR_Texture;
return nullptr;
}
else {
//Loading texture
textures[textureName] = new Texture_Asset(texturesPath[textureName].c_str(), GL_RGB, flipY);
textures[textureName]->assetName = textureName;
}
}
return textures[textureName];
}
auto Begin() {
return textures.begin();
}
auto End() {
return textures.end();
}
auto BeginP() {
return texturesPath.begin();
}
auto EndP() {
return texturesPath.end();
}
//Variables-----------------------------------
private:
//Methods-------------------------------------
TextureManager(){
}
TextureManager(TextureManager const&) = delete;
TextureManager& operator=(TextureManager const&) = delete;
~TextureManager() {};
//Variables-----------------------------------
std::unordered_map<std::string, std::string> texturesPath;
std::unordered_map<std::string, Texture_Asset*> textures;
};
}
#endif