-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXTextureManager.h
86 lines (68 loc) · 1.96 KB
/
XTextureManager.h
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
#pragma once
#include "HelperFunctions.h"
#include "XD3D.h"
#include "Singleton.h"
#include <d3d11.h>
#include <DirectXMath.h>
#include <D3DX10math.h>
#include <D3DX11async.h>
struct XTextureContainer
{
ID3D11ShaderResourceView* pTexture;
bool isLightmap;
};
class XTextureManager : public Singleton<XTextureManager>
{
protected:
std::unordered_map<std::string, XTextureContainer*> m_textures;
std::vector<XTextureContainer*> m_lightmaps;
ID3D11SamplerState* m_pSampleState;
XD3DRenderer* m_pD3D;
int m_numTextures;
int m_numLightmaps;
public:
XTextureManager() { }
XTextureManager(XD3DRenderer* pD3D)
{
m_pD3D = pD3D;
m_numTextures = 0;
m_numLightmaps = 0;
}
void UnloadTextures(void)
{
for (auto i : m_textures)
i.second->pTexture->Release();
for (auto i : m_lightmaps)
i->pTexture->Release();
m_numTextures = m_numLightmaps = 0;
}
~XTextureManager()
{
UnloadTextures();
}
int GetNumTextures() {
return m_numTextures;
}
bool GetTextureData(const std::string name, unsigned char** pData, unsigned int& width, unsigned int& height, unsigned int& rowPitch);
int GetNumLightmaps() {
return m_numLightmaps;
}
ID3D11ShaderResourceView* GetTexture(const std::string& name) {
// assert(m_textures[name]);
if (m_textures[name] == nullptr)
return nullptr;
return m_textures[name]->pTexture;
}
ID3D11ShaderResourceView* GetLightmap(int id) {
assert(m_lightmaps[id]);
return m_lightmaps[id]->pTexture;
}
ID3D11SamplerState* GetSamplerState() {
return m_pSampleState;
}
bool CreateTexture(unsigned char* imgData, const std::string& name, unsigned int height, unsigned int width, bool isLightmap);
bool CreateWhiteTexture(int, int, bool);
bool Load(const std::string& filePath, const std::string& name, bool isLightmap);
bool Save(const std::string& filePath, const std::string& name);
bool CreateSamplerState();
};