]> git.tdb.fi Git - libs/gl.git/blob - source/backends/vulkan/texturecube_backend.cpp
38348f34b8636abd0b09e0e3c478fd694abccaea
[libs/gl.git] / source / backends / vulkan / texturecube_backend.cpp
1 #include "device.h"
2 #include "texturecube.h"
3 #include "texturecube_backend.h"
4 #include "vulkan.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace GL {
10
11 VulkanTextureCube::VulkanTextureCube():
12         Texture(VK_IMAGE_VIEW_TYPE_CUBE)
13 { }
14
15 void VulkanTextureCube::fill_image_info(void *ii) const
16 {
17         const TextureCube &self = *static_cast<const TextureCube *>(this);
18
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;
26 }
27
28 void VulkanTextureCube::sub_image(unsigned face, unsigned level, int x, int y, unsigned wd, unsigned ht, const void *data)
29 {
30         const TextureCube &self = *static_cast<const TextureCube *>(this);
31
32         unsigned level_size = self.get_level_size(level);
33         change_layout(self.levels, level, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, (x==0 && y==0 && wd==level_size && ht==level_size));
34
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();
39
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, &region);
49                 });
50
51         const char *src = static_cast<const char *>(data);
52         copy(src, src+data_size, static_cast<char *>(staging));
53 }
54
55 size_t VulkanTextureCube::get_data_size() const
56 {
57         return 0;
58 }
59
60 } // namespace GL
61 } // namespace Msp