MCPcopy Create free account
hub / github.com/Overv/VulkanTutorial / createImage

Method createImage

code/27_depth_buffering.cpp:882–915  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

880 }
881
882 void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
883 VkImageCreateInfo imageInfo{};
884 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
885 imageInfo.imageType = VK_IMAGE_TYPE_2D;
886 imageInfo.extent.width = width;
887 imageInfo.extent.height = height;
888 imageInfo.extent.depth = 1;
889 imageInfo.mipLevels = 1;
890 imageInfo.arrayLayers = 1;
891 imageInfo.format = format;
892 imageInfo.tiling = tiling;
893 imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
894 imageInfo.usage = usage;
895 imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
896 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
897
898 if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) {
899 throw std::runtime_error("failed to create image!");
900 }
901
902 VkMemoryRequirements memRequirements;
903 vkGetImageMemoryRequirements(device, image, &memRequirements);
904
905 VkMemoryAllocateInfo allocInfo{};
906 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
907 allocInfo.allocationSize = memRequirements.size;
908 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
909
910 if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
911 throw std::runtime_error("failed to allocate image memory!");
912 }
913
914 vkBindImageMemory(device, image, imageMemory, 0);
915 }
916
917 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) {
918 VkCommandBuffer commandBuffer = beginSingleTimeCommands();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected