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

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