SHARE
TWEET

Untitled

a guest Aug 12th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     VkCommandBuffer commandBuffer = beginSingleTimeCommands();
  2.     VkBuffer stagingBuffer;
  3.     VkDeviceMemory stagingBufferMemory;
  4.     VkDeviceSize imageSize = eyeDimensions.width()*eyeDimensions.height()*4;
  5.     VkMemoryRequirements memRequirements;
  6.  
  7.     createBuffer(imageSize, VK_BUFFER_USAGE_TRANSFER_SRC_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, stagingBuffer, stagingBufferMemory, memRequirements);
  8.  
  9.     capture->image().convertTo(QImage::Format_RGB888);
  10.  
  11.     const int align_mod = memRequirements.size % memRequirements.alignment;
  12.     const int aligned_size = ((memRequirements.size % memRequirements.alignment) == 0)
  13.                              ? memRequirements.size
  14.                              : (memRequirements.size + memRequirements.alignment - align_mod);
  15.  
  16.     uint *imgData = (uint*) malloc(sizeof (uint) * imageSize); // TODO: free somewhere
  17.  
  18.     memset(imgData, 0, sizeof(uint) * imageSize);
  19.  
  20.     void* data = nullptr;
  21.     vkMapMemory(graphics->openxr->vulkan->device, stagingBufferMemory, 0, imageSize, 0, &data);
  22.         memcpy(data, imgData, imageSize);
  23.     vkUnmapMemory(graphics->openxr->vulkan->device, stagingBufferMemory);
  24.  
  25.     free(imgData);
  26.  
  27.     VkBufferImageCopy region = {};
  28.     region.bufferOffset = 0;
  29.     region.bufferRowLength = graphics->vulkanImageTemplateInfo.extent.width;
  30.     region.bufferImageHeight = graphics->vulkanImageTemplateInfo.extent.height;
  31.  
  32.     region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  33.     region.imageSubresource.mipLevel = 0;
  34.     region.imageSubresource.baseArrayLayer = 0;
  35.     region.imageSubresource.layerCount = 1;
  36.  
  37.     region.imageOffset = {0, 0, 0};
  38.     region.imageExtent = graphics->vulkanImageTemplateInfo.extent;
  39.  
  40.     vkCmdCopyBufferToImage(
  41.         commandBuffer,
  42.         stagingBuffer,
  43.         *image,
  44.         VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
  45.         1,
  46.         &region
  47.     );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top