diff --git a/Core/Config.cpp b/Core/Config.cpp index e66ac808c6..a5b4bb79d5 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -477,8 +477,9 @@ static ConfigSetting graphicsSettings[] = { ConfigSetting("ImmersiveMode", &g_Config.bImmersiveMode, false, true, true), ReportedConfigSetting("TrueColor", &g_Config.bTrueColor, true, true, true), - ReportedConfigSetting("MipMap", &g_Config.bMipMap, true, true, true), + ReportedConfigSetting("ReplaceTextures", &g_Config.bReplaceTextures, true, true, true), + ReportedConfigSetting("SaveNewTextures", &g_Config.bSaveNewTextures, false, true, true), ReportedConfigSetting("TexScalingLevel", &g_Config.iTexScalingLevel, 1, true, true), ReportedConfigSetting("TexScalingType", &g_Config.iTexScalingType, 0, true, true), diff --git a/Core/Config.h b/Core/Config.h index 8618adaa46..b2cfc1351e 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -180,6 +180,8 @@ public: int bHighQualityDepth; bool bTrueColor; bool bMipMap; + bool bReplaceTextures; + bool bSaveNewTextures; int iTexScalingLevel; // 1 = off, 2 = 2x, ..., 5 = 5x int iTexScalingType; // 0 = xBRZ, 1 = Hybrid bool bTexDeposterize; diff --git a/Core/System.cpp b/Core/System.cpp index d1613cc617..5a78541596 100644 --- a/Core/System.cpp +++ b/Core/System.cpp @@ -586,6 +586,8 @@ std::string GetSysDirectory(PSPDirectories directoryType) { return g_Config.memStickDirectory + "PSP/PPSSPP_STATE/"; case DIRECTORY_CACHE: return g_Config.memStickDirectory + "PSP/SYSTEM/CACHE/"; + case DIRECTORY_TEXTURES: + return g_Config.memStickDirectory + "PSP/TEXTURES/"; case DIRECTORY_APP_CACHE: if (!g_Config.appCacheDirectory.empty()) { return g_Config.appCacheDirectory; diff --git a/Core/System.h b/Core/System.h index 4ff1767d87..7815b60acc 100644 --- a/Core/System.h +++ b/Core/System.h @@ -45,6 +45,7 @@ enum PSPDirectories { DIRECTORY_DUMP, DIRECTORY_SAVESTATE, DIRECTORY_CACHE, + DIRECTORY_TEXTURES, DIRECTORY_APP_CACHE, // Use the OS app cache if available }; diff --git a/GPU/Common/TextureReplacer.cpp b/GPU/Common/TextureReplacer.cpp index 7a8fdd2997..423780d32e 100644 --- a/GPU/Common/TextureReplacer.cpp +++ b/GPU/Common/TextureReplacer.cpp @@ -15,6 +15,10 @@ // Official git repository and contact information can be found at // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. +#include "Common/FileUtil.h" +#include "Core/Config.h" +#include "Core/System.h" +#include "Core/ELF/ParamSFO.h" #include "GPU/Common/TextureReplacer.h" TextureReplacer::TextureReplacer() : enabled_(false) { @@ -23,25 +27,59 @@ TextureReplacer::TextureReplacer() : enabled_(false) { TextureReplacer::~TextureReplacer() { } - void TextureReplacer::Init() { + NotifyConfigChanged(); } void TextureReplacer::NotifyConfigChanged() { + gameID_ = g_paramSFO.GetValueString("DISC_ID"); + + enabled_ = !gameID_.empty() && (g_Config.bReplaceTextures || g_Config.bSaveNewTextures); + if (enabled_) { + basePath_ = GetSysDirectory(DIRECTORY_TEXTURES) + gameID_ + "/"; + + // If we're saving, auto-create the directory. + if (g_Config.bSaveNewTextures && !File::Exists(basePath_)) { + File::CreateFullPath(basePath_); + } + + enabled_ = File::Exists(basePath_) && File::IsDirectory(basePath_); + } + + // TODO: Load ini file. } u32 TextureReplacer::ComputeHash(u32 addr, int bufw, int w, int h, GETextureFormat fmt, u16 maxSeenV) { + _dbg_assert_msg_(G3D, enabled_, "Replacement not enabled"); return 0; } ReplacedTexture TextureReplacer::FindReplacement(u32 hash) { + _assert_msg_(G3D, enabled_, "Replacement not enabled"); + ReplacedTexture result; result.alphaStatus_ = ReplacedTextureAlpha::UNKNOWN; + + // Only actually replace if we're replacing. We might just be saving. + if (g_Config.bReplaceTextures) { + // TODO + } return result; } void TextureReplacer::NotifyTextureDecoded(u32 hash, const void *data, int pitch, int w, int h, ReplacedTextureFormat fmt) { + _assert_msg_(G3D, enabled_, "Replacement not enabled"); + if (!g_Config.bSaveNewTextures) { + // Ignore. + return; + } + + // TODO } void ReplacedTexture::Load(int level, void *out, int rowPitch) { + _assert_msg_(G3D, (size_t)level < levels_.size(), "Invalid miplevel"); + _assert_msg_(G3D, out != nullptr && rowPitch > 0, "Invalid out/pitch"); + + // TODO } diff --git a/GPU/Common/TextureReplacer.h b/GPU/Common/TextureReplacer.h index b7a3f1e8b0..78ccc97175 100644 --- a/GPU/Common/TextureReplacer.h +++ b/GPU/Common/TextureReplacer.h @@ -42,6 +42,7 @@ struct ReplacedTexureLevel { int w; int h; ReplacedTextureFormat fmt; + std::string file; }; struct ReplacedTexture { @@ -102,4 +103,6 @@ public: protected: bool enabled_; + std::string gameID_; + std::string basePath_; };