From df1b0a341c7fb8b11934b27f967026741b3e2d46 Mon Sep 17 00:00:00 2001 From: water111 <48171810+water111@users.noreply.github.com> Date: Wed, 16 Aug 2023 19:40:28 -0400 Subject: [PATCH] handle texture of 0 in extract_tie (#2911) Fixes texture difference shown in issue https://github.com/open-goal/jak-project/issues/2908 --- decompiler/data/TextureDB.cpp | 6 +++ decompiler/data/TextureDB.h | 4 ++ decompiler/level_extractor/extract_tie.cpp | 58 ++++++++++------------ 3 files changed, 35 insertions(+), 33 deletions(-) diff --git a/decompiler/data/TextureDB.cpp b/decompiler/data/TextureDB.cpp index d4568d6e58..8981a0b240 100644 --- a/decompiler/data/TextureDB.cpp +++ b/decompiler/data/TextureDB.cpp @@ -9,6 +9,12 @@ namespace decompiler { +TextureDB::TextureDB() { + std::vector data(16 * 16, 0xffffffff); + add_texture(kPlaceholderWhiteTexturePage, kPlaceholderWhiteTextureId, data, 16, 16, + "placeholder-white", "placeholder", {}, 1, 0); +} + void TextureDB::add_texture(u32 tpage, u32 texid, const std::vector& data, diff --git a/decompiler/data/TextureDB.h b/decompiler/data/TextureDB.h index 1c293ed610..1a933a922f 100644 --- a/decompiler/data/TextureDB.h +++ b/decompiler/data/TextureDB.h @@ -12,6 +12,7 @@ namespace decompiler { struct TextureDB { + TextureDB(); struct TextureData { u16 w, h; std::string name; @@ -30,6 +31,9 @@ struct TextureDB { std::unordered_map animated_tex_output_to_anim_slot; + static constexpr int kPlaceholderWhiteTexturePage = INT16_MAX; + static constexpr int kPlaceholderWhiteTextureId = 0; + void add_texture(u32 tpage, u32 texid, const std::vector& data, diff --git a/decompiler/level_extractor/extract_tie.cpp b/decompiler/level_extractor/extract_tie.cpp index c6db02d090..1aca1fdbc5 100644 --- a/decompiler/level_extractor/extract_tie.cpp +++ b/decompiler/level_extractor/extract_tie.cpp @@ -2318,6 +2318,12 @@ TieCategoryInfo get_jak1_tie_category(u32 flags) { } u32 get_or_add_texture(u32 combo_tex, tfrag3::Level& lev, const TextureDB& tdb) { + if (combo_tex == 0) { + // untextured + combo_tex = (((u32)TextureDB::kPlaceholderWhiteTexturePage) << 16) | + TextureDB::kPlaceholderWhiteTextureId; + } + // try looking it up in the existing textures that we have in the C++ renderer data. // (this is shared with tfrag) u32 idx_in_lev_data = UINT32_MAX; @@ -2329,40 +2335,26 @@ u32 get_or_add_texture(u32 combo_tex, tfrag3::Level& lev, const TextureDB& tdb) } if (idx_in_lev_data == UINT32_MAX) { - if (combo_tex == 0) { - // lg::warn("unhandled texture 0 case in extract_tie for {} {}", - // lev.level_name, - // proto.name); - idx_in_lev_data = 0; - } else { - // didn't find it, have to add a new one texture. - auto tex_it = tdb.textures.find(combo_tex); - if (tex_it == tdb.textures.end()) { - bool ok_to_miss = false; // for TIE, there's no missing textures. - if (ok_to_miss) { - // we're missing a texture, just use the first one. - tex_it = tdb.textures.begin(); - } else { - ASSERT_MSG( - false, - fmt::format("texture {} wasn't found. make sure it is loaded somehow. You may need " - "to " - "include ART.DGO or GAME.DGO in addition to the level DGOs for shared " - "textures. tpage is {}. id is {} (0x{:x})", - combo_tex, combo_tex >> 16, combo_tex & 0xffff, combo_tex & 0xffff)); - } - } - // add a new texture to the level data - idx_in_lev_data = lev.textures.size(); - lev.textures.emplace_back(); - auto& new_tex = lev.textures.back(); - new_tex.combo_id = combo_tex; - new_tex.w = tex_it->second.w; - new_tex.h = tex_it->second.h; - new_tex.debug_name = tex_it->second.name; - new_tex.debug_tpage_name = tdb.tpage_names.at(tex_it->second.page); - new_tex.data = tex_it->second.rgba_bytes; + // didn't find it, have to add a new one texture. + auto tex_it = tdb.textures.find(combo_tex); + if (tex_it == tdb.textures.end()) { + ASSERT_MSG(false, fmt::format( + "texture {} wasn't found. make sure it is loaded somehow. You may need " + "to " + "include ART.DGO or GAME.DGO in addition to the level DGOs for shared " + "textures. tpage is {}. id is {} (0x{:x})", + combo_tex, combo_tex >> 16, combo_tex & 0xffff, combo_tex & 0xffff)); } + // add a new texture to the level data + idx_in_lev_data = lev.textures.size(); + lev.textures.emplace_back(); + auto& new_tex = lev.textures.back(); + new_tex.combo_id = combo_tex; + new_tex.w = tex_it->second.w; + new_tex.h = tex_it->second.h; + new_tex.debug_name = tex_it->second.name; + new_tex.debug_tpage_name = tdb.tpage_names.at(tex_it->second.page); + new_tex.data = tex_it->second.rgba_bytes; } return idx_in_lev_data; }