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

Method createImage

code/30_multisampling.cpp:1033–1066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1031 }
1032
1033 void createImage(uint32_t width, uint32_t height, uint32_t mipLevels, VkSampleCountFlagBits numSamples, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
1034 VkImageCreateInfo imageInfo{};
1035 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
1036 imageInfo.imageType = VK_IMAGE_TYPE_2D;
1037 imageInfo.extent.width = width;
1038 imageInfo.extent.height = height;
1039 imageInfo.extent.depth = 1;
1040 imageInfo.mipLevels = mipLevels;
1041 imageInfo.arrayLayers = 1;
1042 imageInfo.format = format;
1043 imageInfo.tiling = tiling;
1044 imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
1045 imageInfo.usage = usage;
1046 imageInfo.samples = numSamples;
1047 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
1048
1049 if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) {
1050 throw std::runtime_error("failed to create image!");
1051 }
1052
1053 VkMemoryRequirements memRequirements;
1054 vkGetImageMemoryRequirements(device, image, &memRequirements);
1055
1056 VkMemoryAllocateInfo allocInfo{};
1057 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
1058 allocInfo.allocationSize = memRequirements.size;
1059 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
1060
1061 if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
1062 throw std::runtime_error("failed to allocate image memory!");
1063 }
1064
1065 vkBindImageMemory(device, image, imageMemory, 0);
1066 }
1067
1068 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout, uint32_t mipLevels) {
1069 VkCommandBuffer commandBuffer = beginSingleTimeCommands();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected