| 1229 | } |
| 1230 | |
| 1231 | Texture ApiVulkanSample::load_texture_cubemap(const std::string &file, vkb::sg::Image::ContentType content_type) |
| 1232 | { |
| 1233 | Texture texture{}; |
| 1234 | |
| 1235 | texture.image = vkb::sg::Image::load(file, file, content_type); |
| 1236 | texture.image->create_vk_image(get_device(), VK_IMAGE_VIEW_TYPE_CUBE, VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT); |
| 1237 | |
| 1238 | const auto &queue = get_device().get_queue_by_flags(VK_QUEUE_GRAPHICS_BIT, 0); |
| 1239 | |
| 1240 | VkCommandBuffer command_buffer = get_device().create_command_buffer(VK_COMMAND_BUFFER_LEVEL_PRIMARY, true); |
| 1241 | |
| 1242 | vkb::core::BufferC stage_buffer = vkb::core::BufferC::create_staging_buffer(get_device(), texture.image->get_data()); |
| 1243 | |
| 1244 | // Setup buffer copy regions for each mip level |
| 1245 | std::vector<VkBufferImageCopy> buffer_copy_regions; |
| 1246 | |
| 1247 | auto &mipmaps = texture.image->get_mipmaps(); |
| 1248 | const auto &layers = texture.image->get_layers(); |
| 1249 | |
| 1250 | auto &offsets = texture.image->get_offsets(); |
| 1251 | |
| 1252 | for (uint32_t layer = 0; layer < layers; layer++) |
| 1253 | { |
| 1254 | for (size_t i = 0; i < mipmaps.size(); i++) |
| 1255 | { |
| 1256 | VkBufferImageCopy buffer_copy_region = {}; |
| 1257 | buffer_copy_region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 1258 | buffer_copy_region.imageSubresource.mipLevel = vkb::to_u32(i); |
| 1259 | buffer_copy_region.imageSubresource.baseArrayLayer = layer; |
| 1260 | buffer_copy_region.imageSubresource.layerCount = 1; |
| 1261 | buffer_copy_region.imageExtent.width = texture.image->get_extent().width >> i; |
| 1262 | buffer_copy_region.imageExtent.height = texture.image->get_extent().height >> i; |
| 1263 | buffer_copy_region.imageExtent.depth = 1; |
| 1264 | buffer_copy_region.bufferOffset = offsets[layer][i]; |
| 1265 | |
| 1266 | buffer_copy_regions.push_back(buffer_copy_region); |
| 1267 | } |
| 1268 | } |
| 1269 | |
| 1270 | VkImageSubresourceRange subresource_range = {}; |
| 1271 | subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT; |
| 1272 | subresource_range.baseMipLevel = 0; |
| 1273 | subresource_range.levelCount = vkb::to_u32(mipmaps.size()); |
| 1274 | subresource_range.layerCount = layers; |
| 1275 | |
| 1276 | // Image barrier for optimal image (target) |
| 1277 | // Optimal image will be used as destination for the copy |
| 1278 | vkb::image_layout_transition(command_buffer, |
| 1279 | texture.image->get_vk_image().get_handle(), |
| 1280 | VK_IMAGE_LAYOUT_UNDEFINED, |
| 1281 | VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, |
| 1282 | subresource_range); |
| 1283 | |
| 1284 | // Copy mip levels from staging buffer |
| 1285 | vkCmdCopyBufferToImage( |
| 1286 | command_buffer, |
| 1287 | stage_buffer.get_handle(), |
| 1288 | texture.image->get_vk_image().get_handle(), |
nothing calls this directly
no test coverage detected