MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Capture

Method Capture

Source/Engine/Utilities/Screenshot.cpp:134–195  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132}
133
134void Screenshot::Capture(GPUTexture* target, const StringView& path)
135{
136 // Validate
137 if (target == nullptr)
138 {
139 LOG(Warning, "Cannot take screenshot. Render target texture is not allocated.");
140 return;
141 }
142 if (target->Depth() != 1)
143 {
144 LOG(Warning, "Cannot take screenshot. 3D textures are not supported.");
145 return;
146 }
147 if (GPUDevice::Instance == nullptr || GPUDevice::Instance->GetState() != GPUDevice::DeviceState::Ready)
148 {
149 LOG(Warning, "Cannot take screenshot. Graphics device is not ready.");
150 return;
151 }
152 PROFILE_MEM(Graphics);
153
154 // Faster path for staging textures that contents are ready to access on a CPU
155 if (target->IsStaging())
156 {
157 CaptureScreenshot screenshot(target, path);
158 TextureData& data = screenshot.GetData();
159 data.Width = target->Width();
160 data.Height = target->Height();
161 data.Format = target->Format();
162 data.Depth = target->Depth();
163 data.Items.Resize(target->ArraySize());
164 for (int32 arrayIndex = 0; arrayIndex < target->ArraySize(); arrayIndex++)
165 {
166 auto& slice = data.Items[arrayIndex];
167 slice.Mips.Resize(target->MipLevels());
168 for (int32 mipIndex = 0; mipIndex < target->MipLevels(); mipIndex++)
169 {
170 auto& mip = slice.Mips[mipIndex];
171 if (target->GetData(arrayIndex, mipIndex, mip))
172 {
173 LOG(Warning, "Cannot take screenshot. Failed to get texture data.");
174 return;
175 }
176 }
177 }
178 screenshot.Run();
179 return;
180 }
181
182 // Create tasks
183 auto saveTask = New<CaptureScreenshot>(target, path);
184 auto downloadTask = target->DownloadDataAsync(saveTask->GetData());
185 if (downloadTask == nullptr)
186 {
187 LOG(Warning, "Cannot capture screenshot. Cannot create download async task.");
188 Delete(saveTask);
189 return;
190 }
191

Callers 6

TakeScreenshotMethod · 0.80
OnImageClickedMethod · 0.80
GameWindowMethod · 0.80
TakeScreenshotMethod · 0.80
CollectFrameMethod · 0.80
TakeScreenshotMethod · 0.80

Calls 13

DeleteFunction · 0.85
FormatMethod · 0.80
ContinueWithMethod · 0.80
IsAllocatedMethod · 0.80
DepthMethod · 0.45
GetStateMethod · 0.45
IsStagingMethod · 0.45
GetDataMethod · 0.45
ResizeMethod · 0.45
ArraySizeMethod · 0.45
RunMethod · 0.45
DownloadDataAsyncMethod · 0.45

Tested by

no test coverage detected