| 901 | } |
| 902 | |
| 903 | void BeginLoadingImages(Manifest const& manifest) |
| 904 | { |
| 905 | m_loading = true; |
| 906 | ClearImages(); |
| 907 | bool isFirstFile = true; |
| 908 | |
| 909 | m_manifest = manifest; |
| 910 | int manifestIndex = 0; |
| 911 | |
| 912 | for (ManifestEntry const& entry : manifest.textures) |
| 913 | { |
| 914 | ++m_texturesToLoad; |
| 915 | |
| 916 | m_threadPool.AddTask([this, entry, manifestIndex]() |
| 917 | { |
| 918 | MaterialImage image{}; |
| 919 | |
| 920 | std::string extension = fs::path(entry.fileName).extension().generic_string(); |
| 921 | LowercaseString(extension); |
| 922 | if (extension == ".exr") |
| 923 | { |
| 924 | LoadEXR((float**)&image.data, &image.width, &image.height, entry.fileName.c_str(), nullptr); |
| 925 | image.channels = 4; |
| 926 | image.format = ntc::ChannelFormat::FLOAT32; |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | FILE* imageFile = fopen(entry.fileName.c_str(), "rb"); |
| 931 | if (imageFile) |
| 932 | { |
| 933 | bool is16bit = stbi_is_16_bit_from_file(imageFile); |
| 934 | fseek(imageFile, 0, SEEK_SET); |
| 935 | |
| 936 | if (is16bit) |
| 937 | { |
| 938 | image.data = std::shared_ptr<stbi_uc>((stbi_uc*)stbi_load_from_file_16(imageFile, &image.width, &image.height, &image.channels, STBI_rgb_alpha)); |
| 939 | image.format = ntc::ChannelFormat::UNORM16; |
| 940 | } |
| 941 | else |
| 942 | { |
| 943 | image.data = std::shared_ptr<stbi_uc>(stbi_load_from_file(imageFile, &image.width, &image.height, &image.channels, STBI_rgb_alpha)); |
| 944 | image.format = ntc::ChannelFormat::UNORM8; |
| 945 | } |
| 946 | |
| 947 | fclose(imageFile); |
| 948 | } |
| 949 | } |
| 950 | |
| 951 | // The rest of this function is interlocked with other threads |
| 952 | std::lock_guard lockGuard(m_mutex); |
| 953 | |
| 954 | if (!image.data) |
| 955 | { |
| 956 | log::warning("Failed to read image '%s'.\n", entry.fileName.c_str()); |
| 957 | ++m_errors; |
| 958 | return; |
| 959 | } |
| 960 |
nothing calls this directly
no test coverage detected