@@ -13,6 +13,10 @@ void BufferDeleter::operator()(RawBuffer const& raw_buffer) const noexcept {
1313 vmaDestroyBuffer (raw_buffer.allocator , raw_buffer.buffer ,
1414 raw_buffer.allocation );
1515}
16+
17+ void ImageDeleter::operator ()(RawImage const & raw_image) const noexcept {
18+ vmaDestroyImage (raw_image.allocator , raw_image.image , raw_image.allocation );
19+ }
1620} // namespace vma
1721
1822auto vma::create_allocator (vk::Instance const instance,
@@ -130,19 +134,21 @@ auto vma::create_device_buffer(BufferCreateInfo const& create_info,
130134 return ret;
131135}
132136
133- auto vma::create_image (VmaAllocator allocator,
134- ImageCreateInfo const & create_info) -> Image {
135- if (create_info.extent .width == 0 || create_info.extent .height == 0 ) {
137+ auto vma::create_image (ImageCreateInfo const & create_info,
138+ vk::ImageUsageFlags const usage,
139+ std::uint32_t const levels, vk::Format const format,
140+ vk::Extent2D const extent) -> Image {
141+ if (extent.width == 0 || extent.height == 0 ) {
136142 std::println (stderr, " Images cannot have 0 width or height" );
137143 return {};
138144 }
139145 auto image_ci = vk::ImageCreateInfo{};
140146 image_ci.setImageType (vk::ImageType::e2D)
141- .setExtent ({create_info. extent .width , create_info. extent .height , 1 })
142- .setFormat (create_info. format )
143- .setUsage (create_info. usage )
147+ .setExtent ({extent.width , extent.height , 1 })
148+ .setFormat (format)
149+ .setUsage (usage)
144150 .setArrayLayers (1 )
145- .setMipLevels (create_info. levels )
151+ .setMipLevels (levels)
146152 .setSamples (vk::SampleCountFlagBits::e1 )
147153 .setTiling (vk::ImageTiling::eOptimal)
148154 .setInitialLayout (vk::ImageLayout::eUndefined)
@@ -153,20 +159,20 @@ auto vma::create_image(VmaAllocator allocator,
153159 allocation_ci.usage = VMA_MEMORY_USAGE_AUTO;
154160 VkImage image{};
155161 VmaAllocation allocation{};
156- auto const result = vmaCreateImage (allocator, &vk_image_ci, &allocation_ci ,
157- &image, &allocation, {});
162+ auto const result = vmaCreateImage (create_info. allocator , &vk_image_ci,
163+ &allocation_ci, & image, &allocation, {});
158164 if (result != VK_SUCCESS) {
159165 std::println (stderr, " Failed to create VMA Image" );
160166 return {};
161167 }
162168
163169 return RawImage{
164- .allocator = allocator,
170+ .allocator = create_info. allocator ,
165171 .allocation = allocation,
166172 .image = image,
167- .extent = create_info. extent ,
168- .format = create_info. format ,
169- .levels = create_info. levels ,
173+ .extent = extent,
174+ .format = format,
175+ .levels = levels,
170176 };
171177}
172178} // namespace lvk
0 commit comments