| 544 | } |
| 545 | |
| 546 | std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromFileAsync( |
| 547 | const std::filesystem::path& path, |
| 548 | bool sRGB, |
| 549 | ThreadPool& threadPool) |
| 550 | { |
| 551 | std::shared_ptr<TextureData> texture; |
| 552 | |
| 553 | if (FindTextureInCache(path, texture)) |
| 554 | return texture; |
| 555 | |
| 556 | texture->forceSRGB = sRGB; |
| 557 | texture->path = path.generic_string(); |
| 558 | |
| 559 | threadPool.AddTask([this, texture, path]() |
| 560 | { |
| 561 | auto fileData = ReadTextureFile(path); |
| 562 | if (fileData) |
| 563 | { |
| 564 | if (FillTextureData(fileData, texture, path.extension().generic_string(), "")) |
| 565 | { |
| 566 | TextureLoaded(texture); |
| 567 | |
| 568 | std::lock_guard<std::mutex> guard(m_TexturesToFinalizeMutex); |
| 569 | |
| 570 | m_TexturesToFinalize.push(texture); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | ++m_TexturesLoaded; |
| 575 | }); |
| 576 | |
| 577 | return texture; |
| 578 | } |
| 579 | |
| 580 | std::shared_ptr<LoadedTexture> TextureCache::LoadTextureFromMemoryAsync( |
| 581 | const std::shared_ptr<vfs::IBlob>& data, |