This repository was archived by the owner on Feb 19, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
Expand file tree
/
Copy pathTextureManager.cpp
More file actions
executable file
·97 lines (83 loc) · 1.88 KB
/
TextureManager.cpp
File metadata and controls
executable file
·97 lines (83 loc) · 1.88 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
95
96
97
#include "TextureManager.h"
#include "../Logger.h"
#include "../Context.h"
#include "Texture2D.h"
#ifdef ANDROID
#include "../StarEngine.h"
#endif
namespace star
{
TextureManager::~TextureManager()
{
m_TextureMap.clear();
m_PathList.clear();
}
TextureManager::TextureManager(void)
: m_TextureMap()
, m_PathList()
{
}
void TextureManager::LoadTexture(const tstring& path, const tstring& name)
{
if(m_TextureMap.find(name) != m_TextureMap.end())
{
return;
}
auto pathit = m_PathList.find(path);
if(pathit != m_PathList.end())
{
tstring nameOld = pathit->second;
auto nameit = m_TextureMap.find(nameOld);
if(nameit != m_TextureMap.end())
{
m_TextureMap[name] = nameit->second;
return;
}
m_PathList.erase(pathit);
return;
}
m_TextureMap[name] = std::make_shared<Texture2D>(path);
m_PathList[path] = name;
}
bool TextureManager::DeleteTexture(const tstring& name)
{
auto it = m_TextureMap.find(name);
if(it != m_TextureMap.end())
{
m_TextureMap.erase(it);
return true;
}
return false;
}
GLuint TextureManager::GetTextureID(const tstring& name)
{
if(m_TextureMap.find(name) != m_TextureMap.end())
{
return m_TextureMap[name]->GetTextureID();
}
return 0;
}
ivec2 TextureManager::GetTextureDimensions(const tstring& name)
{
auto it = m_TextureMap.find(name);
if(it != m_TextureMap.end())
{
return (ivec2(it->second->GetWidth(), it->second->GetHeight()));
}
return ivec2(0,0);
}
void TextureManager::EraseAllTextures()
{
m_TextureMap.clear();
m_PathList.clear();
}
bool TextureManager::ReloadAllTextures()
{
m_TextureMap.clear();
for(auto it = m_PathList.begin(); it != m_PathList.end(); ++it)
{
m_TextureMap[it->second] = std::make_shared<Texture2D>(it->first);
}
return true;
}
}