From f8184858dae55306b464b5d56c9cde8ecbfad8a1 Mon Sep 17 00:00:00 2001 From: degasus Date: Mon, 22 Dec 2014 22:33:38 +0100 Subject: [PATCH] VideoCommon: Merge code to generate texture names on dumping --- Source/Core/VideoCommon/HiresTextures.cpp | 9 ++++-- Source/Core/VideoCommon/HiresTextures.h | 7 +++++ Source/Core/VideoCommon/TextureCacheBase.cpp | 31 ++++++++++---------- Source/Core/VideoCommon/TextureCacheBase.h | 2 +- 4 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Source/Core/VideoCommon/HiresTextures.cpp b/Source/Core/VideoCommon/HiresTextures.cpp index dff31975c2..633e6407a9 100644 --- a/Source/Core/VideoCommon/HiresTextures.cpp +++ b/Source/Core/VideoCommon/HiresTextures.cpp @@ -80,7 +80,7 @@ void HiresTexture::Init(const std::string& gameCode) } } -HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) +std::string HiresTexture::GenBaseName(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) { u64 tex_hash = GetHashHiresTexture(texture, (int)texture_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); u64 tlut_hash = 0; @@ -90,9 +90,14 @@ HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const tlut_hash = GetHashHiresTexture(tlut, (int)tlut_size, g_ActiveConfig.iSafeTextureCache_ColorSamples); hash ^= tlut_hash; } + return StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)hash, (u16)format); +} + +HiresTexture* HiresTexture::Search(const u8* texture, size_t texture_size, const u8* tlut, size_t tlut_size, u32 width, u32 height, int format) +{ + std::string base_filename = GenBaseName(texture, texture_size, tlut, tlut_size, width, height, format); HiresTexture* ret = nullptr; - std::string base_filename = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32)hash, format); for (int level = 0;; level++) { std::string filename = base_filename; diff --git a/Source/Core/VideoCommon/HiresTextures.h b/Source/Core/VideoCommon/HiresTextures.h index c4bad4a7d6..bd009424b6 100644 --- a/Source/Core/VideoCommon/HiresTextures.h +++ b/Source/Core/VideoCommon/HiresTextures.h @@ -21,6 +21,13 @@ public: int format ); + static std::string GenBaseName( + const u8* texture, size_t texture_size, + const u8* tlut, size_t tlut_size, + u32 width, u32 height, + int format + ); + ~HiresTexture(); struct Level diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 2674cb0c3d..3d9ea0c99d 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -263,9 +263,8 @@ void TextureCache::ClearRenderTargets() } } -void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level) +void TextureCache::DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level) { - std::string filename; std::string szDir = File::GetUserPath(D_DUMPTEXTURES_IDX) + SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID; @@ -273,20 +272,11 @@ void TextureCache::DumpTexture(TCacheEntryBase* entry, unsigned int level) if (!File::Exists(szDir) || !File::IsDirectory(szDir)) File::CreateDir(szDir); - // For compatibility with old texture packs, don't print the LOD index for level 0. - // TODO: TLUT format should actually be stored in filename? :/ - if (level == 0) + if (level > 0) { - filename = StringFromFormat("%s/%s_%08x_%i.png", szDir.c_str(), - SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), - (u32)(entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF); - } - else - { - filename = StringFromFormat("%s/%s_%08x_%i_mip%i.png", szDir.c_str(), - SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), - (u32) (entry->hash & 0x00000000FFFFFFFFLL), entry->format & 0xFFFF, level); + basename += StringFromFormat("_mip%i", level); } + std::string filename = szDir + "/" + basename + ".png"; if (!File::Exists(filename)) entry->Save(filename, level); @@ -507,8 +497,17 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage, else entry->type = TCET_NORMAL; + std::string basename = ""; if (g_ActiveConfig.bDumpTextures && !hires_tex) - DumpTexture(entry, 0); + { + basename = HiresTexture::GenBaseName( + src_data, texture_size, + &texMem[tlutaddr], palette_size, + width, height, + texformat + ); + DumpTexture(entry, basename, 0); + } u32 level = 1; // load mips - TODO: Loading mipmaps from tmem is untested! @@ -543,7 +542,7 @@ TextureCache::TCacheEntryBase* TextureCache::Load(unsigned int const stage, entry->Load(mip_width, mip_height, expanded_mip_width, level); if (g_ActiveConfig.bDumpTextures) - DumpTexture(entry, level); + DumpTexture(entry, basename, level); } } else if (using_custom_lods) diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 54287d2629..e3eb6a00fa 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -120,7 +120,7 @@ protected: static size_t temp_size; private: - static void DumpTexture(TCacheEntryBase* entry, unsigned int level); + static void DumpTexture(TCacheEntryBase* entry, std::string basename, unsigned int level); static void CheckTempSize(size_t required_size); static TCacheEntryBase* AllocateRenderTarget(unsigned int width, unsigned int height);