/* * WiVRn VR streaming * Copyright (C) 2022 Guillaume Meunier * Copyright (C) 2022 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include "vk/allocation.h" #include "vk/fwd.h" #include #include #include #include #include #include #include struct ktxVulkanDeviceInfo; struct image_loader { vk::Image image; vk::Format format; vk::Extent3D extent; vk::ImageViewType image_view_type; std::shared_ptr image_view; uint32_t num_mipmaps; image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, vk::raii::Queue & queue, vk::raii::CommandPool & cb_pool); // Load a PNG/JPEG/KTX2 file void load(std::span bytes, bool srgb); // Load raw pixel data void load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format); template void load(std::span pixels, vk::Extent3D extent, vk::Format format) { load(pixels.data(), pixels.size() * sizeof(T), extent, format); } template void load(const std::array & pixels, vk::Extent3D extent, vk::Format format) { load(pixels.data(), pixels.size() * sizeof(T), extent, format); } template void load(const std::vector & pixels, vk::Extent3D extent, vk::Format format) { load(pixels.data(), pixels.size() * sizeof(T), extent, format); } ~image_loader(); private: ktxVulkanDeviceInfo * vdi = nullptr; vk::raii::Device & device; vk::raii::Queue & queue; vk::raii::CommandPool & cb_pool; buffer_allocation staging_buffer; void do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format); void do_load_ktx(std::span bytes); void create_image_view(); };