void CTextureManager::DebugPrintUsedTextures( void ) { for ( int i = m_TextureList.First(); i != m_TextureList.InvalidIndex(); i = m_TextureList.Next( i ) ) { ITextureInternal *pTexture = m_TextureList[i]; Msg( "Texture: '%s' RefCount: %d\n", pTexture->GetName(), pTexture->GetReferenceCount() ); } if ( m_TextureExcludes.Count() ) { Msg( "\nExcluded Textures: (%d)\n", m_TextureExcludes.Count() ); for ( int i = m_TextureExcludes.First(); i != m_TextureExcludes.InvalidIndex(); i = m_TextureExcludes.Next( i ) ) { char buff[256]; const char *pName = m_TextureExcludes.GetElementName( i ); V_snprintf( buff, sizeof( buff ), "Excluded: %d '%s' \n", m_TextureExcludes[i], pName ); // an excluded texture is valid, but forced tiny if ( IsTextureLoaded( pName ) ) { Msg( buff ); } else { // warn as unknown, could be a spelling error Warning( buff ); } } } }
Texture * TextureManager::GetTexture(const char * a_tgaPath, TextureCategory::Enum a_cat, TextureFilter::Enum a_currentFilter) { // Texture paths are either fully qualified or relative to the config texture dir bool readFromDataPack = m_dataPack != NULL && m_dataPack->IsLoaded(); char fileNameBuf[StringUtils::s_maxCharsPerLine]; char * pathQualifier = readFromDataPack ? "\\" : ":\\"; if (!strstr(a_tgaPath, pathQualifier)) { // Strip out any leading slashes const char * filenameOnly = strstr(a_tgaPath, "\\"); if (filenameOnly != NULL) { sprintf(fileNameBuf, "%s%s", m_texturePath, filenameOnly); } else { sprintf(fileNameBuf, "%s%s", m_texturePath, a_tgaPath); } } else // Already fully qualified { sprintf(fileNameBuf, "%s", a_tgaPath); } // Get the identifier for the new texture StringHash texHash(fileNameBuf); unsigned int texId = texHash.GetHash(); TextureCategory::Enum loadedCat = IsTextureLoaded(texId); // If it already exists if (loadedCat != TextureCategory::None) { // Just returned the cached copy ManagedTexture * foundTex = NULL; m_textureMap[loadedCat].Get(texId, foundTex); return &foundTex->m_texture; } else if (ManagedTexture * newTex = m_texturePool[a_cat].Allocate(sizeof(ManagedTexture))) { // If the filter is not specified, use the default if (a_currentFilter == TextureFilter::Invalid) { a_currentFilter = m_filterMode; } // If loading from a datapack if (readFromDataPack) { // Insert the newly allocated texture if (DataPackEntry * packedTexture = m_dataPack->GetEntry(fileNameBuf)) { if (newTex->m_texture.LoadFromMemory((void *)packedTexture->m_data, packedTexture->m_size, a_currentFilter == TextureFilter::Linear)) { sprintf(newTex->m_path, "%s", fileNameBuf); m_textureMap[a_cat].Insert(texId, newTex); return &newTex->m_texture; } else { Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Texture load from pack failed for %s", fileNameBuf); return NULL; } } else { Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Texture load from pack failed for %s", fileNameBuf); return NULL; } } else { // Insert the newly allocated texture if (newTex->m_texture.LoadFromFile(fileNameBuf, a_currentFilter == TextureFilter::Linear)) { FileManager::Get().GetFileTimeStamp(fileNameBuf, newTex->m_timeStamp); sprintf(newTex->m_path, "%s", fileNameBuf); m_textureMap[a_cat].Insert(texId, newTex); return &newTex->m_texture; } else { Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Texture load from disk failed for %s", fileNameBuf); return NULL; } } } else // Report the error { Log::Get().Write(LogLevel::Error, LogCategory::Engine, "Texture allocation failed for %s", fileNameBuf); return NULL; } return NULL; }