| 428 | } |
| 429 | |
| 430 | bool Tr2FontManager::GetAtlasTextureForSbit( FTC_SBit sbit, Tr2AtlasTexture** at ) |
| 431 | { |
| 432 | auto foundItInUse = m_sbitToTextureMap.find( sbit ); |
| 433 | if( foundItInUse != m_sbitToTextureMap.end() ) |
| 434 | { |
| 435 | // CCP_LOG( __FUNCTION__ " found sbit (%d in map)", m_sbitToTextureMap.size() ); |
| 436 | |
| 437 | IWeakObject* weakObj = foundItInUse->second; |
| 438 | weakObj->QueryInterface( BlueInterfaceIID<Tr2AtlasTexture>(), (void**)at ); |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | auto foundItInCache = m_sbitToCachedTextureMap.find( sbit ); |
| 443 | if( foundItInCache != m_sbitToCachedTextureMap.end() ) |
| 444 | { |
| 445 | // CCP_LOG( __FUNCTION__ " found sbit in cache (%d in cache)", m_sbitToCachedTextureMap.size() ); |
| 446 | |
| 447 | FTC_SBit sbit = foundItInCache->first; |
| 448 | GlyphCacheEntry& entry = foundItInCache->second; |
| 449 | IWeakObject* weakObj = entry.glyphObject; |
| 450 | m_totalGlyphsCachedSize -= entry.memoryUsage; |
| 451 | |
| 452 | // Move it from the cache to the main map |
| 453 | m_sbitToCachedTextureMap.erase( foundItInCache ); |
| 454 | |
| 455 | // entry is no longer valid - do not reference it below |
| 456 | |
| 457 | m_sbitToTextureMap[sbit] = weakObj; |
| 458 | m_textureToSbitMap[weakObj] = sbit; |
| 459 | |
| 460 | // Register it for future about-to-die notifications. |
| 461 | weakObj->WeakRefRegister( this ); |
| 462 | weakObj->QueryInterface( BlueInterfaceIID<Tr2AtlasTexture>(), (void**)at ); |
| 463 | |
| 464 | // Drop the strong reference the cached map used to hold. |
| 465 | weakObj->Unlock(); |
| 466 | return true; |
| 467 | } |
| 468 | |
| 469 | // First time we see this sbit - create an atlas texture and copy the pixels over |
| 470 | *at = nullptr; |
| 471 | |
| 472 | Tr2TextureAtlas* atlas = g_textureAtlasMan->FindAtlas( PIXEL_FORMAT_B8G8R8A8_UNORM ); |
| 473 | if( !atlas ) |
| 474 | { |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | // We add one pixel to allow for potential drop-shadow |
| 479 | |
| 480 | Tr2AtlasTexturePtr tex; |
| 481 | ALResult al = atlas->CreateTexture( sbit->width, sbit->height + 1, Tr2TextureAtlas::ATT_DEFAULT, &tex ); |
| 482 | if( !tex ) |
| 483 | { |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | void* pDest; |
no test coverage detected