handle texture of 0 in extract_tie (#2911)

Fixes texture difference shown in issue
https://github.com/open-goal/jak-project/issues/2908
This commit is contained in:
water111 2023-08-16 19:40:28 -04:00 committed by GitHub
parent 22c12c54ca
commit df1b0a341c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 33 deletions

View File

@ -9,6 +9,12 @@
namespace decompiler {
TextureDB::TextureDB() {
std::vector<u32> 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<u32>& data,

View File

@ -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<std::string, u32> 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<u32>& data,

View File

@ -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;
}