MCPcopy Create free account
hub / github.com/WiVRn/WiVRn / load_all_textures

Method load_all_textures

client/render/scene_loader.cpp:708–786  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706 }
707
708 std::vector<std::shared_ptr<renderer::texture>> load_all_textures(const std::filesystem::path & texture_cache, std::function<void(float)> progress_cb)
709 {
710 // Determine which texture is sRGB
711 std::vector<uint8_t> srgb_array;
712 srgb_array.resize(gltf.textures.size(), false);
713 for (const fastgltf::Material & gltf_material: gltf.materials)
714 {
715 if (gltf_material.pbrData.baseColorTexture)
716 srgb_array.at(gltf_material.pbrData.baseColorTexture->textureIndex) = true;
717
718 if (gltf_material.emissiveTexture)
719 srgb_array.at(gltf_material.emissiveTexture->textureIndex) = true;
720 }
721
722 std::vector<std::shared_ptr<renderer::texture>> textures;
723 textures.reserve(gltf.textures.size());
724
725 int loaded_textures = 0;
726 int total_textures = gltf.textures.size();
727 for (auto && [srgb, gltf_texture]: std::views::zip(srgb_array, gltf.textures))
728 {
729 auto & texture_ref = *textures.emplace_back(std::make_shared<renderer::texture>());
730
731 if (gltf_texture.samplerIndex)
732 texture_ref.sampler = convert(gltf.samplers.at(*gltf_texture.samplerIndex));
733
734 std::vector<std::string> errors;
735
736 if (gltf_texture.basisuImageIndex)
737 {
738 try
739 {
740 texture_ref.image_view = load_image(*gltf_texture.basisuImageIndex, texture_cache, srgb);
741 loaded_textures++;
742 if (progress_cb)
743 progress_cb((float)loaded_textures / total_textures);
744 continue;
745 }
746 catch (std::exception & e)
747 {
748 errors.push_back(std::format("Cannot load image {}: {}", *gltf_texture.basisuImageIndex, e.what()));
749 }
750 }
751
752 // if (gltf_texture.ddsImageIndex)
753 // {
754 // // TODO
755 // }
756
757 // if (gltf_texture.webpImageIndex)
758 // {
759 // // TODO
760 // }
761
762 if (gltf_texture.imageIndex)
763 {
764 try
765 {

Callers 1

operator()Method · 0.80

Calls 7

convertFunction · 0.85
resizeMethod · 0.45
sizeMethod · 0.45
atMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected