|
4 | 4 | #include "../gx/gx.hpp" |
5 | 5 | #include "../internal.hpp" |
6 | 6 | #include "../webgpu/gpu.hpp" |
| 7 | +#include "astc_io.hpp" |
7 | 8 | #include "dds_io.hpp" |
8 | 9 | #include "png_io.hpp" |
9 | 10 | #include "texture_convert.hpp" |
@@ -112,6 +113,10 @@ bool iequals_ascii(std::string_view lhs, std::string_view rhs) noexcept { |
112 | 113 | return true; |
113 | 114 | } |
114 | 115 |
|
| 116 | +bool is_supported_texture_file_extension(std::string_view extension) noexcept { |
| 117 | + return iequals_ascii(extension, ".astc") || iequals_ascii(extension, ".dds") || iequals_ascii(extension, ".png"); |
| 118 | +} |
| 119 | + |
115 | 120 | int compare_ascii_ci(std::string_view lhs, std::string_view rhs) noexcept { |
116 | 121 | const size_t count = std::min(lhs.size(), rhs.size()); |
117 | 122 | for (size_t i = 0; i < count; ++i) { |
@@ -260,7 +265,8 @@ aurora::ArrayRef<uint8_t> tlut_bytes(const GXTlutObj_& tlut) noexcept { |
260 | 265 | return {static_cast<const uint8_t*>(tlut.data), static_cast<size_t>(tlut.numEntries) * sizeof(uint16_t)}; |
261 | 266 | } |
262 | 267 |
|
263 | | -std::optional<uint64_t> compute_referenced_tlut_hash(const GXTexObj_& obj, aurora::ArrayRef<uint8_t> tlutData) noexcept { |
| 268 | +std::optional<uint64_t> compute_referenced_tlut_hash(const GXTexObj_& obj, |
| 269 | + aurora::ArrayRef<uint8_t> tlutData) noexcept { |
264 | 270 | const uint32_t textureSize = texture_base_level_size(obj); |
265 | 271 | const auto* textureData = static_cast<const uint8_t*>(obj.data); |
266 | 272 | if (!is_palette_format(obj.format()) || !obj.has_data() || textureSize == 0 || tlutData.empty()) { |
@@ -391,7 +397,7 @@ std::optional<aurora::texture::TextureSourceKey> parse_replacement_filename(std: |
391 | 397 | return std::nullopt; |
392 | 398 | } |
393 | 399 |
|
394 | | - if (!iequals_ascii(filename.substr(dot), ".dds") && !iequals_ascii(filename.substr(dot), ".png")) { |
| 400 | + if (!is_supported_texture_file_extension(filename.substr(dot))) { |
395 | 401 | return std::nullopt; |
396 | 402 | } |
397 | 403 |
|
@@ -480,10 +486,17 @@ std::optional<aurora::texture::TextureSourceKey> parse_replacement_filename(std: |
480 | 486 | } |
481 | 487 |
|
482 | 488 | std::optional<aurora::gfx::ConvertedTexture> load_texture_file(const std::filesystem::path& path) { |
483 | | - if (iequals_ascii(fs_path_to_string(path.extension()), ".png")) { |
| 489 | + const auto extension = fs_path_to_string(path.extension()); |
| 490 | + if (iequals_ascii(extension, ".astc")) { |
| 491 | + return aurora::gfx::astc::load_astc_file(path); |
| 492 | + } |
| 493 | + if (iequals_ascii(extension, ".png")) { |
484 | 494 | return aurora::gfx::png::load_png_file(path); |
485 | 495 | } |
486 | | - return aurora::gfx::dds::load_dds_file(path); |
| 496 | + if (iequals_ascii(extension, ".dds")) { |
| 497 | + return aurora::gfx::dds::load_dds_file(path); |
| 498 | + } |
| 499 | + return std::nullopt; |
487 | 500 | } |
488 | 501 |
|
489 | 502 | bool remove_mipmaps(aurora::gfx::ConvertedTexture& texture) noexcept { |
@@ -1091,7 +1104,7 @@ ReplacementGroup load_replacement_directory(const std::filesystem::path& root, R |
1091 | 1104 | } |
1092 | 1105 |
|
1093 | 1106 | const auto extension = fs_path_to_string(path.extension()); |
1094 | | - if (!iequals_ascii(extension, ".dds") && !iequals_ascii(extension, ".png")) { |
| 1107 | + if (!is_supported_texture_file_extension(extension)) { |
1095 | 1108 | continue; |
1096 | 1109 | } |
1097 | 1110 |
|
@@ -1147,7 +1160,9 @@ std::optional<TextureHandle> find_source_replacement_locked(const GXTexObj_& obj |
1147 | 1160 | const auto replacementKey = find_source_replacement_key_locked(sourceKey); |
1148 | 1161 | if (!replacementKey.has_value()) { |
1149 | 1162 | const bool alwaysReportMissingKey = false; // Enable for debugging |
1150 | | - if (g_config.allowTextureDumps || alwaysReportMissingKey) { report_missing_key(sourceKey, obj); } |
| 1163 | + if (g_config.allowTextureDumps || alwaysReportMissingKey) { |
| 1164 | + report_missing_key(sourceKey, obj); |
| 1165 | + } |
1151 | 1166 | return std::nullopt; |
1152 | 1167 | } |
1153 | 1168 |
|
|
0 commit comments