mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-19 11:01:09 +00:00
address more comments, fix dumping textures that already got dumped
This commit is contained in:
parent
c2a32e942b
commit
8a98310a16
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
#include <lodepng.h>
|
#include <lodepng.h>
|
||||||
#include "common/logging/log.h"
|
#include "common/logging/log.h"
|
||||||
#include "lodepng_image_interface.h"
|
#include "citra/lodepng_image_interface.h"
|
||||||
|
|
||||||
bool LodePNGImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
|
bool LodePNGImageInterface::DecodePNG(std::vector<u8>& dst, u32& width, u32& height,
|
||||||
const std::string& path) {
|
const std::string& path) {
|
||||||
|
@ -508,14 +508,16 @@ void GameList::AddGamePopup(QMenu& context_menu, const QString& path, u64 progra
|
|||||||
connect(open_texture_dump_location, &QAction::triggered, [this, program_id] {
|
connect(open_texture_dump_location, &QAction::triggered, [this, program_id] {
|
||||||
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
|
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
|
FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
|
||||||
program_id)))
|
program_id))) {
|
||||||
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_DUMP);
|
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_DUMP);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(open_texture_load_location, &QAction::triggered, [this, program_id] {
|
connect(open_texture_load_location, &QAction::triggered, [this, program_id] {
|
||||||
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
|
if (FileUtil::CreateFullPath(fmt::format("{}textures/{:016X}/",
|
||||||
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
|
||||||
program_id)))
|
program_id))) {
|
||||||
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_LOAD);
|
emit OpenFolderRequested(program_id, GameListOpenTarget::TEXTURE_LOAD);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() {
|
connect(navigate_to_gamedb_entry, &QAction::triggered, [this, program_id]() {
|
||||||
emit NavigateToGamedbEntryRequested(program_id, compatibility_list);
|
emit NavigateToGamedbEntryRequested(program_id, compatibility_list);
|
||||||
|
@ -19,7 +19,7 @@ struct CustomTexInfo {
|
|||||||
// TODO: think of a better name for this class...
|
// TODO: think of a better name for this class...
|
||||||
class CustomTexCache {
|
class CustomTexCache {
|
||||||
public:
|
public:
|
||||||
CustomTexCache();
|
explicit CustomTexCache();
|
||||||
~CustomTexCache();
|
~CustomTexCache();
|
||||||
|
|
||||||
bool IsTextureDumped(u64 hash) const;
|
bool IsTextureDumped(u64 hash) const;
|
||||||
|
@ -894,27 +894,6 @@ bool CachedSurface::LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_inf
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<std::string> CachedSurface::GetDumpPath(u64 tex_hash) {
|
|
||||||
auto& custom_tex_cache = Core::System::GetInstance().CustomTexCache();
|
|
||||||
std::string path;
|
|
||||||
|
|
||||||
path =
|
|
||||||
fmt::format("{}textures/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::DumpDir),
|
|
||||||
Core::System::GetInstance().Kernel().GetCurrentProcess()->codeset->program_id);
|
|
||||||
if (!FileUtil::CreateFullPath(path)) {
|
|
||||||
LOG_ERROR(Render, "Unable to create {}", path);
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
path += fmt::format("tex1_{}x{}_{:016X}_{}.png", width, height, tex_hash,
|
|
||||||
static_cast<u32>(pixel_format));
|
|
||||||
if (!custom_tex_cache.IsTextureDumped(tex_hash) && !FileUtil::Exists(path)) {
|
|
||||||
custom_tex_cache.SetTextureDumped(tex_hash);
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
void CachedSurface::DumpTexture(GLuint target_tex, u64 tex_hash) {
|
void CachedSurface::DumpTexture(GLuint target_tex, u64 tex_hash) {
|
||||||
// Dump texture to RGBA8 and encode as PNG
|
// Dump texture to RGBA8 and encode as PNG
|
||||||
const auto& image_interface = Core::System::GetInstance().GetImageInterface();
|
const auto& image_interface = Core::System::GetInstance().GetImageInterface();
|
||||||
@ -929,22 +908,23 @@ void CachedSurface::DumpTexture(GLuint target_tex, u64 tex_hash) {
|
|||||||
|
|
||||||
dump_path += fmt::format("tex1_{}x{}_{:016X}_{}.png", width, height, tex_hash,
|
dump_path += fmt::format("tex1_{}x{}_{:016X}_{}.png", width, height, tex_hash,
|
||||||
static_cast<u32>(pixel_format));
|
static_cast<u32>(pixel_format));
|
||||||
if (!custom_tex_cache.IsTextureDumped(tex_hash) && !FileUtil::Exists(dump_path))
|
if (!custom_tex_cache.IsTextureDumped(tex_hash) && !FileUtil::Exists(dump_path)) {
|
||||||
custom_tex_cache.SetTextureDumped(tex_hash);
|
custom_tex_cache.SetTextureDumped(tex_hash);
|
||||||
|
|
||||||
LOG_INFO(Render_OpenGL, "Dumping texture to {}", dump_path);
|
LOG_INFO(Render_OpenGL, "Dumping texture to {}", dump_path);
|
||||||
std::vector<u8> decoded_texture;
|
std::vector<u8> decoded_texture;
|
||||||
decoded_texture.resize(width * height * 4);
|
decoded_texture.resize(width * height * 4);
|
||||||
glBindTexture(GL_TEXTURE_2D, target_tex);
|
glBindTexture(GL_TEXTURE_2D, target_tex);
|
||||||
if (GLES)
|
if (GLES)
|
||||||
GetTexImageOES(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, height, width, 0,
|
GetTexImageOES(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, height, width, 0,
|
||||||
&decoded_texture[0]);
|
&decoded_texture[0]);
|
||||||
else
|
else
|
||||||
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &decoded_texture[0]);
|
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, &decoded_texture[0]);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
Common::FlipRGBA8Texture(decoded_texture, width, height);
|
Common::FlipRGBA8Texture(decoded_texture, width, height);
|
||||||
if (!image_interface->EncodePNG(dump_path, decoded_texture, width, height))
|
if (!image_interface->EncodePNG(dump_path, decoded_texture, width, height))
|
||||||
LOG_ERROR(Render_OpenGL, "Failed to save decoded texture");
|
LOG_ERROR(Render_OpenGL, "Failed to save decoded texture");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64));
|
MICROPROFILE_DEFINE(OpenGL_TextureUL, "OpenGL", "Texture Upload", MP_RGB(128, 192, 64));
|
||||||
@ -959,7 +939,6 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
|
|||||||
|
|
||||||
// Read custom texture
|
// Read custom texture
|
||||||
auto& custom_tex_cache = Core::System::GetInstance().CustomTexCache();
|
auto& custom_tex_cache = Core::System::GetInstance().CustomTexCache();
|
||||||
bool use_custom_tex = false;
|
|
||||||
std::string dump_path; // Has to be declared here for logging later
|
std::string dump_path; // Has to be declared here for logging later
|
||||||
u64 tex_hash = 0;
|
u64 tex_hash = 0;
|
||||||
// Required for rect to function properly with custom textures
|
// Required for rect to function properly with custom textures
|
||||||
@ -969,7 +948,7 @@ void CachedSurface::UploadGLTexture(const Common::Rectangle<u32>& rect, GLuint r
|
|||||||
tex_hash = Common::ComputeHash64(gl_buffer.get(), gl_buffer_size);
|
tex_hash = Common::ComputeHash64(gl_buffer.get(), gl_buffer_size);
|
||||||
|
|
||||||
if (Settings::values.custom_textures)
|
if (Settings::values.custom_textures)
|
||||||
is_custom = use_custom_tex = LoadCustomTexture(tex_hash, custom_tex_info, custom_rect);
|
is_custom = LoadCustomTexture(tex_hash, custom_tex_info, custom_rect);
|
||||||
|
|
||||||
// Load data from memory to the surface
|
// Load data from memory to the surface
|
||||||
GLint x0 = static_cast<GLint>(custom_rect.left);
|
GLint x0 = static_cast<GLint>(custom_rect.left);
|
||||||
|
@ -384,7 +384,6 @@ struct CachedSurface : SurfaceParams, std::enable_shared_from_this<CachedSurface
|
|||||||
// Custom texture loading and dumping
|
// Custom texture loading and dumping
|
||||||
bool LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_info,
|
bool LoadCustomTexture(u64 tex_hash, Core::CustomTexInfo& tex_info,
|
||||||
Common::Rectangle<u32>& custom_rect);
|
Common::Rectangle<u32>& custom_rect);
|
||||||
std::optional<std::string> GetDumpPath(u64 tex_hash);
|
|
||||||
void DumpTexture(GLuint target_tex, u64 tex_hash);
|
void DumpTexture(GLuint target_tex, u64 tex_hash);
|
||||||
|
|
||||||
// Upload/Download data in gl_buffer in/to this surface's texture
|
// Upload/Download data in gl_buffer in/to this surface's texture
|
||||||
|
Loading…
Reference in New Issue
Block a user