diff --git a/code/ryzom/client/src/client_cfg.cpp b/code/ryzom/client/src/client_cfg.cpp index 8ebb6e417..8a73510e1 100644 --- a/code/ryzom/client/src/client_cfg.cpp +++ b/code/ryzom/client/src/client_cfg.cpp @@ -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 // diff --git a/code/ryzom/client/src/client_cfg.h b/code/ryzom/client/src/client_cfg.h index 7728676e5..7b7c3f8ab 100644 --- a/code/ryzom/client/src/client_cfg.h +++ b/code/ryzom/client/src/client_cfg.h @@ -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 // diff --git a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp index 4c7f2ee28..b8af699dd 100644 --- a/code/ryzom/client/src/interface_v3/action_handler_misc.cpp +++ b/code/ryzom/client/src/interface_v3/action_handler_misc.cpp @@ -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 z; + Driver->getZBuffer(z); + + float min = std::numeric_limits::max(); + float max = std::numeric_limits::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); -}; +} // *************************************************************************** diff --git a/code/ryzom/client/src/main_loop.cpp b/code/ryzom/client/src/main_loop.cpp index 3e7fefdd3..2a513244a 100644 --- a/code/ryzom/client/src/main_loop.cpp +++ b/code/ryzom/client/src/main_loop.cpp @@ -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 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)