载入中...
搜索中...
未找到
GraphicsReadback.cpp
浏览该文件的文档.
1#include <algorithm>
2#include <cmath>
3#include <cstring>
4#include <fstream>
5#include <glm/gtc/packing.hpp>
6#include <memory>
7#include <vector>
8#include "common/Exception.h"
13#include "image/ImageData.h"
14#if defined(__EMSCRIPTEN__)
15#include <emscripten/emscripten.h>
16#endif
17namespace eve::graphics::webgpu {
18void Graphics::recordPresentedReadback(wgpu::CommandEncoder &encoder, const wgpu::Texture &surfaceTexture) {
19 if (!surfaceCanCopySrc) throw Exception("WebGPU: surface does not support screen readback");
20 const int w = static_cast<int>(surfaceTexture.GetWidth());
21 const int h = static_cast<int>(surfaceTexture.GetHeight());
22 if (!presentedReadback || presentedReadbackW != w || presentedReadbackH != h ||
23 presentedReadbackFormat != surfaceFormat) {
24 WGPUTextureDescriptor desc{};
25 desc.label = sv("eve_presented_readback");
26 desc.dimension = WGPUTextureDimension_2D;
27 desc.size = {static_cast<uint32_t>(w), static_cast<uint32_t>(h), 1};
28 desc.format = surfaceFormat;
29 desc.mipLevelCount = 1;
30 desc.sampleCount = 1;
31 desc.usage = WGPUTextureUsage_CopyDst | WGPUTextureUsage_CopySrc;
32 presentedReadback = device.CreateTexture(reinterpret_cast<const wgpu::TextureDescriptor *>(&desc));
33 presentedReadbackW = w;
34 presentedReadbackH = h;
35 presentedReadbackFormat = surfaceFormat;
36 }
37 WGPUTexelCopyTextureInfo from{}, to{};
38 from.texture = surfaceTexture.Get();
39 from.aspect = WGPUTextureAspect_All;
40 to.texture = presentedReadback.Get();
41 to.aspect = WGPUTextureAspect_All;
42 WGPUExtent3D extent{static_cast<uint32_t>(w), static_cast<uint32_t>(h), 1};
43 encoder.CopyTextureToTexture(reinterpret_cast<const wgpu::TexelCopyTextureInfo *>(&from),
44 reinterpret_cast<const wgpu::TexelCopyTextureInfo *>(&to),
45 reinterpret_cast<const wgpu::Extent3D *>(&extent));
46}
47
49 if (activeCanvas) return getPixelImpl(static_cast<OffscreenCanvas *>(activeCanvas), x, y);
50 if ((screenReadbackEnabled && presentedReadback) || !sceneColorSlots.empty()) {
51 return getPixelImpl(nullptr, x, y);
52 }
53 return clearColor;
54}
55
57 if (activeCanvas) return newImageDataImpl(static_cast<OffscreenCanvas *>(activeCanvas));
58 if (screenReadbackEnabled && (!surfaceCanCopySrc || !presentedReadback))
59 throw Exception("WebGPU: no presented frame is available for screen readback");
60 if ((screenReadbackEnabled && presentedReadback) || !sceneColorSlots.empty()) return newImageDataImpl(nullptr);
61 return new image::ImageData(1, 1, "RGBA8");
62}
63
64// ---------------------------------------------------------------------------
65// Readback
66// ---------------------------------------------------------------------------
67
68namespace {
69
70bool copyTextureToCpu(wgpu::Instance &instance, wgpu::Device &device, wgpu::Queue &queue, wgpu::Texture src, int width,
71 int height, std::vector<uint8_t> &outRgba, int bytesPerPixel = 4) {
72 if (!src) return false;
73 uint64_t bytesPerRow = static_cast<uint64_t>(width) * bytesPerPixel;
74 bytesPerRow = (bytesPerRow + 255) / 256 * 256; // copy alignment 256
75 uint64_t size = bytesPerRow * height;
76
77 WGPUBufferDescriptor bd{};
78 bd.label = sv("eve_readback");
79 bd.size = size;
80 bd.usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_MapRead;
81 bd.mappedAtCreation = false;
82 wgpu::Buffer dst = device.CreateBuffer(reinterpret_cast<const wgpu::BufferDescriptor *>(&bd));
83
84 wgpu::CommandEncoder enc = device.CreateCommandEncoder();
85 WGPUTexelCopyTextureInfo from{};
86 from.texture = src.Get();
87 from.mipLevel = 0;
88 from.aspect = WGPUTextureAspect_All;
89 from.origin = {0, 0, 0};
90 WGPUTexelCopyBufferInfo to{};
91 to.buffer = dst.Get();
92 to.layout.offset = 0;
93 to.layout.bytesPerRow = static_cast<uint32_t>(bytesPerRow);
94 to.layout.rowsPerImage = static_cast<uint32_t>(height);
95 WGPUExtent3D extent{static_cast<uint32_t>(width), static_cast<uint32_t>(height), 1};
96 enc.CopyTextureToBuffer(reinterpret_cast<const wgpu::TexelCopyTextureInfo *>(&from),
97 reinterpret_cast<const wgpu::TexelCopyBufferInfo *>(&to),
98 reinterpret_cast<const wgpu::Extent3D *>(&extent));
99 wgpu::CommandBuffer cmd = enc.Finish();
100 queue.Submit(1, &cmd);
101
102 struct MapState {
103 bool done = false;
104 bool success = false;
105 WGPUMapAsyncStatus status = WGPUMapAsyncStatus_Force32;
106 } map;
107 WGPUBufferMapCallbackInfo cbInfo{};
108#if defined(__EMSCRIPTEN__)
109 cbInfo.mode = WGPUCallbackMode_AllowProcessEvents;
110#else
111 cbInfo.mode = WGPUCallbackMode_WaitAnyOnly;
112#endif
113 cbInfo.callback = [](WGPUMapAsyncStatus status, WGPUStringView /*message*/, void *userdata1, void * /*userdata2*/) {
114 auto *state = static_cast<MapState *>(userdata1);
115 state->status = status;
116 state->success = status == WGPUMapAsyncStatus_Success;
117 state->done = true;
118 };
119 cbInfo.userdata1 = &map;
120 WGPUFuture future = wgpuBufferMapAsync(dst.Get(), WGPUMapMode_Read, 0, size, cbInfo);
121
122#if defined(__EMSCRIPTEN__)
123 int guard = 0;
124 while (!map.done && guard < 2000) {
125 emscripten_sleep(0);
126 wgpuInstanceProcessEvents(instance.Get());
127 ++guard;
128 }
129#else
130 WGPUFutureWaitInfo waitInfo{};
131 waitInfo.future = future;
132 (void)wgpuInstanceWaitAny(instance.Get(), 1, &waitInfo, UINT64_MAX);
133#endif
134 if (!map.success) {
135 std::fprintf(stderr, "[webgpu] texture readback map failed: status=%d done=%d\n", int(map.status),
136 map.done ? 1 : 0);
137 return false;
138 }
139
140 const uint8_t *data = static_cast<const uint8_t *>(dst.GetConstMappedRange(0, size));
141 if (!data) return false;
142 const size_t tightRowBytes = static_cast<size_t>(width) * bytesPerPixel;
143 outRgba.resize(tightRowBytes * height);
144 for (int y = 0; y < height; ++y)
145 std::memcpy(outRgba.data() + size_t(y) * tightRowBytes, data + size_t(y) * bytesPerRow, tightRowBytes);
146 dst.Unmap();
147 return true;
148}
149
150float decodeHalf(uint16_t value) {
151 const uint32_t sign = uint32_t(value & 0x8000u) << 16u;
152 uint32_t exponent = (value >> 10u) & 0x1fu;
153 uint32_t mantissa = value & 0x03ffu;
154 uint32_t bits = 0;
155 if (exponent == 0) {
156 if (mantissa == 0) {
157 bits = sign;
158 } else {
159 exponent = 1;
160 while ((mantissa & 0x0400u) == 0) {
161 mantissa <<= 1u;
162 --exponent;
163 }
164 mantissa &= 0x03ffu;
165 bits = sign | ((exponent + 112u) << 23u) | (mantissa << 13u);
166 }
167 } else if (exponent == 31u) {
168 bits = sign | 0x7f800000u | (mantissa << 13u);
169 } else {
170 bits = sign | ((exponent + 112u) << 23u) | (mantissa << 13u);
171 }
172 float result = 0.f;
173 std::memcpy(&result, &bits, sizeof(result));
174 return result;
175}
176
177float hdrToDisplay(float value) {
178 const float linear = std::max(value, 0.f);
179 const float mapped =
180 std::clamp((linear * (2.51f * linear + 0.03f)) / (linear * (2.43f * linear + 0.59f) + 0.14f), 0.f, 1.f);
181 return mapped <= 0.0031308f ? mapped * 12.92f : 1.055f * std::pow(mapped, 1.f / 2.4f) - 0.055f;
182}
183
184Color hdrPixelToColor(const uint8_t *pixel) {
185 uint16_t channels[4]{};
186 std::memcpy(channels, pixel, sizeof(channels));
187 return Color(hdrToDisplay(decodeHalf(channels[0])), hdrToDisplay(decodeHalf(channels[1])),
188 hdrToDisplay(decodeHalf(channels[2])), std::clamp(decodeHalf(channels[3]), 0.f, 1.f));
189}
190
191} // namespace
192
194 const bool presented = !canvas && screenReadbackEnabled && presentedReadback;
195 const bool bgra = presented && (presentedReadbackFormat == WGPUTextureFormat_BGRA8Unorm ||
196 presentedReadbackFormat == WGPUTextureFormat_BGRA8UnormSrgb);
197 int w = presented ? presentedReadbackW : canvas ? canvas->getWidth() : (sceneColorWidth > 0 ? sceneColorWidth : 1);
198 int h = presented ? presentedReadbackH
199 : canvas ? canvas->getHeight()
200 : (sceneColorHeight > 0 ? sceneColorHeight : 1);
201 if (x < 0 || y < 0 || x >= w || y >= h) return Color(0.f, 0.f, 0.f, 0.f);
202 std::vector<uint8_t> rgba;
203 wgpu::Texture src = presented ? presentedReadback
204 : canvas ? canvas->color
205 : (sceneColorSlots.empty() ? nullptr : sceneColorSlots[lastPresentSlot].color);
206 const bool hdrScene = !presented && canvas == nullptr && sceneColorFormat == WGPUTextureFormat_RGBA16Float;
207 if (!src || !copyTextureToCpu(instance, device, queue, src, w, h, rgba, hdrScene ? 8 : 4)) return clearColor;
208 if (hdrScene) return hdrPixelToColor(rgba.data() + (size_t(y) * w + x) * 8);
209 const uint8_t *p = rgba.data() + (size_t(y) * w + x) * 4;
210 return Color(p[bgra ? 2 : 0] / 255.f, p[1] / 255.f, p[bgra ? 0 : 2] / 255.f, p[3] / 255.f);
211}
212
214 const bool presented = !canvas && screenReadbackEnabled && presentedReadback;
215 const bool bgra = presented && (presentedReadbackFormat == WGPUTextureFormat_BGRA8Unorm ||
216 presentedReadbackFormat == WGPUTextureFormat_BGRA8UnormSrgb);
217 int w = presented ? presentedReadbackW : canvas ? canvas->getWidth() : (sceneColorWidth > 0 ? sceneColorWidth : 1);
218 int h = presented ? presentedReadbackH
219 : canvas ? canvas->getHeight()
220 : (sceneColorHeight > 0 ? sceneColorHeight : 1);
221 auto img = std::make_unique<image::ImageData>(w, h, "RGBA8");
222 std::vector<uint8_t> rgba;
223 wgpu::Texture src = presented ? presentedReadback
224 : canvas ? canvas->color
225 : (sceneColorSlots.empty() ? nullptr : sceneColorSlots[lastPresentSlot].color);
226 const bool hdrScene = !presented && canvas == nullptr && sceneColorFormat == WGPUTextureFormat_RGBA16Float;
227 if (src && copyTextureToCpu(instance, device, queue, src, w, h, rgba, hdrScene ? 8 : 4)) {
228 if (!hdrScene) {
229 if (bgra)
230 for (size_t pixel = 0; pixel < size_t(w) * h; ++pixel) std::swap(rgba[pixel * 4], rgba[pixel * 4 + 2]);
231 std::memcpy(img->getData(), rgba.data(), rgba.size());
232 } else {
233 auto *dst = static_cast<uint8_t *>(img->getData());
234 for (size_t pixel = 0; pixel < size_t(w) * h; ++pixel) {
235 const Color color = hdrPixelToColor(rgba.data() + pixel * 8);
236 dst[pixel * 4 + 0] = uint8_t(std::clamp(color.r * 255.f, 0.f, 255.f));
237 dst[pixel * 4 + 1] = uint8_t(std::clamp(color.g * 255.f, 0.f, 255.f));
238 dst[pixel * 4 + 2] = uint8_t(std::clamp(color.b * 255.f, 0.f, 255.f));
239 dst[pixel * 4 + 3] = uint8_t(std::clamp(color.a * 255.f, 0.f, 255.f));
240 }
241 }
242 } else {
243 throw Exception("WebGPU: texture readback failed");
244 }
245 return img.release();
246}
247
249 if (!canvas || !canvas->hdr) return nullptr;
250 const int w = canvas->getWidth();
251 const int h = canvas->getHeight();
252 std::vector<uint8_t> rgba16f;
253 if (!copyTextureToCpu(instance, device, queue, canvas->color, w, h, rgba16f, 8)) return nullptr;
254 auto *img = new image::ImageData(w, h, "RGBA16F");
255 std::memcpy(img->getData(), rgba16f.data(), rgba16f.size());
256 return img;
257}
258
259image::ImageData *Graphics::readGBufferToImageData(const std::string &attachment) {
260 submitPendingDeferredPasses();
261 if (!device || gbufferSlots.empty() || gbufferWidth <= 0 || gbufferHeight <= 0) return nullptr;
262 GbufferSlot &slot = gbufferSlots[std::min<size_t>(lastGbufferSlot, gbufferSlots.size() - 1)];
263 wgpu::Texture src;
264 if (attachment == "depth")
265 src = slot.depthColor;
266 else if (attachment == "normal")
267 src = slot.normal;
268 else if (attachment == "albedo")
269 src = slot.albedo;
270 else if (attachment == "pbrParams")
271 src = slot.pbrParams;
272 else if (attachment == "emissive")
273 src = slot.emissive;
274 else
275 return nullptr;
276
277 std::vector<uint8_t> rgba;
278 const bool hdr = attachment == "emissive";
279 if (!copyTextureToCpu(instance, device, queue, src, gbufferWidth, gbufferHeight, rgba, hdr ? 8 : 4)) return nullptr;
280 if (hdr) {
281 const size_t channels = size_t(gbufferWidth) * size_t(gbufferHeight) * 4;
282 for (size_t i = 0; i < channels; ++i) {
283 uint16_t half;
284 std::memcpy(&half, rgba.data() + i * 2, sizeof(half));
285 rgba[i] = uint8_t(std::lround(std::clamp(glm::unpackHalf1x16(half), 0.f, 1.f) * 255.f));
286 }
287 rgba.resize(channels);
288 }
289 auto *image = new image::ImageData(gbufferWidth, gbufferHeight, "RGBA8");
290 std::memcpy(image->getData(), rgba.data(), rgba.size());
291 if (attachment == "depth") {
292 // Mirror Vulkan readback: expose linear depth as grayscale (G/B hold velocity on GPU).
293 auto* pixels = static_cast<uint8_t*>(image->getData());
294 const size_t pixelCount = size_t(gbufferWidth) * size_t(gbufferHeight);
295 for (size_t i = 0; i < pixelCount; ++i) {
296 pixels[i * 4u + 1u] = pixels[i * 4u];
297 pixels[i * 4u + 2u] = pixels[i * 4u];
298 }
299 }
300 return image;
301}
302
304 submitPendingDeferredPasses();
305 if (!device || decalSlots.empty() || decalWidth <= 0 || decalHeight <= 0) return nullptr;
306 DecalSlot &slot = decalSlots[std::min<size_t>(lastDecalSlot, decalSlots.size() - 1)];
307 wgpu::Texture src;
308 if (attachment == "albedo")
309 src = slot.albedo;
310 else if (attachment == "normal")
311 src = slot.normal;
312 else if (attachment == "params")
313 src = slot.params;
314 else
315 return nullptr;
316 std::vector<uint8_t> rgba;
317 if (!copyTextureToCpu(instance, device, queue, src, decalWidth, decalHeight, rgba)) return nullptr;
318 auto *image = new image::ImageData(decalWidth, decalHeight, "RGBA8");
319 std::memcpy(image->getData(), rgba.data(), rgba.size());
320 return image;
321}
322
323// ---------------------------------------------------------------------------
324// Async frame readback (browser)
325// ---------------------------------------------------------------------------
326
327namespace {
328
329bool encodeRgbaToPng(const std::string &path, int width, int height, const std::vector<uint8_t> &rgba) {
330 try {
331 image::ImageData img(width, height, "RGBA8");
332 std::memcpy(img.getData(), rgba.data(), rgba.size());
333 std::unique_ptr<eve::filesystem::FileData> png(
334 img.encode(medialoader::FormatHandler::ENCODED_PNG, path.c_str(), false));
335 if (!png) return false;
336 std::ofstream out(path, std::ios::binary);
337 if (!out) return false;
338 out.write(static_cast<const char *>(png->getData()), static_cast<std::streamsize>(png->getSize()));
339 return out.good();
340 } catch (...) {
341 return false;
342 }
343}
344
345} // namespace
346
347bool Graphics::beginFrameReadback(const std::string &path) {
348 // A finished readback can be replaced; only refuse while one is in flight.
349 if ((pendingReadback_ && !pendingReadback_->done) || !device) return false;
350 const bool presented = screenReadbackEnabled && presentedReadback;
351 wgpu::Texture src = presented ? presentedReadback : lastReadbackTex;
352 int w = presented ? presentedReadbackW : lastReadbackW;
353 int h = presented ? presentedReadbackH : lastReadbackH;
354 if (!src || w <= 0 || h <= 0) {
355 // Fall back to the scene color slot before anything was rendered.
356 if (sceneColorSlots.empty()) return false;
357 const uint32_t slot = lastPresentSlot;
358 if (slot >= sceneColorSlots.size()) return false;
359 src = sceneColorSlots[slot].color;
360 w = sceneColorWidth;
361 h = sceneColorHeight;
362 if (!src || w <= 0 || h <= 0) return false;
363 }
364
365 const bool hdr = src.GetFormat() == wgpu::TextureFormat::RGBA16Float;
366 const bool bgra =
367 src.GetFormat() == wgpu::TextureFormat::BGRA8Unorm || src.GetFormat() == wgpu::TextureFormat::BGRA8UnormSrgb;
368 uint64_t bytesPerRow = static_cast<uint64_t>(w * (hdr ? 8 : 4));
369 bytesPerRow = (bytesPerRow + 255) / 256 * 256;
370 const uint64_t size = bytesPerRow * static_cast<uint64_t>(h);
371
372 WGPUBufferDescriptor bd{};
373 bd.label = sv("eve_readback");
374 bd.size = size;
375 bd.usage = WGPUBufferUsage_CopyDst | WGPUBufferUsage_MapRead;
376 bd.mappedAtCreation = false;
377 wgpu::Buffer dst = device.CreateBuffer(reinterpret_cast<const wgpu::BufferDescriptor *>(&bd));
378 if (!dst) return false;
379
380 // Copy the resolved scene color into the readback buffer, then map
381 // asynchronously (two-phase: the pump waits for the map callback on the
382 // browser event loop without ASYNCIFY sleeps).
383 wgpu::CommandEncoder enc = device.CreateCommandEncoder();
384 WGPUTexelCopyTextureInfo from{};
385 from.texture = src.Get();
386 from.mipLevel = 0;
387 from.aspect = WGPUTextureAspect_All;
388 from.origin = {0, 0, 0};
389 WGPUTexelCopyBufferInfo to{};
390 to.buffer = dst.Get();
391 to.layout.offset = 0;
392 to.layout.bytesPerRow = static_cast<uint32_t>(bytesPerRow);
393 to.layout.rowsPerImage = static_cast<uint32_t>(h);
394 WGPUExtent3D extent{static_cast<uint32_t>(w), static_cast<uint32_t>(h), 1};
395 enc.CopyTextureToBuffer(reinterpret_cast<const wgpu::TexelCopyTextureInfo *>(&from),
396 reinterpret_cast<const wgpu::TexelCopyBufferInfo *>(&to),
397 reinterpret_cast<const wgpu::Extent3D *>(&extent));
398 wgpu::CommandBuffer cmd = enc.Finish();
399 queue.Submit(1, &cmd);
400
401 auto pr = std::make_unique<PendingReadback>();
402 pr->path = path;
403 pr->width = w;
404 pr->height = h;
405 pr->bytesPerRow = bytesPerRow;
406 pr->dst = dst;
407 pr->hdr = hdr;
408 pr->bgra = bgra;
409
410 WGPUBufferMapCallbackInfo cbInfo{};
411 cbInfo.mode = WGPUCallbackMode_AllowSpontaneous;
412 cbInfo.callback = [](WGPUMapAsyncStatus status, WGPUStringView /*message*/, void *userdata1, void * /*userdata2*/) {
413 auto *p = static_cast<PendingReadback *>(userdata1);
414 p->mapped = (status == WGPUMapAsyncStatus_Success);
415 };
416 cbInfo.userdata1 = pr.get();
417 wgpuBufferMapAsync(dst.Get(), WGPUMapMode_Read, 0, size, cbInfo);
418
419 pendingReadback_ = std::move(pr);
420 return true;
421}
422
424 if (!pendingReadback_) return 0;
425 if (!pendingReadback_->done) return 1;
426 return pendingReadback_->ok ? 2 : 3;
427}
428
430 if (!pendingReadback_ || pendingReadback_->done) return;
431 auto &pr = *pendingReadback_;
432 if (!pr.mapped) {
433 // The map callback is delivered on the browser event loop between
434 // frames (emdawnwebgpu callUserCallback), so no ASYNCIFY sleep is
435 // needed here �?this runs from present() on the main loop.
436#if defined(__EMSCRIPTEN__)
437 wgpuInstanceProcessEvents(instance.Get());
438#endif
439 return;
440 }
441 const uint8_t *data =
442 static_cast<const uint8_t *>(pr.dst.GetConstMappedRange(0, pr.bytesPerRow * static_cast<uint64_t>(pr.height)));
443 std::vector<uint8_t> rgba(static_cast<size_t>(pr.width) * pr.height * 4);
444 if (data) {
445 for (int y = 0; y < pr.height; ++y) {
446 auto *dst = rgba.data() + size_t(y) * pr.width * 4;
447 const auto *row = data + size_t(y) * pr.bytesPerRow;
448 for (int x = 0; x < pr.width; ++x) {
449 if (pr.hdr) {
450 const auto color = hdrPixelToColor(row + size_t(x) * 8);
451 dst[x * 4] = uint8_t(std::clamp(color.r * 255.f, 0.f, 255.f));
452 dst[x * 4 + 1] = uint8_t(std::clamp(color.g * 255.f, 0.f, 255.f));
453 dst[x * 4 + 2] = uint8_t(std::clamp(color.b * 255.f, 0.f, 255.f));
454 dst[x * 4 + 3] = uint8_t(std::clamp(color.a * 255.f, 0.f, 255.f));
455 } else {
456 dst[x * 4] = row[x * 4 + (pr.bgra ? 2 : 0)];
457 dst[x * 4 + 1] = row[x * 4 + 1];
458 dst[x * 4 + 2] = row[x * 4 + (pr.bgra ? 0 : 2)];
459 dst[x * 4 + 3] = row[x * 4 + 3];
460 }
461 }
462 }
463 }
464 pr.dst.Unmap();
465 pr.ok = data && encodeRgbaToPng(pr.path, pr.width, pr.height, rgba);
466 pr.done = true;
467}
468
469
470} // namespace eve::graphics::webgpu
double y
double x
float w
Definition AnimClip.cpp:738
std::map< std::string, std::vector< Key >, std::less<> > channels
glm::vec4 p[6]
scene::NodeDesc desc
float linear
vkb::Device & device
vk::UniqueImage image
wgpu::PopErrorScopeStatus status
int h
std::uint32_t height
std::uint32_t width
std::string to
std::string from
std::future< JobOutput > future
Poco::JSON::Object::Ptr result
bool done
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
uint8_t * pixels
std::string slot
ScriptStructure out
float size
Definition TreeMesh.cpp:158
EVENGINE_API_FOUNDATION public API.
Definition Exception.h:13
image::ImageData * readGBufferToImageData(const std::string &attachment) override
Reads g buffer to image data.
void pumpReadback()
Advances a pending frame readback; called every present().
Color getPixelImpl(OffscreenCanvas *canvas, int x, int y)
Blocking CPU readback of an offscreen canvas or scene color target.
image::ImageData * newImageData() override
Creates a image data. @ownership Caller deletes unless documented otherwise.
image::ImageData * newHDRImageDataImpl(OffscreenCanvas *canvas)
Blocking linear RGBA16F readback of an HDR offscreen canvas. @ownership The caller owns the returned ...
bool beginFrameReadback(const std::string &path) override
Begins frame readback.
image::ImageData * newImageDataImpl(OffscreenCanvas *canvas)
Creates a image data impl. @ownership Caller deletes unless documented otherwise.
int frameReadbackStatus() const override
Frame readback status.
Color getPixel(int x, int y) override
Returns the pixel.
image::ImageData * readDecalLayerToImageData(const std::string &attachment) override
Reads decal layer to image data.
Offscreen render target (RGBA8Unorm color, optional Depth32Float). 2D batches are flushed into the ca...
Definition Canvas.h:17
int getWidth() const override
Returns the width.
Definition Canvas.h:25
int getHeight() const override
Returns the height.
Definition Canvas.h:27
Represents raw pixel data.
Definition ImageData.h:38
WGPUStringView sv(const char *s)
Build a WGPUStringView from a C string (null-safe, length auto-computed).
Definition wgpu_types.h:20
eve::Color Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13
eve::Result< void > success()
glm::vec4 color