summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software
diff options
context:
space:
mode:
authorRyan Houdek <Sonicadvance1@gmail.com>2013-11-21 21:17:58 -0600
committerRyan Houdek <Sonicadvance1@gmail.com>2013-11-21 21:17:58 -0600
commitea9ac07ec9a920612425413fb4256519b827328f (patch)
treec628b92f30fa3069b496031b40fc8a0ece5797fa /Source/Core/VideoBackends/Software
parent1aa06b8fa4105d22cac0dd847230215099bbeb78 (diff)
parentff917897731d400a8e71c1480425733e651126ee (diff)
Merge branch 'master' into jit_exit_addresses
Diffstat (limited to 'Source/Core/VideoBackends/Software')
-rw-r--r--Source/Core/VideoBackends/Software/Src/DebugUtil.cpp77
-rw-r--r--Source/Core/VideoBackends/Software/Src/DebugUtil.h2
-rw-r--r--Source/Core/VideoBackends/Software/Src/HwRasterizer.cpp7
-rw-r--r--Source/Core/VideoBackends/Software/Src/SWRenderer.cpp23
-rw-r--r--Source/Core/VideoBackends/Software/Src/SWRenderer.h6
-rw-r--r--Source/Core/VideoBackends/Software/Src/SWVideoConfig.cpp4
-rw-r--r--Source/Core/VideoBackends/Software/Src/SWmain.cpp3
7 files changed, 69 insertions, 53 deletions
diff --git a/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp b/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp
index 4472639a20..75c6c08ada 100644
--- a/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp
+++ b/Source/Core/VideoBackends/Software/Src/DebugUtil.cpp
@@ -42,7 +42,7 @@ void Init()
}
}
-void SaveTexture(const char* filename, u32 texmap, s32 mip)
+void SaveTexture(const std::string filename, u32 texmap, s32 mip)
{
FourTexUnits& texUnit = bpmem.tex[(texmap >> 2) & 1];
u8 subTexmap = texmap & 3;
@@ -54,28 +54,21 @@ void SaveTexture(const char* filename, u32 texmap, s32 mip)
u8 *data = new u8[width * height * 4];
- GetTextureBGRA(data, texmap, mip, width, height);
+ GetTextureRGBA(data, texmap, mip, width, height);
- (void)SaveTGA(filename, width, height, data);
+ (void)TextureToPng(data, width*4, filename, width, height, true);
+ delete[] data;
- delete []data;
}
-void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height)
+void GetTextureRGBA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height)
{
- u8 sample[4];
-
for (u32 y = 0; y < height; y++)
{
for (u32 x = 0; x < width; x++)
{
- TextureSampler::SampleMip(x << 7, y << 7, mip, false, texmap, sample);
-
- // RGBA to BGRA
- *(dst++) = sample[2];
- *(dst++) = sample[1];
- *(dst++) = sample[0];
- *(dst++) = sample[3];
+ TextureSampler::SampleMip(x << 7, y << 7, mip, false, texmap, dst);
+ dst += 4;
}
}
}
@@ -104,9 +97,9 @@ void DumpActiveTextures()
s32 maxLod = GetMaxTextureLod(texmap);
for (s32 mip = 0; mip <= maxLod; ++mip)
{
- SaveTexture(StringFromFormat("%star%i_ind%i_map%i_mip%i.tga",
+ SaveTexture(StringFromFormat("%star%i_ind%i_map%i_mip%i.png",
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
- swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
+ swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip), texmap, mip);
}
}
@@ -121,14 +114,14 @@ void DumpActiveTextures()
s32 maxLod = GetMaxTextureLod(texmap);
for (s32 mip = 0; mip <= maxLod; ++mip)
{
- SaveTexture(StringFromFormat("%star%i_stage%i_map%i_mip%i.tga",
+ SaveTexture(StringFromFormat("%star%i_stage%i_map%i_mip%i.png",
File::GetUserPath(D_DUMPTEXTURES_IDX).c_str(),
- swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip).c_str(), texmap, mip);
+ swstats.thisFrame.numDrawnObjects, stageNum, texmap, mip), texmap, mip);
}
}
}
-void DumpEfb(const char* filename)
+void DumpEfb(const std::string filename)
{
u8 *data = new u8[EFB_WIDTH * EFB_HEIGHT * 4];
u8 *writePtr = data;
@@ -139,20 +132,19 @@ void DumpEfb(const char* filename)
for (int x = 0; x < EFB_WIDTH; x++)
{
EfbInterface::GetColor(x, y, sample);
- // ABGR to BGRA
- *(writePtr++) = sample[1];
- *(writePtr++) = sample[2];
+ // ABGR to RGBA
*(writePtr++) = sample[3];
+ *(writePtr++) = sample[2];
+ *(writePtr++) = sample[1];
*(writePtr++) = sample[0];
}
}
- (void)SaveTGA(filename, EFB_WIDTH, EFB_HEIGHT, data);
-
- delete []data;
+ (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
+ delete[] data;
}
-void DumpDepth(const char* filename)
+void DumpDepth(const std::string filename)
{
u8 *data = new u8[EFB_WIDTH * EFB_HEIGHT * 4];
u8 *writePtr = data;
@@ -162,17 +154,16 @@ void DumpDepth(const char* filename)
for (int x = 0; x < EFB_WIDTH; x++)
{
u32 depth = EfbInterface::GetDepth(x, y);
- // depth to bgra
- *(writePtr++) = (depth >> 16) & 0xff;
+ // depth to rgba
+ *(writePtr++) = depth & 0xff;
*(writePtr++) = (depth >> 8) & 0xff;
- *(writePtr++) = depth & 0xff;
+ *(writePtr++) = (depth >> 16) & 0xff;
*(writePtr++) = 255;
}
}
- (void)SaveTGA(filename, EFB_WIDTH, EFB_HEIGHT, data);
-
- delete []data;
+ (void)TextureToPng(data, EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
+ delete[] data;
}
void DrawObjectBuffer(s16 x, s16 y, u8 *color, int bufferBase, int subBuffer, const char *name)
@@ -232,9 +223,9 @@ void OnObjectEnd()
if (!g_bSkipCurrentFrame)
{
if (g_SWVideoConfig.bDumpObjects && swstats.thisFrame.numDrawnObjects >= g_SWVideoConfig.drawStart && swstats.thisFrame.numDrawnObjects < g_SWVideoConfig.drawEnd)
- DumpEfb(StringFromFormat("%sobject%i.tga",
+ DumpEfb(StringFromFormat("%sobject%i.png",
File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
- swstats.thisFrame.numDrawnObjects).c_str());
+ swstats.thisFrame.numDrawnObjects));
if (g_SWVideoConfig.bHwRasterizer || drawingHwTriangles)
{
@@ -247,11 +238,13 @@ void OnObjectEnd()
if (DrawnToBuffer[i])
{
DrawnToBuffer[i] = false;
- (void)SaveTGA(StringFromFormat("%sobject%i_%s(%i).tga",
- File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
- swstats.thisFrame.numDrawnObjects, ObjectBufferName[i], i - BufferBase[i]).c_str(),
- EFB_WIDTH, EFB_HEIGHT, ObjectBuffer[i]);
+ std::string filename = StringFromFormat("%sobject%i_%s(%i).png",
+ File::GetUserPath(D_DUMPFRAMES_IDX).c_str(),
+ swstats.thisFrame.numDrawnObjects, ObjectBufferName[i], i - BufferBase[i]);
+
+ (void)TextureToPng((u8*)ObjectBuffer[i], EFB_WIDTH * 4, filename, EFB_WIDTH, EFB_HEIGHT, true);
memset(ObjectBuffer[i], 0, sizeof(ObjectBuffer[i]));
+
}
}
@@ -265,10 +258,10 @@ void OnFrameEnd()
{
if (g_SWVideoConfig.bDumpFrames)
{
- DumpEfb(StringFromFormat("%sframe%i_color.tga",
- File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount).c_str());
- DumpDepth(StringFromFormat("%sframe%i_depth.tga",
- File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount).c_str());
+ DumpEfb(StringFromFormat("%sframe%i_color.png",
+ File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount));
+ DumpDepth(StringFromFormat("%sframe%i_depth.png",
+ File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), swstats.frameCount));
}
}
}
diff --git a/Source/Core/VideoBackends/Software/Src/DebugUtil.h b/Source/Core/VideoBackends/Software/Src/DebugUtil.h
index 3cbb318ffb..7d5ac4beea 100644
--- a/Source/Core/VideoBackends/Software/Src/DebugUtil.h
+++ b/Source/Core/VideoBackends/Software/Src/DebugUtil.h
@@ -9,7 +9,7 @@ namespace DebugUtil
{
void Init();
- void GetTextureBGRA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height);
+ void GetTextureRGBA(u8 *dst, u32 texmap, s32 mip, u32 width, u32 height);
void DumpActiveTextures();
diff --git a/Source/Core/VideoBackends/Software/Src/HwRasterizer.cpp b/Source/Core/VideoBackends/Software/Src/HwRasterizer.cpp
index 996b440dc4..88b3e15ebd 100644
--- a/Source/Core/VideoBackends/Software/Src/HwRasterizer.cpp
+++ b/Source/Core/VideoBackends/Software/Src/HwRasterizer.cpp
@@ -329,15 +329,12 @@ namespace HwRasterizer
int image_width = texImage0.width;
int image_height = texImage0.height;
- DebugUtil::GetTextureBGRA(temp, 0, 0, image_width, image_height);
+ DebugUtil::GetTextureRGBA(temp, 0, 0, image_width, image_height);
glGenTextures(1, (GLuint *)&texture);
glBindTexture(TEX2D, texture);
-#ifdef USE_GLES
glTexImage2D(TEX2D, 0, GL_RGBA, (GLsizei)image_width, (GLsizei)image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp);
-#else
- glTexImage2D(TEX2D, 0, GL_RGBA8, (GLsizei)image_width, (GLsizei)image_height, 0, GL_BGRA, GL_UNSIGNED_BYTE, temp);
-#endif
+
GL_REPORT_ERRORD();
}
diff --git a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp
index 1d894b18da..069ca5eebc 100644
--- a/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp
+++ b/Source/Core/VideoBackends/Software/Src/SWRenderer.cpp
@@ -5,6 +5,7 @@
#include "Common.h"
#include "../../OGL/Src/GLUtil.h"
+#include "ImageWrite.h"
#include "RasterFont.h"
#include "SWRenderer.h"
#include "SWStatistics.h"
@@ -17,6 +18,11 @@ static GLint attr_pos = -1, attr_tex = -1;
static GLint uni_tex = -1;
static GLuint program;
+static volatile bool s_bScreenshot;
+static std::mutex s_criticalScreenshot;
+static std::string s_sScreenshotName;
+
+
// Rasterfont isn't compatible with GLES
// degasus: I think it does, but I can't test it
#ifndef USE_GLES
@@ -25,6 +31,7 @@ RasterFont* s_pfont = NULL;
void SWRenderer::Init()
{
+ s_bScreenshot = false;
}
void SWRenderer::Shutdown()
@@ -80,6 +87,13 @@ void SWRenderer::Prepare()
GL_REPORT_ERRORD();
}
+void SWRenderer::SetScreenshot(const char *_szFilename)
+{
+ std::lock_guard<std::mutex> lk(s_criticalScreenshot);
+ s_sScreenshotName = _szFilename;
+ s_bScreenshot = true;
+}
+
void SWRenderer::RenderText(const char* pstr, int left, int top, u32 color)
{
#ifndef USE_GLES
@@ -124,6 +138,15 @@ void SWRenderer::DrawDebugText()
void SWRenderer::DrawTexture(u8 *texture, int width, int height)
{
+ // Save screenshot
+ if (s_bScreenshot)
+ {
+ std::lock_guard<std::mutex> lk(s_criticalScreenshot);
+ TextureToPng(texture, width*4, s_sScreenshotName, width, height, false);
+ // Reset settings
+ s_sScreenshotName.clear();
+ s_bScreenshot = false;
+ }
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();
diff --git a/Source/Core/VideoBackends/Software/Src/SWRenderer.h b/Source/Core/VideoBackends/Software/Src/SWRenderer.h
index ba856936cb..80a93ea203 100644
--- a/Source/Core/VideoBackends/Software/Src/SWRenderer.h
+++ b/Source/Core/VideoBackends/Software/Src/SWRenderer.h
@@ -6,13 +6,15 @@
#define _RENDERER_H_
#include "CommonTypes.h"
+#include "Thread.h"
namespace SWRenderer
-{
+{
void Init();
void Prepare();
void Shutdown();
-
+
+ void SetScreenshot(const char *_szFilename);
void RenderText(const char* pstr, int left, int top, u32 color);
void DrawDebugText();
diff --git a/Source/Core/VideoBackends/Software/Src/SWVideoConfig.cpp b/Source/Core/VideoBackends/Software/Src/SWVideoConfig.cpp
index 43b6a96ef7..eb7cb79d40 100644
--- a/Source/Core/VideoBackends/Software/Src/SWVideoConfig.cpp
+++ b/Source/Core/VideoBackends/Software/Src/SWVideoConfig.cpp
@@ -65,8 +65,8 @@ void SWVideoConfig::Save(const char* ini_file)
iniFile.Set("Hardware", "RenderToMainframe", renderToMainframe);
iniFile.Set("Rendering", "HwRasterizer", bHwRasterizer);
- iniFile.Set("Rendering", "ZComploc", &bZComploc);
- iniFile.Set("Rendering", "ZFreeze", &bZFreeze);
+ iniFile.Set("Rendering", "ZComploc", bZComploc);
+ iniFile.Set("Rendering", "ZFreeze", bZFreeze);
iniFile.Set("Info", "ShowStats", bShowStats);
diff --git a/Source/Core/VideoBackends/Software/Src/SWmain.cpp b/Source/Core/VideoBackends/Software/Src/SWmain.cpp
index 939dd4553a..074b6bc38b 100644
--- a/Source/Core/VideoBackends/Software/Src/SWmain.cpp
+++ b/Source/Core/VideoBackends/Software/Src/SWmain.cpp
@@ -236,7 +236,8 @@ u32 VideoSoftware::Video_GetQueryResult(PerfQueryType type)
bool VideoSoftware::Video_Screenshot(const char *_szFilename)
{
- return false;
+ SWRenderer::SetScreenshot(_szFilename);
+ return true;
}
// -------------------------------