2 #include "texturecube.h"
3 #include "texturecube_backend.h"
11 VulkanTextureCube::VulkanTextureCube():
12 Texture(VK_IMAGE_VIEW_TYPE_CUBE)
15 void VulkanTextureCube::fill_image_info(void *ii) const
17 const TextureCube &self = *static_cast<const TextureCube *>(this);
19 VkImageCreateInfo *image_info = static_cast<VkImageCreateInfo *>(ii);
20 image_info->flags |= VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
21 image_info->imageType = VK_IMAGE_TYPE_2D;
22 image_info->extent.width = self.size;
23 image_info->extent.height = self.size;
24 image_info->mipLevels = self.levels;
25 image_info->arrayLayers = 6;
28 void VulkanTextureCube::sub_image(unsigned face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
30 const TextureCube &self = *static_cast<const TextureCube *>(this);
32 unsigned level_size = self.get_level_size(level);
33 synchronize(face, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (x==0 && y==0 && wd==level_size && ht==level_size));
35 size_t data_size = wd*ht*get_pixel_size(storage_fmt);
36 void *staging = device.get_transfer_queue().prepare_transfer(data_size,
37 [this, face, level, x, y, wd, ht](VkCommandBuffer cmd_buf, VkBuffer staging_buf, size_t src_off){
38 const VulkanFunctions &vk = device.get_functions();
40 VkBufferImageCopy region = { };
41 region.bufferOffset = src_off;
42 region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
43 region.imageSubresource.mipLevel = level;
44 region.imageSubresource.baseArrayLayer = face;
45 region.imageSubresource.layerCount = 1;
46 region.imageOffset = { x, y, 0 };
47 region.imageExtent = { wd, ht, 1 };
48 vk.CmdCopyBufferToImage(cmd_buf, staging_buf, handle, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
51 const char *src = static_cast<const char *>(data);
52 copy(src, src+data_size, static_cast<char *>(staging));
55 size_t VulkanTextureCube::get_data_size() const