-
Notifications
You must be signed in to change notification settings - Fork 0
/
textureManager.cpp
75 lines (62 loc) · 1.52 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "textureManager.h"
//constructor
TextureManager::TextureManager()
{
// texture = NULL;
// iTexture = NULL;
//textureMapSRV = NULL;
//width = 0;
//height = 0;
//file = NULL;
graphics = NULL;
initialized = false;
}
//destructor
TextureManager::~TextureManager()
{
//textureMapSRV->Release();
}
//load texture
ID3D11ShaderResourceView *TextureManager::loadTexture(const wchar_t *f)
{
std::wostringstream toConvert;
toConvert << f;
const std::wstring fileName(toConvert.str());
textureIterator = textureTable.find(fileName);
//if texture isn't loaded
if (textureIterator == textureTable.end())
{
sTexture *temp = new sTexture;
temp->textureMapSRV = graphics->createTextureSRV(f);
textureTable.emplace(fileName, *temp);
return temp->textureMapSRV;
}
else
return textureIterator->second.textureMapSRV;
}
void TextureManager::initialize(Graphics *graph)
{
graphics = graph;
//load and confirm texture
// hr = D3DX11CreateShaderResourceViewFromFile(graphics->getDevice(), file, 0, 0, &textureMapSRV, 0);
// if (FAILED(hr))
// throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating texture resource."));
//textureMapSRV = graphics->createTextureSRV(file);
//get texture dimensions
initialized = true;
}
//dump texture if graphics device lost
void TextureManager::onLostDevice()
{
if(!initialized)
return;
// safeRelease(texture);
// safeRelease(iTexture);
}
//load texture on device reset
void TextureManager::onResetDevice()
{
if(!initialized)
return;
// graphics->loadTexture(file);
}