aboutsummaryrefslogtreecommitdiffstats
path: root/src/gltf.cpp
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-09-14 20:52:01 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-09-14 20:52:01 +0200
commita848ff57b1802c8956c49f4b24175aa79b250d28 (patch)
tree78cc43d7196d5340dead72d9feae966c3b512d10 /src/gltf.cpp
parent15069341c7c8c36c7371ea1de4b63ed52034b3a8 (diff)
Parallelize texture loading
Diffstat (limited to 'src/gltf.cpp')
-rw-r--r--src/gltf.cpp9
1 files 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 <fstream>
#include <filesystem>
+#include <algorithm>
+#include <execution>
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>
@@ -114,12 +116,15 @@ void gltf::load_textures(const std::filesystem::path &path) {
auto images_count = gltf_images.size();
std::vector<raw_image> images{images_count};
- for (size_t image_index = 0; image_index < images_count; image_index++) {
+ std::vector<size_t> 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<std::string>()).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();