diff options
| author | degasus <wickmarkus@web.de> | 2015-01-14 21:53:05 +0100 |
|---|---|---|
| committer | degasus <wickmarkus@web.de> | 2015-01-21 21:22:55 +0100 |
| commit | f9ced4eb133809b01abb1e3d1a7b11535fd92989 (patch) | |
| tree | 118e37bce429447d230f6c302ae87250bafd0279 /Source/Core/VideoCommon | |
| parent | 62402efa6c2777c4e9829767c39fed71fe3de60a (diff) | |
CustomTexture: also support the legacy format
Diffstat (limited to 'Source/Core/VideoCommon')
| -rw-r--r-- | Source/Core/VideoCommon/HiresTextures.cpp | 132 | ||||
| -rw-r--r-- | Source/Core/VideoCommon/HiresTextures.h | 2 |
2 files changed, 82 insertions, 52 deletions
diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index 2c916ec0f8..e41b591fc5 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -18,11 +18,18 @@ #include "VideoCommon/HiresTextures.h" #include "VideoCommon/VideoConfig.h" -std::unordered_map<std::string, std::string> HiresTexture::textureMap; +static std::unordered_map<std::string, std::string> s_textureMap; +static bool s_check_native_format; +static bool s_check_new_format; + +static const std::string s_format_prefix = "tex1_"; + void HiresTexture::Init(const std::string& gameCode) { - textureMap.clear(); + s_textureMap.clear(); + s_check_native_format = false; + s_check_new_format = false; CFileSearch::XStringVector Directories; @@ -66,69 +73,94 @@ void HiresTexture::Init(const std::string& gameCode) const CFileSearch::XStringVector& rFilenames = FileSearch.GetFileNames(); const std::string code = StringFromFormat("%s_", gameCode.c_str()); + const std::string code2 = ""; - if (rFilenames.size() > 0) + for (auto& rFilename : rFilenames) { - for (auto& rFilename : rFilenames) + std::string FileName; + SplitPath(rFilename, nullptr, &FileName, nullptr); + + if (FileName.substr(0, code.length()) == code) { - std::string FileName; - SplitPath(rFilename, nullptr, &FileName, nullptr); + s_textureMap[FileName] = rFilename; + s_check_native_format = true; + } - if (FileName.substr(0, code.length()).compare(code) == 0 && textureMap.find(FileName) == textureMap.end()) - textureMap.insert(std::map<std::string, std::string>::value_type(FileName, rFilename)); + if (FileName.substr(0, s_format_prefix.length()) == s_format_prefix) + { + s_textureMap[FileName] = rFilename; + s_check_new_format = true; } } } std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps, bool dump) { - // checking for min/max on paletted textures - u32 min = 0xffff; - u32 max = 0; - switch(tlut_size) + if (!dump && s_check_native_format) { - case 0: break; - case 16 * 2: - for (size_t i = 0; i < texture_size; i++) - { - min = std::min<u32>(min, texture[i] & 0xf); - min = std::min<u32>(min, texture[i] >> 4); - max = std::max<u32>(max, texture[i] & 0xf); - max = std::max<u32>(max, texture[i] >> 4); - } - break; - case 256 * 2: - for (size_t i = 0; i < texture_size; i++) - { - min = std::min<u32>(min, texture[i]); - max = std::max<u32>(max, texture[i]); - } - break; - case 16384 * 2: - for (size_t i = 0; i < texture_size/2; i++) - { - min = std::min<u32>(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); - max = std::max<u32>(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); - } - break; + // try to load the old format first + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); + u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples) : 0; + std::string name = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)(tex_hash ^ tlut_hash), (u16)format); + if (s_textureMap.find(name) != s_textureMap.end()) + return name; } - if (tlut_size > 0) + + if (dump || s_check_new_format) { - tlut_size = 2 * (max + 1 - min); - tlut += 2 * min; - } + // checking for min/max on paletted textures + u32 min = 0xffff; + u32 max = 0; + switch(tlut_size) + { + case 0: break; + case 16 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min<u32>(min, texture[i] & 0xf); + min = std::min<u32>(min, texture[i] >> 4); + max = std::max<u32>(max, texture[i] & 0xf); + max = std::max<u32>(max, texture[i] >> 4); + } + break; + case 256 * 2: + for (size_t i = 0; i < texture_size; i++) + { + min = std::min<u32>(min, texture[i]); + max = std::max<u32>(max, texture[i]); + } + break; + case 16384 * 2: + for (size_t i = 0; i < texture_size/2; i++) + { + min = std::min<u32>(min, Common::swap16(((u16*)texture)[i]) & 0x3fff); + max = std::max<u32>(max, Common::swap16(((u16*)texture)[i]) & 0x3fff); + } + break; + } + if (tlut_size > 0) + { + tlut_size = 2 * (max + 1 - min); + tlut += 2 * min; + } + + u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); + u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; - u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size); - u64 tlut_hash = tlut_size ? GetHashHiresTexture(tlut, (int)tlut_size) : 0; + std::string basename = s_format_prefix + StringFromFormat("%s%dx%d_%016lx", has_mipmaps ? "m_" : "", width, height, tex_hash); + std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; + std::string formatname = StringFromFormat("_%d", format); - std::string basename = StringFromFormat("tex1%s_%dx%d_%016lx", has_mipmaps ? "_m" : "", width, height, tex_hash); - std::string tlutname = tlut_size ? StringFromFormat("_%016lx", tlut_hash) : ""; - std::string formatname = StringFromFormat("_%d", format); + // try to match a wildcard template + if (!dump && s_textureMap.find(basename + "_*" + formatname) != s_textureMap.end()) + return basename + "_*" + formatname; - if (!dump && textureMap.find(basename + "_*" + formatname) != textureMap.end()) - return basename + "_*" + formatname; + // else generate the complete texture + if (dump || s_textureMap.find(basename + tlutname + formatname) != s_textureMap.end()) + return basename + tlutname + formatname; + } - return basename + tlutname + formatname; + return ""; } HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format, bool has_mipmaps) @@ -144,12 +176,12 @@ HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const filename += StringFromFormat("_mip%u", level); } - if (textureMap.find(filename) != textureMap.end()) + if (s_textureMap.find(filename) != s_textureMap.end()) { Level l; File::IOFile file; - file.Open(textureMap[filename], "rb"); + file.Open(s_textureMap[filename], "rb"); std::vector<u8> buffer(file.GetSize()); file.ReadBytes(buffer.data(), file.GetSize()); diff --git a/Source/Core/VideoCommon/HiresTextures.h b/Source/Core/VideoCommon/HiresTextures.h index 340d660706..f49f578625 100644 --- a/Source/Core/VideoCommon/HiresTextures.h +++ b/Source/Core/VideoCommon/HiresTextures.h @@ -39,8 +39,6 @@ public: }; std::vector<Level> m_levels; - static std::unordered_map<std::string, std::string> textureMap; - private: HiresTexture() {} |
