Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Screenshot capability of Software rasterizer for feature completness.
  • Loading branch information
Sonicadvance1 committed Nov 16, 2013
1 parent 23c84c2 commit e8a4cc0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Source/Core/VideoBackends/OGL/Src/Render.cpp
Expand Up @@ -1810,7 +1810,7 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle
{
u32 W = back_rc.GetWidth();
u32 H = back_rc.GetHeight();
u8 *data = (u8 *)malloc((sizeof(u8) * 4 * W * H));
u8 *data = new u8[W * 4 * H];
glPixelStorei(GL_PACK_ALIGNMENT, 1);

glReadPixels(back_rc.left, back_rc.bottom, W, H, GL_RGBA, GL_UNSIGNED_BYTE, data);
Expand All @@ -1825,7 +1825,6 @@ bool Renderer::SaveScreenshot(const std::string &filename, const TargetRectangle

// Turn image upside down
FlipImageData(data, W, H, 4);

return TextureToPng(data, W*4, filename.c_str(), W, H, false);
}

Expand Down
26 changes: 26 additions & 0 deletions Source/Core/VideoBackends/Software/Src/SWRenderer.cpp
Expand Up @@ -5,6 +5,8 @@
#include "Common.h"

#include "../../OGL/Src/GLUtil.h"
#include "ImageWrite.h"
#include "ImageWrite.h"
#include "RasterFont.h"
#include "SWRenderer.h"
#include "SWStatistics.h"
Expand All @@ -17,6 +19,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
Expand All @@ -25,6 +32,7 @@ RasterFont* s_pfont = NULL;

void SWRenderer::Init()
{
s_bScreenshot = false;
}

void SWRenderer::Shutdown()
Expand Down Expand Up @@ -80,6 +88,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
Expand Down Expand Up @@ -124,6 +139,17 @@ 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);
u8 *data = new u8[width * 4 * height];
memcpy(data, texture, sizeof(u8) * 4 * width * height);
TextureToPng(data, width*4, s_sScreenshotName.c_str(), width, height, false);
// Reset settings
s_sScreenshotName.clear();
s_bScreenshot = false;
}
GLsizei glWidth = (GLsizei)GLInterface->GetBackBufferWidth();
GLsizei glHeight = (GLsizei)GLInterface->GetBackBufferHeight();

Expand Down
6 changes: 4 additions & 2 deletions Source/Core/VideoBackends/Software/Src/SWRenderer.h
Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion Source/Core/VideoBackends/Software/Src/SWmain.cpp
Expand Up @@ -236,7 +236,8 @@ u32 VideoSoftware::Video_GetQueryResult(PerfQueryType type)

bool VideoSoftware::Video_Screenshot(const char *_szFilename)
{
return false;
SWRenderer::SetScreenshot(_szFilename);
return true;
}

// -------------------------------
Expand Down

0 comments on commit e8a4cc0

Please sign in to comment.