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

Method createImage

code/29_mipmapping.cpp:983–1016  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

981 }
982
983 void createImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
984 VkImageCreateInfo imageInfo{};
985 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
986 imageInfo.imageType = VK_IMAGE_TYPE_2D;
987 imageInfo.extent.width = width;
988 imageInfo.extent.height = height;
989 imageInfo.extent.depth = 1;
990 imageInfo.mipLevels = mipLevels;
991 imageInfo.arrayLayers = 1;
992 imageInfo.format = format;
993 imageInfo.tiling = tiling;
994 imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
995 imageInfo.usage = usage;
996 imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
997 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
998
999 if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) {
1000 throw std::runtime_error("failed to create image!");
1001 }
1002
1003 VkMemoryRequirements memRequirements;
1004 vkGetImageMemoryRequirements(device, image, &memRequirements);
1005
1006 VkMemoryAllocateInfo allocInfo{};
1007 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1008 allocInfo.allocationSize = memRequirements.size;
1009 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
1010
1011 if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
1012 throw std::runtime_error("failed to allocate image memory!");
1013 }
1014
1015 vkBindImageMemory(device, image, imageMemory, 0);
1016 }
1017
1018 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels) {
1019 VkCommandBuffer commandBuffer = beginSingleTimeCommands();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected