Allow building without downloading libktx

This commit is contained in:
Guillaume Meunier
2025-01-15 21:25:35 +01:00
parent 88e7eb3c73
commit 4c0c47f807
6 changed files with 42 additions and 3 deletions
+13
View File
@@ -18,9 +18,12 @@
*/
#include "image_loader.h"
#include "wivrn_config.h"
#include <cstdint>
#if WIVRN_USE_LIBKTX
#include <ktxvulkan.h>
#endif
#include <memory>
#include <span>
#include <spdlog/spdlog.h>
@@ -48,6 +51,7 @@ struct image_resources
vk::raii::ImageView image_view = nullptr;
};
#if WIVRN_USE_LIBKTX
struct ktx_image_resources
{
ktxVulkanTexture ktx_texture;
@@ -63,6 +67,7 @@ struct ktx_image_resources
ktxVulkanTexture_Destruct(&ktx_texture, device, nullptr);
}
};
#endif
template <typename T>
constexpr vk::Format formats[4] = {vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined};
@@ -160,13 +165,17 @@ image_loader::image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::D
queue(queue),
cb_pool(cb_pool)
{
#if WIVRN_USE_LIBKTX
vdi = ktxVulkanDeviceInfo_Create(*physical_device, *device, *queue, *cb_pool, nullptr);
#endif
}
image_loader::~image_loader()
{
#if WIVRN_USE_LIBKTX
if (vdi)
ktxVulkanDeviceInfo_Destroy(vdi);
#endif
}
void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format)
@@ -397,6 +406,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
void image_loader::do_load_ktx(std::span<const std::byte> bytes)
{
#if WIVRN_USE_LIBKTX
ktxTexture * texture;
ktxVulkanTexture vk_texture;
@@ -451,6 +461,9 @@ void image_loader::do_load_ktx(std::span<const std::byte> bytes)
};
image_view = std::shared_ptr<vk::raii::ImageView>(r, &r->image_view);
#else
throw std::runtime_error("Compiled without KTX support");
#endif
}
static constexpr bool starts_with(std::span<const std::byte> data, std::span<const uint8_t> prefix)
+5
View File
@@ -21,6 +21,7 @@
#include "vk/allocation.h"
#include "vk/fwd.h"
#include "wivrn_config.h"
#include <cstddef>
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
@@ -29,7 +30,9 @@
#include <span>
#include <vulkan/vulkan.hpp>
#if WIVRN_USE_LIBKTX
struct ktxVulkanDeviceInfo;
#endif
struct image_loader
{
@@ -71,7 +74,9 @@ struct image_loader
~image_loader();
private:
#if WIVRN_USE_LIBKTX
ktxVulkanDeviceInfo * vdi = nullptr;
#endif
vk::raii::Device & device;
vk::raii::Queue & queue;
-1
View File
@@ -28,7 +28,6 @@
#include <glm/vec2.hpp>
#include <glm/vec3.hpp>
#include <glm/vec4.hpp>
#include <ktxvulkan.h>
#include <memory>
#include <optional>
#include <string>