blob: 9b1061c45cadc4d7881622dc9a577e74d9334857 (
plain)
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
|
#pragma once
#include "Configuration/UnityConfigure.h"
#include "Runtime/Utilities/dense_hash_map.h"
#include "Runtime/Utilities/LogAssert.h"
#include "Runtime/GfxDevice/GfxDeviceConfigure.h"
#include "Runtime/GfxDevice/GfxDeviceTypes.h"
class
TextureIdMap
{
public:
static void Initialize();
static void Uninitialize();
static void UpdateTexture(TextureID texid, intptr_t nativeTex);
static void RemoveTexture(TextureID texid);
static intptr_t QueryNativeTexture(TextureID texid);
private:
struct TextureIDHashFunctor
{
inline size_t operator()(TextureID x) const
{
UInt32 a = x.m_ID;
a = (a+0x7ed55d16) + (a<<12);
a = (a^0xc761c23c) ^ (a>>19);
a = (a+0x165667b1) + (a<<5);
a = (a+0xd3a2646c) ^ (a<<9);
a = (a+0xfd7046c5) + (a<<3);
a = (a^0xb55a4f09) ^ (a>>16);
return a;
}
};
typedef pair<const TextureID, intptr_t> TextureIdToTexturePair;
typedef dense_hash_map< TextureID, intptr_t, TextureIDHashFunctor, std::equal_to<TextureID>, STL_ALLOCATOR(kMemSTL, TextureIdToTexturePair) > TextureMap;
static TextureMap s_Textures;
// some devices call OnCreate twice - easier to workaround here
static bool s_Inited;
};
inline void TextureIdMap::UpdateTexture(TextureID texid, intptr_t nativeTex)
{
TextureMap::iterator it = s_Textures.find(texid);
if(it != s_Textures.end())
it->second = nativeTex;
else
s_Textures.insert(std::make_pair(texid, nativeTex));
}
inline void TextureIdMap::RemoveTexture(TextureID texid)
{
s_Textures.erase(texid);
}
inline intptr_t TextureIdMap::QueryNativeTexture(TextureID texid)
{
TextureMap::iterator it = s_Textures.find(texid);
return it == s_Textures.end() ? 0 : it->second;
}
|