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
+12
View File
@@ -23,6 +23,7 @@ option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
auto_option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" AUTO)
auto_option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" AUTO)
auto_option(WIVRN_USE_SYSTEMD "Use libsystemd" AUTO)
auto_option(WIVRN_USE_LIBKTX "Use libktx" AUTO)
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
option(WIVRN_BUILD_CLIENT "Build WiVRn client" OFF)
option(WIVRN_BUILD_SERVER "Build WiVRn server" ON)
@@ -195,6 +196,16 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD)
find_program(RSVG_CONVERT rsvg-convert REQUIRED)
endif()
if (WIVRN_BUILD_CLIENT)
if (WIVRN_USE_LIBKTX STREQUAL "AUTO")
if (ANDROID)
set(WIVRN_USE_LIBKTX ON)
else()
set(WIVRN_USE_LIBKTX OFF)
endif()
endif()
endif()
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
find_package(Fontconfig REQUIRED)
@@ -204,6 +215,7 @@ if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
elseif(WIVRN_USE_SYSTEM_OPENXR STREQUAL "ON")
find_package(OpenXR 1.0.26 REQUIRED)
endif()
endif()
if(ANDROID)
+11 -2
View File
@@ -7,7 +7,11 @@ set(KTX_FEATURE_LOADTEST_APPS OFF)
set(FASTGLTF_COMPILE_AS_CPP20 ON)
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb libktx implot uni-algo)
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo)
if (WIVRN_USE_LIBKTX)
FetchContent_MakeAvailable(libktx)
endif()
if (NOT BOOST_FOUND)
FetchContent_MakeAvailable(boost)
@@ -84,7 +88,12 @@ file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "*.glsl")
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
wivrn_compile_glsl(wivrn ${VULKAN_SHADERS})
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb ktx_read Boost::locale)
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm fastgltf FreetypeHarfbuzz stb Boost::locale)
if (WIVRN_USE_LIBKTX)
target_link_libraries(wivrn ktx_read)
endif()
target_compile_definitions(wivrn PRIVATE -DXR_USE_GRAPHICS_API_VULKAN)
target_compile_definitions(wivrn PRIVATE -DVMA_STATS_STRING_ENABLED=0)
target_compile_definitions(wivrn PRIVATE -DGLM_ENABLE_EXPERIMENTAL)
+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>
+1
View File
@@ -34,6 +34,7 @@
#cmakedefine01 WIVRN_SHOW_IMGUI_DEMO_WINDOW
#cmakedefine01 WIVRN_CLIENT_DEBUG_MENU
#cmakedefine01 WIVRN_USE_LIBKTX
#define WIVRN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#define OPENCOMPOSITE_SEARCH_PATH "@OPENCOMPOSITE_SEARCH_PATH@"