GSTexture: Implement Save() using common code

This commit is contained in:
Connor McLaughlin 2022-01-03 14:44:23 +10:00 committed by refractionpcsx2
parent 90e1284d83
commit 874e3d976f
2 changed files with 37 additions and 1 deletions

View File

@ -15,6 +15,8 @@
#include "PrecompiledHeader.h"
#include "GSTexture.h"
#include "GSDevice.h"
#include "GS/GSPng.h"
#include <bitset>
GSTexture::GSTexture()
@ -34,6 +36,40 @@ GSTexture::GSTexture()
{
}
bool GSTexture::Save(const std::string& fn)
{
#ifdef PCSX2_DEVBUILD
GSPng::Format format = GSPng::RGB_A_PNG;
#else
GSPng::Format format = GSPng::RGB_PNG;
#endif
switch (m_format)
{
case Format::UNorm8:
format = GSPng::R8I_PNG;
break;
case Format::Color:
break;
default:
Console.Error("Format %d not saved to image", static_cast<int>(m_format));
return false;
}
GSMap map;
if (!g_gs_device->DownloadTexture(this, GSVector4i(0, 0, m_size.x, m_size.y), map))
{
Console.Error("(GSTextureVK) DownloadTexture() failed.");
return false;
}
const int compression = theApp.GetConfigI("png_compression_level");
bool success = GSPng::Save(format, fn, map.bits, m_size.x, m_size.y, map.pitch, compression);
g_gs_device->DownloadTextureComplete();
return success;
}
void GSTexture::GenerateMipmapsIfNeeded()
{
if (!m_needs_mipmaps_generated || m_mipmap_levels <= 1)

View File

@ -77,7 +77,7 @@ public:
virtual bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) = 0;
virtual void Unmap() = 0;
virtual void GenerateMipmap() {}
virtual bool Save(const std::string& fn) = 0;
virtual bool Save(const std::string& fn);
virtual u32 GetID() { return 0; }
GSVector2 GetScale() const { return m_scale; }