If already in table, return cached copy Otherwise, create surfaces, and load texture into memory
| 167 | // If already in table, return cached copy |
| 168 | // Otherwise, create surfaces, and load texture into memory |
| 169 | CachedTexture * CTextureCache::GetOrCreateCachedTexture(const TextureInfo & ti) |
| 170 | { |
| 171 | #ifdef DAEDALUS_ENABLE_PROFILING |
| 172 | DAEDALUS_PROFILE( "CTextureCache::GetOrCreateCachedTexture" ); |
| 173 | #endif |
| 174 | // NB: this is a no-op in normal builds. |
| 175 | MutexLock lock(GetDebugMutex()); |
| 176 | |
| 177 | // |
| 178 | // Retrieve the texture from the cache (if it already exists) |
| 179 | // |
| 180 | u32 ixa {MakeHashIdxA( ti )}; |
| 181 | if( mpCacheHashTable[ixa] && mpCacheHashTable[ixa]->GetTextureInfo() == ti ) |
| 182 | { |
| 183 | RECORD_CACHE_HIT( 1, 0 ); |
| 184 | mpCacheHashTable[ixa]->UpdateIfNecessary(); |
| 185 | |
| 186 | return mpCacheHashTable[ixa]; |
| 187 | } |
| 188 | |
| 189 | u32 ixb {MakeHashIdxB( ti )}; |
| 190 | if( mpCacheHashTable[ixb] && mpCacheHashTable[ixb]->GetTextureInfo() == ti ) |
| 191 | { |
| 192 | RECORD_CACHE_HIT( 1, 0 ); |
| 193 | mpCacheHashTable[ixb]->UpdateIfNecessary(); |
| 194 | |
| 195 | return mpCacheHashTable[ixb]; |
| 196 | } |
| 197 | |
| 198 | CachedTexture * texture = nullptr; |
| 199 | TextureVec::iterator it = std::lower_bound( mTextures.begin(), mTextures.end(), ti, SSortTextureEntries() ); |
| 200 | if( it != mTextures.end() && (*it)->GetTextureInfo() == ti ) |
| 201 | { |
| 202 | texture = *it; |
| 203 | RECORD_CACHE_HIT( 0, 1 ); |
| 204 | } |
| 205 | else |
| 206 | { |
| 207 | texture = CachedTexture::Create( ti ); |
| 208 | if (texture != nullptr) |
| 209 | { |
| 210 | mTextures.insert( it, texture ); |
| 211 | } |
| 212 | |
| 213 | RECORD_CACHE_HIT( 0, 0 ); |
| 214 | } |
| 215 | |
| 216 | // Update the hashtable |
| 217 | if( texture ) |
| 218 | { |
| 219 | texture->UpdateIfNecessary(); |
| 220 | |
| 221 | mpCacheHashTable[ixa] = texture; |
| 222 | mpCacheHashTable[ixb] = texture; |
| 223 | } |
| 224 | |
| 225 | return texture; |
| 226 | } |
nothing calls this directly
no test coverage detected