MCPcopy Create free account
hub / github.com/PacktPublishing/3D-Graphics-Rendering-Cookbook / downloadImageData

Function downloadImageData

shared/UtilsVulkan.cpp:2129–2150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2127}
2128
2129bool downloadImageData(VulkanRenderDevice& vkDev, VkImage& textureImage, uint32_t texWidth, uint32_t texHeight, VkFormat texFormat, uint32_t layerCount, void* imageData, VkImageLayout sourceImageLayout)
2130{
2131 uint32_t bytesPerPixel = bytesPerTexFormat(texFormat);
2132
2133 VkDeviceSize layerSize = texWidth * texHeight * bytesPerPixel;
2134 VkDeviceSize imageSize = layerSize * layerCount;
2135
2136 VkBuffer stagingBuffer;
2137 VkDeviceMemory stagingBufferMemory;
2138 createBuffer(vkDev.device, vkDev.physicalDevice, imageSize, VK_BUFFER_USAGE_TRANSFER_DST_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, stagingBuffer, stagingBufferMemory);
2139
2140 transitionImageLayout(vkDev, textureImage, texFormat, sourceImageLayout, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, layerCount);
2141 copyImageToBuffer(vkDev, textureImage, stagingBuffer, static_cast<uint32_t>(texWidth), static_cast<uint32_t>(texHeight), layerCount);
2142 transitionImageLayout(vkDev, textureImage, texFormat, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, sourceImageLayout, layerCount);
2143
2144 downloadBufferData(vkDev, stagingBufferMemory, 0, imageData, imageSize);
2145
2146 vkDestroyBuffer(vkDev.device, stagingBuffer, nullptr);
2147 vkFreeMemory(vkDev.device, stagingBufferMemory, nullptr);
2148
2149 return true;
2150}
2151
2152bool createDepthResources(VulkanRenderDevice& vkDev, uint32_t width, uint32_t height, VulkanImage& depth)
2153{

Callers 1

downloadImageMethod · 0.85

Calls 5

bytesPerTexFormatFunction · 0.85
createBufferFunction · 0.85
transitionImageLayoutFunction · 0.85
copyImageToBufferFunction · 0.85
downloadBufferDataFunction · 0.85

Tested by

no test coverage detected