From 3cd6bc2d9eebbdd575164816110717241d9e22db Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Apr 2023 19:48:07 +0100 Subject: Load assimp textures in parallel --- assetFactory/assimp.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp index 55090f4..0c6cb86 100644 --- a/assetFactory/assimp.cpp +++ b/assetFactory/assimp.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include template @@ -101,12 +102,18 @@ AssImp::postLoad() return AssetFactory::Shapes::value_type {m->mName.C_Str(), std::make_shared(scene, m)}; }); const auto textures = AIRANGE(scene, Textures); - std::transform(textures.begin(), textures.end(), - std::inserter(mf->textureFragments, mf->textureFragments.end()), [](const aiTexture * t) { - auto texture = std::make_shared(); - texture->id = texture->path = t->mFilename.C_Str(); - texture->image = std::make_unique( - std::span {reinterpret_cast(t->pcData), t->mWidth}, STBI_rgb_alpha); + auto textureFutures = textures * [](const aiTexture * t) { + return std::async(std::launch::async, [t]() { + auto texture = std::make_shared(); + texture->id = texture->path = t->mFilename.C_Str(); + texture->image = std::make_unique( + std::span {reinterpret_cast(t->pcData), t->mWidth}, STBI_rgb_alpha); + return texture; + }); + }; + std::transform(textureFutures.begin(), textureFutures.end(), + std::inserter(mf->textureFragments, mf->textureFragments.end()), [](auto && textureFuture) { + auto texture = textureFuture.get(); return AssetFactory::TextureFragments::value_type {texture->id, texture}; }); } -- cgit v1.2.3