summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assetFactory/assimp.cpp19
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};
});
}