MCPcopy Create free account
hub / github.com/ZDoom/Raze / CopyScreenToBuffer

Method CopyScreenToBuffer

source/common/rendering/vulkan/system/vk_renderdevice.cpp:385–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385void VulkanRenderDevice::CopyScreenToBuffer(int w, int h, uint8_t *data)
386{
387 VkTextureImage image;
388
389 // Convert from rgba16f to rgba8 using the GPU:
390 image.Image = ImageBuilder()
391 .Format(VK_FORMAT_R8G8B8A8_UNORM)
392 .Usage(VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT)
393 .Size(w, h)
394 .DebugName("CopyScreenToBuffer")
395 .Create(device.get());
396
397 GetPostprocess()->BlitCurrentToImage(&image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
398
399 // Staging buffer for download
400 auto staging = BufferBuilder()
401 .Size(w * h * 4)
402 .Usage(VK_BUFFER_USAGE_TRANSFER_DST_BIT, VMA_MEMORY_USAGE_GPU_TO_CPU)
403 .DebugName("CopyScreenToBuffer")
404 .Create(device.get());
405
406 // Copy from image to buffer
407 VkBufferImageCopy region = {};
408 region.imageExtent.width = w;
409 region.imageExtent.height = h;
410 region.imageExtent.depth = 1;
411 region.imageSubresource.layerCount = 1;
412 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
413 mCommands->GetDrawCommands()->copyImageToBuffer(image.Image->image, image.Layout, staging->buffer, 1, &region);
414
415 // Submit command buffers and wait for device to finish the work
416 mCommands->WaitForCommands(false);
417
418 // Map and convert from rgba8 to rgb8
419 uint8_t *dest = (uint8_t*)data;
420 uint8_t *pixels = (uint8_t*)staging->Map(0, w * h * 4);
421 int dindex = 0;
422 for (int y = 0; y < h; y++)
423 {
424 int sindex = (h - y - 1) * w * 4;
425 for (int x = 0; x < w; x++)
426 {
427 dest[dindex] = pixels[sindex];
428 dest[dindex + 1] = pixels[sindex + 1];
429 dest[dindex + 2] = pixels[sindex + 2];
430 dindex += 3;
431 sindex += 4;
432 }
433 }
434 staging->Unmap();
435}
436
437void VulkanRenderDevice::SetActiveRenderTarget()
438{

Callers

nothing calls this directly

Calls 12

ImageBuilderClass · 0.85
BufferBuilderClass · 0.85
BlitCurrentToImageMethod · 0.80
copyImageToBufferMethod · 0.80
GetDrawCommandsMethod · 0.80
CreateMethod · 0.45
SizeMethod · 0.45
FormatMethod · 0.45
getMethod · 0.45
WaitForCommandsMethod · 0.45
MapMethod · 0.45
UnmapMethod · 0.45

Tested by

no test coverage detected