| 603 | } |
| 604 | |
| 605 | CompressionResult* LoadCompressedTextureSet(const char* fileName, bool createImagesIfEmpty) |
| 606 | { |
| 607 | ntc::FileStreamWrapper inputFile(m_ntcContext); |
| 608 | ntc::Status ntcStatus = m_ntcContext->OpenFile(fileName, false, inputFile.ptr()); |
| 609 | if (ntcStatus != ntc::Status::Ok) |
| 610 | { |
| 611 | log::error("Failed to open input file '%s', error code = %s: %s", fileName, |
| 612 | ntc::StatusToString(ntcStatus), ntc::GetLastErrorMessage()); |
| 613 | return nullptr; |
| 614 | } |
| 615 | |
| 616 | ntc::TextureSetMetadataWrapper metadata(m_ntcContext); |
| 617 | ntcStatus = m_ntcContext->CreateTextureSetMetadataFromStream(inputFile, metadata.ptr()); |
| 618 | if (ntcStatus != ntc::Status::Ok) |
| 619 | { |
| 620 | log::error("Failed to load input file '%s', error code = %s: %s", fileName, |
| 621 | ntc::StatusToString(ntcStatus), ntc::GetLastErrorMessage()); |
| 622 | return nullptr; |
| 623 | } |
| 624 | |
| 625 | int const maxImageDimension = 16384; |
| 626 | ntc::TextureSetDesc const& textureSetDesc = metadata->GetDesc(); |
| 627 | if (textureSetDesc.width > maxImageDimension || textureSetDesc.height > maxImageDimension) |
| 628 | { |
| 629 | log::error("Cannot load input file '%s' because the textures stored in it are too large for " |
| 630 | "graphics API usage. The texture set is %dx%d pixels, and maximum supported size is %dx%d.", |
| 631 | fileName, textureSetDesc.width, textureSetDesc.height, maxImageDimension, maxImageDimension); |
| 632 | return nullptr; |
| 633 | } |
| 634 | |
| 635 | if (!m_images.empty()) |
| 636 | { |
| 637 | std::unordered_set<std::string> missingImageNames; |
| 638 | std::unordered_set<std::string> extraImageNames; |
| 639 | for (MaterialImage const& image : m_images) |
| 640 | missingImageNames.insert(image.name); |
| 641 | |
| 642 | int const texturesInSet = metadata->GetTextureCount(); |
| 643 | for (int index = 0; index < texturesInSet; ++index) |
| 644 | { |
| 645 | std::string textureName = metadata->GetTexture(index)->GetName(); |
| 646 | auto it = missingImageNames.find(textureName); |
| 647 | if (it == missingImageNames.end()) |
| 648 | extraImageNames.insert(textureName); |
| 649 | else |
| 650 | missingImageNames.erase(it); |
| 651 | } |
| 652 | |
| 653 | if (!extraImageNames.empty() || !missingImageNames.empty()) |
| 654 | { |
| 655 | std::stringstream ss; |
| 656 | ss << "The compressed texture set contains textures that do not match the loaded reference images.\n"; |
| 657 | if (!extraImageNames.empty()) |
| 658 | { |
| 659 | ss << "Extra textures:\n"; |
| 660 | for (std::string const& name : extraImageNames) |
| 661 | { |
| 662 | ss << " - " << name << "\n"; |
nothing calls this directly
no test coverage detected