+// Enum!
+
+enum TextureCacheIndexType
+{
+ TEXTURE_CACHE_INDEX_FREE_LIST = 0, ///< Only for FreeList. We should not use this for TextureCacheIndex.
+ TEXTURE_CACHE_INDEX_TYPE_LOCAL = 1,
+ TEXTURE_CACHE_INDEX_TYPE_TEXTURE,
+ TEXTURE_CACHE_INDEX_TYPE_BUFFER,
+ TEXTURE_CACHE_INDEX_TYPE_MASKING, ///< Not implemented yet.
+ TEXTURE_CACHE_INDEX_TYPE_MAX = 7, ///< Maximum number of cache type we can use.
+};
+
+// Union!
+
+/**
+ * @brief standard union type of texture index.
+ * Due to the FreeList can only use for uint32_t and we need to seperate
+ * each index per container type, we can only hold maximum 2^28 textures
+ * at the same time.
+ * 0 ~ 2^28 - 1 : index of FreeList. TextureCacheManager will not use it.
+ * 2^28 ~ 2*2^28 - 1 : index of mTextureInfoContainer, the main texture container.
+ * 2*2^28 ~ 3*2^28 - 1 : index of mExternalTextures.
+ * 3*2^28 ~ 4*2^28 - 1 : index of mEncodedBufferTextures.
+ */
+union TextureCacheIndexData
+{
+ TextureCacheIndexData() = default;
+ constexpr TextureCacheIndexData(const uint32_t index)
+ : indexValue(index)
+ {
+ }
+ constexpr explicit TextureCacheIndexData(const int32_t index)
+ : indexValue(static_cast<uint32_t>(index))
+ {
+ }
+ constexpr TextureCacheIndexData(const TextureCacheIndexType& type, const uint32_t index)
+ : detailValue{index, type}
+ {
+ }
+ constexpr TextureCacheIndexData(const TextureCacheIndexData& indexData)
+ : indexValue(indexData.indexValue)
+ {
+ }
+ constexpr TextureCacheIndexData(TextureCacheIndexData&& indexData)
+ : indexValue(indexData.indexValue)
+ {
+ }
+
+ TextureCacheIndexData& operator=(const uint32_t index)
+ {
+ indexValue = index;
+ return *this;
+ }
+ TextureCacheIndexData& operator=(const TextureCacheIndexData& rhs)
+ {
+ indexValue = rhs.indexValue;
+ return *this;
+ }
+ TextureCacheIndexData& operator=(TextureCacheIndexData&& rhs)
+ {
+ indexValue = rhs.indexValue;
+ return *this;
+ }
+
+ constexpr operator uint32_t() const
+ {
+ return indexValue;
+ }
+ constexpr operator uint32_t()
+ {
+ return indexValue;
+ }
+ constexpr explicit operator int32_t() const
+ {
+ return static_cast<int32_t>(indexValue);
+ }
+ constexpr explicit operator int32_t()
+ {
+ return static_cast<int32_t>(indexValue);
+ }
+
+ // Return detailValue.index. - the real index of datailValue.type container
+ constexpr inline uint32_t GetIndex() const
+ {
+ return detailValue.index;
+ }
+
+ inline constexpr bool operator==(const TextureCacheIndexData& rhs)
+ {
+ return indexValue == rhs.indexValue;
+ }
+ inline constexpr bool operator<(const TextureCacheIndexData& rhs)
+ {
+ return indexValue < rhs.indexValue;
+ }
+
+ // Data area
+ uint32_t indexValue;
+ struct
+ {
+ unsigned int index : 28;
+ TextureCacheIndexType type : 4;
+ } detailValue;
+};
+