diff --git a/CMakeLists.txt b/CMakeLists.txt index c5c2494e..a8aecfbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 907bb2cd..ca775b78 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -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) diff --git a/client/render/image_loader.cpp b/client/render/image_loader.cpp index d43f370b..2c34e0f3 100644 --- a/client/render/image_loader.cpp +++ b/client/render/image_loader.cpp @@ -18,9 +18,12 @@ */ #include "image_loader.h" +#include "wivrn_config.h" #include +#if WIVRN_USE_LIBKTX #include +#endif #include #include #include @@ -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 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 bytes) { +#if WIVRN_USE_LIBKTX ktxTexture * texture; ktxVulkanTexture vk_texture; @@ -451,6 +461,9 @@ void image_loader::do_load_ktx(std::span bytes) }; image_view = std::shared_ptr(r, &r->image_view); +#else + throw std::runtime_error("Compiled without KTX support"); +#endif } static constexpr bool starts_with(std::span data, std::span prefix) diff --git a/client/render/image_loader.h b/client/render/image_loader.h index 6db3dd38..c8bee22d 100644 --- a/client/render/image_loader.h +++ b/client/render/image_loader.h @@ -21,6 +21,7 @@ #include "vk/allocation.h" #include "vk/fwd.h" +#include "wivrn_config.h" #include #include #include @@ -29,7 +30,9 @@ #include #include +#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; diff --git a/client/render/scene_data.h b/client/render/scene_data.h index 6f71f1a2..b51671b1 100644 --- a/client/render/scene_data.h +++ b/client/render/scene_data.h @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include diff --git a/common/wivrn_config.h.in b/common/wivrn_config.h.in index f5fbf423..bde3d523 100644 --- a/common/wivrn_config.h.in +++ b/common/wivrn_config.h.in @@ -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@"