diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-10 19:48:07 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-10 19:48:07 +0100 |
commit | 3cd6bc2d9eebbdd575164816110717241d9e22db (patch) | |
tree | 6331bbe0439bb0a048c1a07a71e209fcbafd2d53 /assetFactory | |
parent | First cut loading assets using assimp (diff) | |
download | ilt-3cd6bc2d9eebbdd575164816110717241d9e22db.tar.bz2 ilt-3cd6bc2d9eebbdd575164816110717241d9e22db.tar.xz ilt-3cd6bc2d9eebbdd575164816110717241d9e22db.zip |
Load assimp textures in parallel
Diffstat (limited to 'assetFactory')
-rw-r--r-- | assetFactory/assimp.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
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 <assimp/cimport.h> #include <assimp/postprocess.h> #include <assimp/scene.h> +#include <future> #include <stb/stb_image.h> template<typename T> @@ -101,12 +102,18 @@ AssImp::postLoad() return AssetFactory::Shapes::value_type {m->mName.C_Str(), std::make_shared<AssImpNode>(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<TextureFragment>(); - texture->id = texture->path = t->mFilename.C_Str(); - texture->image = std::make_unique<Image>( - std::span {reinterpret_cast<unsigned char *>(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<TextureFragment>(); + texture->id = texture->path = t->mFilename.C_Str(); + texture->image = std::make_unique<Image>( + std::span {reinterpret_cast<unsigned char *>(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}; }); } |