| 76 | }; |
| 77 | |
| 78 | bool CaptureScreenshot::Run() |
| 79 | { |
| 80 | const auto texture = _texture.Get(); |
| 81 | if (texture == nullptr && _renderTask == nullptr) |
| 82 | { |
| 83 | LOG(Warning, "Missing target render task."); |
| 84 | return true; |
| 85 | } |
| 86 | PROFILE_MEM(Graphics); |
| 87 | |
| 88 | // TODO: how about a case two or more screenshots at the same second? update counter and check files |
| 89 | |
| 90 | // Ensure that path is valid and folder exists |
| 91 | String screenshotsDir; |
| 92 | if (_path.IsEmpty()) |
| 93 | { |
| 94 | #if USE_EDITOR |
| 95 | screenshotsDir = Globals::ProjectFolder / TEXT("Screenshots"); |
| 96 | #else |
| 97 | screenshotsDir = Globals::ProductLocalFolder / TEXT("Screenshots"); |
| 98 | #endif |
| 99 | _path = screenshotsDir / String::Format(TEXT("Screenshot_{0}.png"), DateTime::Now().ToFileNameString()); |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | screenshotsDir = StringUtils::GetDirectoryName(_path); |
| 104 | } |
| 105 | if (!FileSystem::DirectoryExists(screenshotsDir)) |
| 106 | FileSystem::CreateDirectory(screenshotsDir); |
| 107 | |
| 108 | #if COMPILE_WITH_TEXTURE_TOOL |
| 109 | // Export to file |
| 110 | if (TextureTool::ExportTexture(_path, _data)) |
| 111 | { |
| 112 | LOG(Warning, "Cannot export screenshot to file."); |
| 113 | return true; |
| 114 | } |
| 115 | #else |
| 116 | LOG(Warning, "Cannot export screenshot to file. No textures exporting support in build."); |
| 117 | return true; |
| 118 | #endif |
| 119 | |
| 120 | LOG(Info, "Saved screenshot '{1}' (time: {0} ms)", Math::RoundToInt((float)(DateTime::NowUTC() - _startTime).GetTotalMilliseconds()), _path); |
| 121 | |
| 122 | _renderTask = nullptr; |
| 123 | return false; |
| 124 | } |
| 125 | |
| 126 | void CaptureScreenshot::OnFail() |
| 127 | { |
no test coverage detected