From a848ff57b1802c8956c49f4b24175aa79b250d28 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Wed, 14 Sep 2022 20:52:01 +0200 Subject: Parallelize texture loading --- src/gltf.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/gltf.cpp b/src/gltf.cpp index 9b55cbb..ed7a85d 100644 --- a/src/gltf.cpp +++ b/src/gltf.cpp @@ -2,6 +2,8 @@ #include #include +#include +#include #define STB_IMAGE_IMPLEMENTATION #include @@ -114,12 +116,15 @@ void gltf::load_textures(const std::filesystem::path &path) { auto images_count = gltf_images.size(); std::vector images{images_count}; - for (size_t image_index = 0; image_index < images_count; image_index++) { + std::vector v(images_count); + std::iota(v.begin(), v.end(), 0); + + std::for_each(std::execution::par, v.begin(), v.end(), [&](const size_t image_index) { const auto &gltf_image = gltf_images[image_index]; auto filepath = (path / gltf_image["uri"].get()).string(); auto& image = images[image_index]; image.data = stbi_load(filepath.c_str(), &image.width, &image.height, &image.channels, 4); - } + }); // const auto &gltf_samplers = gltf_json["samplers"]; // auto samplers_count = gltf_samplers.size(); -- cgit v1.3