Screenshot capability of Software rasterizer for feature completness.

This commit is contained in:
Ryan Houdek 2013-11-15 22:07:08 -06:00
parent 23c84c220f
commit e8a4cc0f71
4 changed files with 33 additions and 5 deletions

View file

@ -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);
@ -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);
}

View file

@ -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"
@ -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
@ -25,6 +32,7 @@ RasterFont* s_pfont = NULL;
void SWRenderer::Init()
{
s_bScreenshot = false;
}
void SWRenderer::Shutdown()
@ -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
@ -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();

View file

@ -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();

View file

@ -236,7 +236,8 @@ u32 VideoSoftware::Video_GetQueryResult(PerfQueryType type)
bool VideoSoftware::Video_Screenshot(const char *_szFilename)
{
return false;
SWRenderer::SetScreenshot(_szFilename);
return true;
}
// -------------------------------