-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextureManager.cpp
54 lines (49 loc) · 1.26 KB
/
TextureManager.cpp
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
#include "TextureManager.h"
#include "RenderDevice.h"
#include "Texture.h"
#include "stdafx.h"
#include "typeDefs3D.h"
D3DTexture* TextureManager::LoadTexture(BaseTexture* memtex, const bool linearRGB)
{
const Iter it = m_map.find(memtex);
if (it == m_map.end())
{
TexInfo texinfo;
texinfo.d3dtex = m_rd.UploadTexture(memtex, &texinfo.texWidth, &texinfo.texHeight, linearRGB);
if (!texinfo.d3dtex)
return 0;
texinfo.dirty = false;
m_map[memtex] = texinfo;
return texinfo.d3dtex;
}
else
{
if (it->second.dirty)
{
m_rd.UpdateTexture(it->second.d3dtex, memtex, linearRGB);
it->second.dirty = false;
}
return it->second.d3dtex;
}
}
void TextureManager::SetDirty(BaseTexture* memtex)
{
const Iter it = m_map.find(memtex);
if (it != m_map.end())
it->second.dirty = true;
}
void TextureManager::UnloadTexture(BaseTexture* memtex)
{
const Iter it = m_map.find(memtex);
if (it != m_map.end())
{
SAFE_RELEASE(it->second.d3dtex);
m_map.erase(it);
}
}
void TextureManager::UnloadAll()
{
for (Iter it = m_map.begin(); it != m_map.end(); ++it)
SAFE_RELEASE(it->second.d3dtex);
m_map.clear();
}