mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-29 00:59:44 -06:00
Working screenshots for everyone! This may not be the 'best' way to implement it but it's the most compatible, working and least mutually exclusive as possible (works with DC too). More coming soon.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2449 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -283,7 +283,7 @@ void __Log(int log, const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
HRESULT ScreenShot(TCHAR *File)
|
||||
HRESULT ScreenShot(const char *File)
|
||||
{
|
||||
if (D3D::dev == NULL)
|
||||
return S_FALSE;
|
||||
@ -314,7 +314,8 @@ HRESULT ScreenShot(TCHAR *File)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
unsigned int Video_Screenshot(TCHAR* _szFilename)
|
||||
void Video_Screenshot(const char *_szFilename)
|
||||
{
|
||||
return ScreenShot(_szFilename) == S_OK ? TRUE : FALSE;
|
||||
if(ScreenShot(_szFilename) != S_OK)
|
||||
PanicAlert("Error while capturing screen");
|
||||
}
|
||||
|
@ -52,6 +52,10 @@
|
||||
#include "OS/Win32.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
#include <wx/image.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Win32Window.h" // warning: crapcode
|
||||
#else
|
||||
@ -79,6 +83,10 @@ static GLuint s_ZBufferTarget = 0;
|
||||
static bool s_bATIDrawBuffers = false;
|
||||
static bool s_bHaveStencilBuffer = false;
|
||||
|
||||
static bool s_bScreenshot = false;
|
||||
static Common::CriticalSection s_criticalScreenshot;
|
||||
static std::string s_sScreenshotName;
|
||||
|
||||
static Renderer::RenderMode s_RenderMode = Renderer::RM_Normal;
|
||||
bool g_bBlendSeparate = false;
|
||||
int frameCount;
|
||||
@ -1065,6 +1073,21 @@ void Renderer::Swap(const TRectangle& rc)
|
||||
}
|
||||
// -------------------------------------
|
||||
|
||||
// Take screenshot, if necessary
|
||||
if(s_bScreenshot) {
|
||||
s_criticalScreenshot.Enter();
|
||||
|
||||
if(SaveRenderTarget(s_sScreenshotName.c_str())) {
|
||||
char msg[255];
|
||||
sprintf(msg, "Saved %s\n", s_sScreenshotName.c_str());
|
||||
OSD::AddMessage(msg, 500);
|
||||
} else
|
||||
PanicAlert("Error while capturing screen");
|
||||
|
||||
s_sScreenshotName = "";
|
||||
s_bScreenshot = false;
|
||||
s_criticalScreenshot.Leave();
|
||||
}
|
||||
|
||||
// Place messages on the picture, then copy it to the screen
|
||||
SwapBuffers();
|
||||
@ -1240,28 +1263,57 @@ void Renderer::RenderText(const char* pstr, int left, int top, u32 color)
|
||||
0, nBackbufferWidth, nBackbufferHeight);
|
||||
}
|
||||
|
||||
bool Renderer::SaveRenderTarget(const char* filename, int jpeg)
|
||||
void Renderer::SetScreenshot(const char *filename)
|
||||
{
|
||||
bool bflip = true;
|
||||
int nBackbufferHeight = (int)OpenGL_GetHeight();
|
||||
int nBackbufferWidth = (int)OpenGL_GetWidth();
|
||||
s_criticalScreenshot.Enter();
|
||||
s_sScreenshotName = filename;
|
||||
s_bScreenshot = true;
|
||||
|
||||
std::vector<u32> data(nBackbufferWidth * nBackbufferHeight);
|
||||
glReadPixels(0, 0, nBackbufferWidth, nBackbufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, &data[0]);
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
return false;
|
||||
s_criticalScreenshot.Leave();
|
||||
}
|
||||
|
||||
if (bflip) {
|
||||
// swap scanlines
|
||||
std::vector<u32> scanline(nBackbufferWidth);
|
||||
for (int i = 0; i < nBackbufferHeight/2; ++i) {
|
||||
memcpy(&scanline[0], &data[i*nBackbufferWidth], nBackbufferWidth*4);
|
||||
memcpy(&data[i*nBackbufferWidth], &data[(nBackbufferHeight-i-1)*nBackbufferWidth], nBackbufferWidth*4);
|
||||
memcpy(&data[(nBackbufferHeight-i-1)*nBackbufferWidth], &scanline[0], nBackbufferWidth*4);
|
||||
}
|
||||
}
|
||||
|
||||
return SaveTGA(filename, nBackbufferWidth, nBackbufferHeight, &data[0]);
|
||||
bool Renderer::SaveRenderTarget(const char *filename)
|
||||
{
|
||||
int w = (int)OpenGL_GetWidth(), h = (int)OpenGL_GetHeight();
|
||||
bool result = false;
|
||||
|
||||
if(!filename)
|
||||
return false;
|
||||
|
||||
u8 *data = (u8 *)malloc(3 * w * h);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
|
||||
glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
if (glGetError() != GL_NO_ERROR)
|
||||
return false;
|
||||
|
||||
// Flip image
|
||||
for(int y = 0; y < h / 2; y++) {
|
||||
for(int x = 0; x < w; x++) {
|
||||
std::swap(data[(y * w + x) * 3],
|
||||
data[((h - 1 - y) * w + x) * 3]);
|
||||
|
||||
std::swap(data[(y * w + x) * 3 + 1],
|
||||
data[((h - 1 - y) * w + x) * 3 + 1]);
|
||||
|
||||
std::swap(data[(y * w + x) * 3 + 2],
|
||||
data[((h - 1 - y) * w + x) * 3 + 2]);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
wxImage a(w, h, data);
|
||||
|
||||
a.SaveFile(wxString::FromAscii(filename), wxBITMAP_TYPE_BMP);
|
||||
result = true;
|
||||
#else
|
||||
result = SaveTGA(filename, w, h, data);
|
||||
|
||||
free(data);
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -126,7 +126,8 @@ public:
|
||||
|
||||
// Random utilities
|
||||
static void RenderText(const char* pstr, int left, int top, u32 color);
|
||||
static bool SaveRenderTarget(const char* filename, int jpeg);
|
||||
static void SetScreenshot(const char *filename);
|
||||
static bool SaveRenderTarget(const char *filename);
|
||||
|
||||
// Finish up the current frame, print some stats
|
||||
static void Swap(const TRectangle& rc);
|
||||
|
@ -337,25 +337,9 @@ void DebugLog(const char* _fmt, ...)
|
||||
#endif
|
||||
}
|
||||
|
||||
unsigned int Video_Screenshot(TCHAR* _szFilename)
|
||||
void Video_Screenshot(const char *_szFilename)
|
||||
{
|
||||
char str[64];
|
||||
int left = 200, top = 15;
|
||||
sprintf(str, "Dolphin OpenGL");
|
||||
|
||||
Renderer::ResetGLState();
|
||||
Renderer::RenderText(str, left+1, top+1, 0xff000000);
|
||||
Renderer::RenderText(str, left, top, 0xffc0ffff);
|
||||
Renderer::RestoreGLState();
|
||||
|
||||
if (Renderer::SaveRenderTarget(_szFilename, 0))
|
||||
{
|
||||
char msg[255];
|
||||
sprintf(msg, "saved %s\n", _szFilename);
|
||||
OSD::AddMessage(msg, 500);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
Renderer::SetScreenshot(_szFilename);
|
||||
}
|
||||
|
||||
void Video_UpdateXFB(u8* _pXFB, u32 _dwWidth, u32 _dwHeight, s32 _dwYOffset, bool scheduling)
|
||||
|
Reference in New Issue
Block a user