Fixed: #1196 Allow to dump ZBuffer when doing a screenshot

This commit is contained in:
kervala 2010-11-17 22:24:04 +01:00
parent 681703dff6
commit 8f9822595b
4 changed files with 96 additions and 46 deletions

View file

@ -410,6 +410,7 @@ CClientConfig::CClientConfig()
ScreenShotWidth = 0;
ScreenShotHeight = 0;
ScreenShotFullDetail = true;
ScreenShotZBuffer = false;
MaxNumberOfTimedFXInstances = 20;
SelectionFX = "sfx_selection_mouseover.ps";
@ -1028,6 +1029,7 @@ void CClientConfig::setValues()
READ_INT_FV(ScreenShotWidth)
READ_INT_FV(ScreenShotHeight)
READ_BOOL_FV(ScreenShotFullDetail)
READ_BOOL_FV(ScreenShotZBuffer)
/////////////////////////
// NEW PATCHING SYSTEM //

View file

@ -280,6 +280,7 @@ struct CClientConfig
uint ScreenShotWidth; // If 0 : normal screen shot, else custom screen shot without interface
uint ScreenShotHeight;
bool ScreenShotFullDetail; // If set to true, then load balancing will be disabled for the duration of the screenshot
bool ScreenShotZBuffer; // If set to true, save also the ZBuffer in a file
/////////////////////////
// NEW PATCHING SYSTEM //

View file

@ -600,6 +600,67 @@ void initScreenshot()
if (!CFile::isExists(ScreenshotsDirectory)) CFile::createDirectory(ScreenshotsDirectory);
}
bool screenshotZBuffer(const std::string &filename)
{
std::string::size_type pos = filename.find(".");
if (pos == std::string::npos)
return false;
std::string filename_z = filename.substr(0, pos) + "_z" + filename.substr(pos);
std::string ext = filename.substr(pos+1);
std::vector<float> z;
Driver->getZBuffer(z);
float min = std::numeric_limits<float>::max();
float max = std::numeric_limits<float>::min();
// get min and max values
for(uint i = 0; i < z.size(); ++i)
{
float value = z[i];
if (value > max)
{
max = value;
}
else if (value < min)
{
min = value;
}
}
max = max - min;
CBitmap zi;
zi.resize(Driver->getWindowWidth(), Driver->getWindowHeight());
CRGBA *dest = (CRGBA *) &zi.getPixels()[0];
for(uint k = 0; k < z.size(); ++k)
{
// normalize values
uint8 i = (uint8) ((z[k] - min) * 255.f / max);
dest->set(i, i, i, i);
++ dest;
}
try
{
COFile f;
f.open(filename_z);
if (ext == "png")
zi.writePNG(f, 32);
else
zi.writeTGA(f, 32);
}
catch(...)
{
return false;
}
return true;
}
void screenShotTGA()
{
CBitmap btm;
@ -607,10 +668,20 @@ void screenShotTGA()
string filename = CFile::findNewFile (ScreenshotsDirectory+"screenshot.tga");
COFile fs(filename);
btm.writeTGA(fs, 24, false);
nlinfo("Screenshot '%s' saved in tga format (%dx%d)", filename.c_str(), (int) ClientCfg.ScreenShotWidth, (int) ClientCfg.ScreenShotHeight);
if (!btm.writeTGA(fs, 24, false))
{
fs.close();
CFile::deleteFile(filename);
return;
}
if (ClientCfg.ScreenShotZBuffer)
screenshotZBuffer(filename);
nlinfo("Screenshot '%s' saved in tga format (%ux%u)", filename.c_str(), ClientCfg.ScreenShotWidth, ClientCfg.ScreenShotHeight);
displayScreenShotSavedInfo(filename);
};
}
void screenShotPNG()
{
@ -619,6 +690,7 @@ void screenShotPNG()
string filename = CFile::findNewFile (ScreenshotsDirectory+"screenshot.png");
COFile fs(filename);
if (!btm.writePNG(fs, 24))
{
fs.close();
@ -626,9 +698,12 @@ void screenShotPNG()
return;
}
nlinfo("Screenshot '%s' saved in png format (%dx%d)", filename.c_str(), (int) ClientCfg.ScreenShotWidth, (int) ClientCfg.ScreenShotHeight);
if (ClientCfg.ScreenShotZBuffer)
screenshotZBuffer(filename);
nlinfo("Screenshot '%s' saved in png format (%ux%u)", filename.c_str(), ClientCfg.ScreenShotWidth, ClientCfg.ScreenShotHeight);
displayScreenShotSavedInfo(filename);
};
}
void screenShotJPG()
{
@ -637,10 +712,20 @@ void screenShotJPG()
string filename = CFile::findNewFile (ScreenshotsDirectory+"screenshot.jpg");
COFile fs(filename);
btm.writeJPG(fs);
nlinfo("Screenshot '%s' saved in jpg format (%dx%d)", filename.c_str(), (int) ClientCfg.ScreenShotWidth, (int) ClientCfg.ScreenShotHeight);
if (!btm.writeJPG(fs))
{
fs.close();
CFile::deleteFile(filename);
return;
}
if (ClientCfg.ScreenShotZBuffer)
screenshotZBuffer(filename);
nlinfo("Screenshot '%s' saved in jpg format (%ux%u)", filename.c_str(), ClientCfg.ScreenShotWidth, ClientCfg.ScreenShotHeight);
displayScreenShotSavedInfo(filename);
};
}
// ***************************************************************************

View file

@ -2739,44 +2739,6 @@ bool mainLoop()
R2::getEditor().updateBeforeSwapBuffer();
}
static volatile bool captureBuffers = false;
if (captureBuffers)
{
CBitmap color;
Driver->getBuffer(color);
try
{
COFile f;
f.open("color.tga");
color.writeTGA(f);
}
catch(...)
{
}
std::vector<float> z;
Driver->getZBuffer(z);
CBitmap zi;
zi.resize(color.getWidth(), color.getHeight());
CRGBA *dest = (CRGBA *) &zi.getPixels()[0];
for(uint k = 0; k < z.size(); ++k)
{
uint8 i = (uint8) (z[k] * 255.f);
dest->set(i, i, i, i);
++ dest;
}
try
{
COFile f;
f.open("z.tga");
zi.writeTGA(f);
}
catch(...)
{
}
}
Driver->swapBuffers();
if(Profiling)