Add API for checking if textures have an available replacement (#236)

* Add API for checking if textures have an available replacement

* Add test stubs for arm64

* GXIsTexObjReplaced -> has_replacement
This commit is contained in:
Irastris
2026-06-27 23:10:07 -04:00
committed by GitHub
parent 27f3bdfd22
commit 9087a409da
4 changed files with 55 additions and 0 deletions
+49
View File
@@ -1126,6 +1126,15 @@ void reload_replacement_directory(const std::filesystem::path& root, Replacement
unregister_replacements(group);
group = load_replacement_directory(root, options);
}
bool has_replacement(const GXTexObj* obj, const GXTlutObj* tlut) {
const auto* obj_ = reinterpret_cast<const GXTexObj_*>(obj);
if (tlut != nullptr) {
const auto* tlut_ = reinterpret_cast<const GXTlutObj_*>(tlut);
return gfx::texture_replacement::has_replacement(*obj_, *tlut_);
}
return gfx::texture_replacement::has_replacement(*obj_);
}
} // namespace aurora::texture
namespace aurora::gfx::texture_replacement {
@@ -1191,6 +1200,46 @@ std::optional<TextureHandle> find_replacement(const GXTexObj_& obj, const GXTlut
return find_source_replacement_locked(obj, sourceKey);
}
bool has_replacement(const GXTexObj_& obj) noexcept {
std::lock_guard lk(s_registryMutex);
if (s_entriesByKey.empty()) {
return false;
}
if (obj.data != nullptr) {
texture::ReplacementKey pointerKey{texture::TexturePointerKey{.data = obj.data}};
if (s_entriesByKey.contains(pointerKey)) {
return true;
}
}
if (s_sourceEntryCount == 0) {
return false;
}
return find_source_replacement_key_locked(build_source_key(obj)).has_value();
}
bool has_replacement(const GXTexObj_& obj, const GXTlutObj_& tlut) noexcept {
std::lock_guard lk(s_registryMutex);
if (s_entriesByKey.empty()) {
return false;
}
if (obj.data != nullptr) {
texture::ReplacementKey pointerKey{texture::TexturePointerKey{.data = obj.data}};
if (s_entriesByKey.contains(pointerKey)) {
return true;
}
}
if (s_sourceEntryCount == 0) {
return false;
}
return find_source_replacement_key_locked(build_source_key(obj, tlut)).has_value();
}
std::string build_texture_replacement_name(const GXTexObj_& obj) noexcept {
const auto key = build_source_key(obj);
return format_replacement_filename(key);
+2
View File
@@ -8,5 +8,7 @@ void initialize() noexcept;
void shutdown() noexcept;
std::optional<TextureHandle> find_replacement(const GXTexObj_& obj) noexcept;
std::optional<TextureHandle> find_replacement(const GXTexObj_& obj, const GXTlutObj_& tlut) noexcept;
bool has_replacement(const GXTexObj_& obj) noexcept;
bool has_replacement(const GXTexObj_& obj, const GXTlutObj_& tlut) noexcept;
std::string build_texture_replacement_name(const GXTexObj_& obj) noexcept;
} // namespace aurora::gfx::texture_replacement