summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/AbstractTexture.cpp
diff options
context:
space:
mode:
authoriwubcode <iwubcode@users.noreply.github.com>2017-05-30 23:44:03 -0500
committeriwubcode <iwubcode@users.noreply.github.com>2017-11-17 22:11:23 -0600
commita9f0d1783bdf00e6610d314c48d8c16cf9439a1f (patch)
treeeda71b9dd45e465ee82613095ee2e5997e867be1 /Source/Core/VideoCommon/AbstractTexture.cpp
parent79387dddb24ddf035b70cd9379a42368dcd49e93 (diff)
Support frame and video dumping from VideoCommon
Diffstat (limited to 'Source/Core/VideoCommon/AbstractTexture.cpp')
-rw-r--r--Source/Core/VideoCommon/AbstractTexture.cpp87
1 files changed, 85 insertions, 2 deletions
diff --git a/Source/Core/VideoCommon/AbstractTexture.cpp b/Source/Core/VideoCommon/AbstractTexture.cpp
index 18f9c72064..0e92b6f7bd 100644
--- a/Source/Core/VideoCommon/AbstractTexture.cpp
+++ b/Source/Core/VideoCommon/AbstractTexture.cpp
@@ -4,9 +4,12 @@
#include <algorithm>
+#include "Common/Assert.h"
+
#include "VideoCommon/AbstractTexture.h"
+#include "VideoCommon/ImageWrite.h"
-AbstractTexture::AbstractTexture(const TextureConfig& c) : m_config(c)
+AbstractTexture::AbstractTexture(const TextureConfig& c) : m_config(c), m_currently_mapped(false)
{
}
@@ -14,7 +17,87 @@ AbstractTexture::~AbstractTexture() = default;
bool AbstractTexture::Save(const std::string& filename, unsigned int level)
{
- return false;
+ // We can't dump compressed textures currently (it would mean drawing them to a RGBA8
+ // framebuffer, and saving that). TextureCache does not call Save for custom textures
+ // anyway, so this is fine for now.
+ _assert_(m_config.format == AbstractTextureFormat::RGBA8);
+
+ auto result = level == 0 ? Map() : Map(level);
+
+ if (!result.has_value())
+ {
+ return false;
+ }
+
+ auto raw_data = result.value();
+ return TextureToPng(raw_data.data, raw_data.stride, filename, raw_data.width, raw_data.height);
+}
+
+std::optional<AbstractTexture::RawTextureInfo> AbstractTexture::Map()
+{
+ if (m_currently_mapped)
+ {
+ Unmap();
+ m_currently_mapped = false;
+ }
+ auto result = MapFullImpl();
+
+ if (!result.has_value())
+ {
+ m_currently_mapped = false;
+ return {};
+ }
+
+ m_currently_mapped = true;
+ return result;
+}
+
+std::optional<AbstractTexture::RawTextureInfo> AbstractTexture::Map(u32 level, u32 x, u32 y,
+ u32 width, u32 height)
+{
+ _assert_(level < m_config.levels);
+
+ u32 max_level_width = std::max(m_config.width >> level, 1u);
+ u32 max_level_height = std::max(m_config.height >> level, 1u);
+
+ _assert_(width < max_level_width);
+ _assert_(height < max_level_height);
+
+ auto result = MapRegionImpl(level, x, y, width, height);
+
+ if (!result.has_value())
+ {
+ m_currently_mapped = false;
+ return {};
+ }
+
+ m_currently_mapped = true;
+ return result;
+}
+
+std::optional<AbstractTexture::RawTextureInfo> AbstractTexture::Map(u32 level)
+{
+ _assert_(level < m_config.levels);
+
+ u32 level_width = std::max(m_config.width >> level, 1u);
+ u32 level_height = std::max(m_config.height >> level, 1u);
+
+ return Map(level, 0, 0, level_width, level_height);
+}
+
+void AbstractTexture::Unmap()
+{
+}
+
+std::optional<AbstractTexture::RawTextureInfo> AbstractTexture::MapFullImpl()
+{
+ return {};
+}
+
+std::optional<AbstractTexture::RawTextureInfo>
+AbstractTexture::MapRegionImpl(u32 level, u32 x, u32 y, u32 width, u32 height)
+{
+ return {};
}
bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format)