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

Method createImage

code/26_texture_mapping.cpp:805–838  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

803 }
804
805 void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
806 VkImageCreateInfo imageInfo{};
807 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
808 imageInfo.imageType = VK_IMAGE_TYPE_2D;
809 imageInfo.extent.width = width;
810 imageInfo.extent.height = height;
811 imageInfo.extent.depth = 1;
812 imageInfo.mipLevels = 1;
813 imageInfo.arrayLayers = 1;
814 imageInfo.format = format;
815 imageInfo.tiling = tiling;
816 imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
817 imageInfo.usage = usage;
818 imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
819 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
820
821 if (vkCreateImage(device, &imageInfo, nullptr, &image) != VK_SUCCESS) {
822 throw std::runtime_error("failed to create image!");
823 }
824
825 VkMemoryRequirements memRequirements;
826 vkGetImageMemoryRequirements(device, image, &memRequirements);
827
828 VkMemoryAllocateInfo allocInfo{};
829 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
830 allocInfo.allocationSize = memRequirements.size;
831 allocInfo.memoryTypeIndex = findMemoryType(memRequirements.memoryTypeBits, properties);
832
833 if (vkAllocateMemory(device, &allocInfo, nullptr, &imageMemory) != VK_SUCCESS) {
834 throw std::runtime_error("failed to allocate image memory!");
835 }
836
837 vkBindImageMemory(device, image, imageMemory, 0);
838 }
839
840 void transitionImageLayout(VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout) {
841 VkCommandBuffer commandBuffer = beginSingleTimeCommands();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected