summaryrefslogtreecommitdiff
path: root/Runtime/GfxDevice/TextureIdMap.h
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/GfxDevice/TextureIdMap.h
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/GfxDevice/TextureIdMap.h')
-rw-r--r--Runtime/GfxDevice/TextureIdMap.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/Runtime/GfxDevice/TextureIdMap.h b/Runtime/GfxDevice/TextureIdMap.h
new file mode 100644
index 0000000..9b1061c
--- /dev/null
+++ b/Runtime/GfxDevice/TextureIdMap.h
@@ -0,0 +1,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;
+}