-------------------------------------------------------------------------------
| 410 | } |
| 411 | //------------------------------------------------------------------------------- |
| 412 | int CMaterialManager::LoadTexture(IDirect3DTexture9** p_ppiOut,aiString* szPath) |
| 413 | { |
| 414 | ai_assert(nullptr != p_ppiOut); |
| 415 | ai_assert(nullptr != szPath); |
| 416 | |
| 417 | *p_ppiOut = nullptr; |
| 418 | |
| 419 | const std::string s = szPath->data; |
| 420 | TextureCache::iterator ff; |
| 421 | if ((ff = sCachedTextures.find(s)) != sCachedTextures.end()) { |
| 422 | *p_ppiOut = (*ff).second; |
| 423 | (*p_ppiOut)->AddRef(); |
| 424 | return 1; |
| 425 | } |
| 426 | |
| 427 | // first get a valid path to the texture |
| 428 | if( 5 == FindValidPath(szPath)) |
| 429 | { |
| 430 | // embedded file. Find its index |
| 431 | unsigned int iIndex = atoi(szPath->data+1); |
| 432 | if (iIndex < g_pcAsset->pcScene->mNumTextures) |
| 433 | { |
| 434 | if (0 == g_pcAsset->pcScene->mTextures[iIndex]->mHeight) |
| 435 | { |
| 436 | // it is an embedded file ... don't need the file format hint, |
| 437 | // simply let D3DX load the file |
| 438 | D3DXIMAGE_INFO info; |
| 439 | if (FAILED(D3DXCreateTextureFromFileInMemoryEx(g_piDevice, |
| 440 | g_pcAsset->pcScene->mTextures[iIndex]->pcData, |
| 441 | g_pcAsset->pcScene->mTextures[iIndex]->mWidth, |
| 442 | D3DX_DEFAULT, |
| 443 | D3DX_DEFAULT, |
| 444 | 1, |
| 445 | D3DUSAGE_AUTOGENMIPMAP, |
| 446 | D3DFMT_UNKNOWN, |
| 447 | D3DPOOL_MANAGED, |
| 448 | D3DX_DEFAULT, |
| 449 | D3DX_DEFAULT, |
| 450 | 0, |
| 451 | &info, |
| 452 | nullptr, |
| 453 | p_ppiOut))) |
| 454 | { |
| 455 | std::string sz = "[ERROR] Unable to load embedded texture (#1): "; |
| 456 | sz.append(szPath->data); |
| 457 | CLogDisplay::Instance().AddEntry(sz,D3DCOLOR_ARGB(0xFF,0xFF,0x0,0x0)); |
| 458 | |
| 459 | this->SetDefaultTexture(p_ppiOut); |
| 460 | return 1; |
| 461 | } |
| 462 | } |
| 463 | else |
| 464 | { |
| 465 | // fill a new texture ... |
| 466 | if(FAILED(g_piDevice->CreateTexture( |
| 467 | g_pcAsset->pcScene->mTextures[iIndex]->mWidth, |
| 468 | g_pcAsset->pcScene->mTextures[iIndex]->mHeight, |
| 469 | 0,D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,p_ppiOut,nullptr))) |
no test coverage detected