MaterialDefinition* MaterialManager::FindMaterial(ShaderGroup* m_pShaderGroup, TextureDefinition* pTextureColor) { for( CPPListNode* pNode = m_MaterialsStillLoading.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; if( pMaterial->m_pShaderGroup == m_pShaderGroup && pMaterial->m_pTextureColor == pTextureColor ) { return pMaterial; } } for( CPPListNode* pNode = m_Materials.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; if( pMaterial->m_pShaderGroup == m_pShaderGroup && pMaterial->m_pTextureColor == pTextureColor ) { return pMaterial; } } return 0; }
void TextureManager::InvalidateAllTextures(bool cleanglallocs) { for( CPPListNode* pNode = m_LoadedTextures.GetHead(); pNode; ) { TextureDefinition* pTextureDef = (TextureDefinition*)pNode; pNode = pNode->GetNext(); pTextureDef->Invalidate(cleanglallocs); m_TexturesStillLoading.MoveTail( pTextureDef ); pTextureDef->m_FullyLoaded = false; } for( CPPListNode* pNode = m_InitializedFBOs.GetHead(); pNode; ) { FBODefinition* pFBODef = (FBODefinition*)pNode; pNode = pNode->GetNext(); pFBODef->Invalidate(cleanglallocs); m_UninitializedFBOs.MoveTail( pFBODef ); pFBODef->m_FullyLoaded = false; } }
TextureDefinition* TextureManager::FindTexture(const char* texturefilename) { for( CPPListNode* pNode = m_LoadedTextures.GetHead(); pNode; pNode = pNode->GetNext() ) { if( strcmp( ((TextureDefinition*)pNode)->m_Filename, texturefilename ) == 0 ) return (TextureDefinition*)pNode; } for( CPPListNode* pNode = m_TexturesStillLoading.GetHead(); pNode; pNode = pNode->GetNext() ) { if( strcmp( ((TextureDefinition*)pNode)->m_Filename, texturefilename ) == 0 ) return (TextureDefinition*)pNode; } return 0; }
void MaterialManager::Tick() { // TODO: free file once the material is loaded... or not and check for updates on alt-tab for( CPPListNode* pNode = m_MaterialsStillLoading.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; if( pMaterial->m_pFile->m_FileLoadStatus == FileLoadStatus_Success ) { pMaterial->ImportFromFile(); #if MYFW_USING_WX char* foldername = "Unknown"; if( pMaterial->m_pFile ) foldername = pMaterial->m_pFile->GetNameOfDeepestFolderPath(); g_pPanelMemory->RemoveMaterial( pMaterial ); g_pPanelMemory->AddMaterial( pMaterial, foldername, pMaterial->m_Name, MaterialDefinition::StaticOnLeftClick, MaterialDefinition::StaticOnRightClick, MaterialDefinition::StaticOnDrag ); g_pPanelMemory->SetLabelEditFunction( g_pPanelMemory->m_pTree_Materials, pMaterial, MaterialDefinition::StaticOnLabelEdit ); #endif } if( pMaterial->m_FullyLoaded ) { m_Materials.MoveTail( pMaterial ); //if( pMaterial->m_pFile ) //{ // g_pFileManager->FreeFile( pMaterial->m_pFile ); //} } } }
void TextureManager::FreeAllTextures(bool shuttingdown) { for( CPPListNode* pNode = m_LoadedTextures.GetHead(); pNode; ) { TextureDefinition* pTextureDef = (TextureDefinition*)pNode; pNode = pNode->GetNext(); MyAssert( pTextureDef->GetRefCount() == 1 ); pTextureDef->Release(); } for( CPPListNode* pNode = m_TexturesStillLoading.GetHead(); pNode; ) { TextureDefinition* pTextureDef = (TextureDefinition*)pNode; pNode = pNode->GetNext(); MyAssert( pTextureDef->GetRefCount() == 1 ); pTextureDef->Release(); } for( CPPListNode* pNode = m_InitializedFBOs.GetHead(); pNode; ) { FBODefinition* pFBODef = (FBODefinition*)pNode; pNode = pNode->GetNext(); if( pFBODef->m_OnlyFreeOnShutdown == false || shuttingdown ) { MyAssert( pFBODef->GetRefCount() == 1 ); pFBODef->Release(); } } for( CPPListNode* pNode = m_UninitializedFBOs.GetHead(); pNode; ) { FBODefinition* pFBODef = (FBODefinition*)pNode; pNode = pNode->GetNext(); if( pFBODef->m_OnlyFreeOnShutdown == false || shuttingdown ) { MyAssert( pFBODef->GetRefCount() == 1 ); pFBODef->Release(); } } }
MaterialDefinition* MaterialManager::FindMaterialByFilename(const char* fullpath) { for( CPPListNode* pNode = m_MaterialsStillLoading.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; if( strcmp( pMaterial->m_pFile->m_FullPath, fullpath ) == 0 ) return pMaterial; } for( CPPListNode* pNode = m_Materials.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; if( pMaterial->m_pFile && strcmp( pMaterial->m_pFile->m_FullPath, fullpath ) == 0 ) return pMaterial; } return 0; }
void MaterialManager::SaveAllMaterials(bool saveunchanged) { for( CPPListNode* pNode = m_Materials.GetHead(); pNode; pNode = pNode->GetNext() ) { MaterialDefinition* pMaterial = (MaterialDefinition*)pNode; //if( pMaterial->m_UnsavedChanges || saveunchanged ) { pMaterial->SaveMaterial(); } } }
ShaderGroup* ShaderGroupManager::FindShaderGroupByName(const char* name) { assert( name ); for( CPPListNode* pNode = m_ShaderGroupList.GetHead(); pNode; pNode = pNode->GetNext() ) { ShaderGroup* pShaderGroup = (ShaderGroup*)pNode; if( strcmp( pShaderGroup->GetName(), name ) == 0 ) { return pShaderGroup; } } return 0; }
void TextureManager::Tick() { // Initialize all FBOs { CPPListNode* pNextNode; for( CPPListNode* pNode = m_UninitializedFBOs.GetHead(); pNode != 0; pNode = pNextNode ) { pNextNode = pNode->GetNext(); FBODefinition* pFBODef = (FBODefinition*)pNode; if( pFBODef->m_FailedToInit ) continue; bool success = pFBODef->Create(); if( success ) { LOGInfo( LOGTag, "pFBODef->Create() succeeded\n" ); //g_pPanelMemory->AddTexture( pFBODef ); m_InitializedFBOs.MoveTail( pFBODef ); pFBODef->m_FullyLoaded = true; } else { pFBODef->m_FailedToInit = true; LOGError( LOGTag, "========================\n" ); LOGError( LOGTag, "pFBODef->Create() failed\n" ); LOGError( LOGTag, "========================\n" ); } } } //// debug: list all textures that need loading. //for( CPPListNode* pNode = m_TexturesStillLoading.GetHead(); pNode; pNode = pNode->GetNext() ) //{ // TextureDefinition* pTextureDef = (TextureDefinition*)pNode; // LOGInfo( LOGTag, "Still need to load: %s\n", pTextureDef->m_Filename ); //} int texturesloadedthistick = 0; CPPListNode* pNextNode; for( CPPListNode* pNode = m_TexturesStillLoading.GetHead(); pNode != 0; pNode = pNextNode ) { pNextNode = pNode->GetNext(); if( m_MaxTexturesToLoadInOneTick != -1 && texturesloadedthistick >= m_MaxTexturesToLoadInOneTick ) break; texturesloadedthistick++; TextureDefinition* pTextureDef = (TextureDefinition*)pNode; //LOGInfo( LOGTag, "Loading Texture: %s\n", pTextureDef->m_Filename ); // if we have an opengl texture, then nothing to do. this shouldn't happen, loaded textures should be in "m_LoadedTextures". MyAssert( pTextureDef->m_TextureID == 0 ); if( pTextureDef->m_TextureID != 0 ) { LOGInfo( LOGTag, "Loading Texture: Already had a texture id?!? pTextureDef->m_TextureID != 0\n" ); continue; } bool textureloaded = false; #if 0 //MYFW_ANDROID //LOGInfo( LOGTag, "Loading Texture: pTextureDef->m_pFile %d\n", pTextureDef->m_pFile ); if( pTextureDef->m_pFile == 0 ) { pTextureDef->m_pFile = RequestTexture( pTextureDef->m_Filename, pTextureDef ); textureloaded = true; } else { LOGInfo( LOGTag, "Loading Texture: calling Android_LoadTextureFromMemory\n" ); pTextureDef->m_TextureID = Android_LoadTextureFromMemory( pTextureDef ); textureloaded = true; } #else // if the file load hasn't started... start the file load. if( pTextureDef->m_pFile == 0 ) { //LOGInfo( LOGTag, "Loading Texture: RequestFile\n" ); pTextureDef->m_pFile = RequestFile( pTextureDef->m_Filename ); //LOGInfo( LOGTag, "Loading Texture: ~RequestFile\n" ); } else { // if the file is ready, create an opengl texture from it. if( pTextureDef->m_pFile->m_FileLoadStatus == FileLoadStatus_Success ) { //LOGInfo( LOGTag, "Loading Texture: pTextureDef->m_pFile->m_FileReady\n" ); pTextureDef->m_TextureID = CreateTextureFromBuffer( pTextureDef ); //LOGInfo( LOGTag, "Loading Texture: CreateTextureFromBuffer\n" ); if( pTextureDef->m_TextureID != 0 ) { //LOGInfo( LOGTag, "Loading Texture: textureloaded = true\n" ); textureloaded = true; } } if( pTextureDef->m_pFile->m_FileLoadStatus > FileLoadStatus_Success ) { LOGError( LOGTag, "File load failed %s\n", pTextureDef->m_Filename ); SAFE_RELEASE( pTextureDef ); } } #endif if( textureloaded ) { LOGInfo( LOGTag, "textureloaded %s\n", pTextureDef->m_Filename ); // by default, we don't free the texture from main ram, so if we free the opengl tex, we can "reload" quick. if( pTextureDef->QueryFreeWhenCreated() ) g_pFileManager->FreeFile( pTextureDef->m_pFile ); m_LoadedTextures.MoveTail( pTextureDef ); pTextureDef->m_FullyLoaded = true; #if MYFW_USING_WX g_pPanelMemory->AddTexture( pTextureDef, "Global", pTextureDef->m_Filename, TextureDefinition::StaticOnDrag ); #endif LOGInfo( LOGTag, "pTextureDef->m_FullyLoaded = true %s\n", pTextureDef->m_Filename ); } } }