Move everything in the client/ subdirectory

This commit is contained in:
Guillaume Meunier
2022-11-12 19:35:14 +01:00
parent ae31d7727c
commit 019682cefd
95 changed files with 323 additions and 245 deletions
+1 -1
View File
@@ -61,7 +61,7 @@
<!-- Tell NativeActivity the name of the .so -->
<meta-data
android:name="android.app.lib_name"
android:value="WiVRn" />
android:value="wivrn" />
<!-- This filter lets the apk show up as a launchable icon. -->
+12 -181
View File
@@ -1,198 +1,29 @@
cmake_minimum_required(VERSION 3.19)
project(WiVRn VERSION 1.0 LANGUAGES C CXX)
option(USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
set(TINYGLTF_BUILD_LOADER_EXAMPLE OFF)
set(TINYGLTF_BUILD_GL_EXAMPLES OFF)
set(TINYGLTF_BUILD_VALIDATOR_EXAMPLE OFF)
set(TINYGLTF_BUILD_BUILDER_EXAMPLE OFF)
set(TINYGLTF_HEADER_ONLY OFF)
set(TINYGLTF_INSTALL OFF)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
include(FetchContent)
include(ExternalProject)
FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.10.0)
FetchContent_Declare(boostpfr
GIT_REPOSITORY https://github.com/boostorg/pfr.git
GIT_TAG 69c5692cd666b1685a5eef00a4a79ca2e6093ff0)
FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 0.9.9.8)
FetchContent_Declare(tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.6.3)
if (USE_SYSTEM_FREETYPE)
find_package(Freetype REQUIRED)
find_package(harfbuzz REQUIRED)
set(deps_freetype Freetype::Freetype harfbuzz::harfbuzz)
else()
FetchContent_Declare(
freetype
GIT_REPOSITORY https://gitlab.freedesktop.org/freetype/freetype.git
GIT_TAG VER-2-12-1
CMAKE_ARGS
-DCMAKE_BUILD_TYPE=Release
-DFT_DISABLE_ZLIB=TRUE
-DFT_DISABLE_BZIP2=TRUE
-DFT_DISABLE_PNG=TRUE
# -DFT_DISABLE_HARFBUZZ=TRUE
-DFT_REQUIRE_HARFBUZZ=TRUE
-DFT_DISABLE_BROTLI=TRUE
-DBUILD_SHARED_LIBS=TRUE)
FetchContent_Declare(
harfbuzz
# DEPENDS freetype_without_harfbuzz
GIT_REPOSITORY https://github.com/harfbuzz/harfbuzz.git
GIT_TAG 5.3.1
CMAKE_ARGS -DHB_HAVE_FREETYPE=ON)
set(deps_freetype freetype harfbuzz)
set(fetch_content freetype harfbuzz)
endif()
if(USE_ANDROID_VALIDATION_LAYER)
set(VVL_VERSION "1.3.231.1")
set(VVL_ZIPFILE ${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip)
if(NOT EXISTS ${VVL_ZIPFILE})
file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/sdk-${VVL_VERSION}/android-binaries-${VVL_VERSION}.zip
${VVL_ZIPFILE})
endif()
file(ARCHIVE_EXTRACT INPUT ${VVL_ZIPFILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer)
add_library(vvl1 SHARED IMPORTED)
set_property(TARGET vvl1 PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libVkLayer_khronos_validation.so)
add_library(vvl2 SHARED IMPORTED)
set_property(TARGET vvl2 PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so)
set(deps_vvl vvl1 vvl2) # Hack to get gradle to package the validation layer in the APK
endif()
FetchContent_MakeAvailable(spdlog boostpfr glm tinygltf ${fetch_content})
FetchContent_GetProperties(tinygltf SOURCE_DIR TinyGLTF_SOURCE_DIR)
find_package(Vulkan REQUIRED)
get_property(importTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY IMPORTED_TARGETS)
get_property(buildsystemTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY BUILDSYSTEM_TARGETS)
message("Imported targets: ${importTargets}")
message("Build system targets: ${buildsystemTargets}")
option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
option(WIVRN_USE_ANDROID_VALIDATION_LAYER "Download the android version of the Vulkan validation layer" OFF)
option(WIVRN_BUILD_CLIENT "Build WiVRn client" ON)
option(WIVRN_BUILD_SERVER "Build WiVRn server" OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(CompileGLSL)
if(ANDROID)
include(AndroidNdkModules)
android_ndk_import_module_native_app_glue()
find_library(ANDROID_LIBRARY NAMES android)
find_library(MEDIA_LIBRARY NAMES mediandk)
if(OCULUS_SDK)
add_library(OpenXR SHARED IMPORTED)
target_include_directories(OpenXR INTERFACE ${OCULUS_SDK}/3rdParty/khronos/openxr/OpenXR-SDK/include)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set_property(TARGET OpenXR
PROPERTY IMPORTED_LOCATION ${OCULUS_SDK}/OpenXR/Libs/Android/${ANDROID_ABI}/Debug/libopenxr_loader.so)
else()
set_property(TARGET OpenXR
PROPERTY IMPORTED_LOCATION ${OCULUS_SDK}/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_loader.so)
endif()
else()
message(FATAL_ERROR "TODO: implement non-oculus android headsets")
endif()
add_library(${PROJECT_NAME} MODULE)
target_link_libraries(${PROJECT_NAME} ${ANDROID_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${MEDIA_LIBRARY})
target_link_libraries(${PROJECT_NAME} native_app_glue)
target_link_libraries(${PROJECT_NAME} OpenXR)
target_link_libraries(${PROJECT_NAME} Boost::pfr)
target_compile_definitions(${PROJECT_NAME} PRIVATE -DXR_USE_PLATFORM_ANDROID -DVK_USE_PLATFORM_ANDROID_KHR)
target_link_options(${PROJECT_NAME} PRIVATE -Wl,--undefined=ANativeActivity_onCreate)
file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS
"src/decoder/android/*.cpp")
target_sources(${PROJECT_NAME} PRIVATE ${PLATFORM_SOURCE})
else()
find_package(OpenXR REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil
libswscale)
add_executable(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE -DXR_USE_PLATFORM_XLIB)
target_link_libraries(${PROJECT_NAME} OpenXR::openxr_loader
OpenXR::headers PkgConfig::LIBAV)
file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS
"src/decoder/ffmpeg/*.cpp")
target_sources(${PROJECT_NAME} PRIVATE ${PLATFORM_SOURCE})
endif()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20)
target_compile_definitions(${PROJECT_NAME} PRIVATE "XR_USE_TIMESPEC=1")
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden)
add_subdirectory(common)
file(GLOB LOCAL_SOURCE CONFIGURE_DEPENDS
"src/*.cpp"
"src/decoder/*.cpp"
"src/external/*.c"
"src/scenes/*.cpp"
"src/utils/*.cpp"
"src/vk/*.cpp"
"src/xr/*.cpp"
"src/render/*.cpp")
file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "src/*.glsl")
target_sources(${PROJECT_NAME} PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
target_link_libraries(${PROJECT_NAME} Vulkan::Vulkan spdlog::spdlog glm::glm tinygltf ${deps_freetype} ${deps_vvl})
target_compile_definitions(${PROJECT_NAME} PRIVATE -DXR_USE_GRAPHICS_API_VULKAN)
target_compile_options(${PROJECT_NAME} PRIVATE -fdiagnostics-color -Wall -Wextra -pedantic) # -Werror
target_compile_options(${PROJECT_NAME} PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-volatile>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wno-deprecated-volatile>
)
target_include_directories(${PROJECT_NAME} PRIVATE src)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
execute_process(COMMAND git describe --always OUTPUT_VARIABLE GIT_VERSION)
string(STRIP ${GIT_VERSION} GIT_VERSION)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/version.h
COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/src/version.h.in
-D OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.h
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GitVersion.cmake
)
target_sources(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.h)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/vk_layer_settings.txt
"khronos_validation.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_BREAK
khronos_validation.report_flags = error,warn
khronos_validation.log_filename = stdout
khronos_validation.disables =
khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_THREAD_SAFETY_EXT
")
if (WIVRN_BUILD_CLIENT)
add_subdirectory(client)
endif()
if (WIVRN_BUILD_SERVER)
add_subdirectory(server)
endif()
compile_glsl(${PROJECT_NAME} ${VULKAN_SHADERS})
+1 -1
View File
@@ -34,7 +34,7 @@ android {
externalNativeBuild {
cmake {
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DUSE_SYSTEM_FREETYPE=OFF'
arguments '-DANDROID_TOOLCHAIN=clang', '-DANDROID_STL=c++_static', '-DCMAKE_EXPORT_COMPILE_COMMANDS=ON', '-DWIVRN_USE_SYSTEM_FREETYPE=OFF', '-DWIVRN_BUILD_CLIENT=ON', '-DWIVRN_BUILD_SERVER=OFF'
resValue "string", "app_name", "WiVRn"
}
}
+229
View File
@@ -0,0 +1,229 @@
set(TINYGLTF_BUILD_LOADER_EXAMPLE OFF)
set(TINYGLTF_BUILD_GL_EXAMPLES OFF)
set(TINYGLTF_BUILD_VALIDATOR_EXAMPLE OFF)
set(TINYGLTF_BUILD_BUILDER_EXAMPLE OFF)
set(TINYGLTF_HEADER_ONLY OFF)
set(TINYGLTF_INSTALL OFF)
FetchContent_Declare(spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.10.0)
FetchContent_Declare(boostpfr
GIT_REPOSITORY https://github.com/boostorg/pfr.git
GIT_TAG 69c5692cd666b1685a5eef00a4a79ca2e6093ff0)
FetchContent_Declare(glm
GIT_REPOSITORY https://github.com/g-truc/glm.git
GIT_TAG 0.9.9.8)
FetchContent_Declare(tinygltf
GIT_REPOSITORY https://github.com/syoyo/tinygltf.git
GIT_TAG v2.6.3)
if (USE_SYSTEM_FREETYPE)
find_package(Freetype REQUIRED)
find_package(harfbuzz REQUIRED)
set(deps_freetype Freetype::Freetype harfbuzz::harfbuzz)
else()
set(HARFBUZZ_VERSION 5.3.1)
set(FREETYPE_VERSION 2.12.1)
if(NOT EXISTS ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
if (EXISTS ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz SYMBOLIC)
else()
file(DOWNLOAD https://download.savannah.gnu.org/releases/freetype/freetype-${FREETYPE_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}.tar.xz)
endif()
endif()
if(NOT EXISTS ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz)
if (EXISTS ${CMAKE_SOURCE_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz)
file(CREATE_LINK ${CMAKE_SOURCE_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz SYMBOLIC)
else()
file(DOWNLOAD https://github.com/harfbuzz/harfbuzz/releases/download/${HARFBUZZ_VERSION}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz ${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}.tar.xz)
endif()
endif()
file(ARCHIVE_EXTRACT INPUT freetype-${FREETYPE_VERSION}.tar.xz DESTINATION ${CMAKE_BINARY_DIR})
file(ARCHIVE_EXTRACT INPUT harfbuzz-${HARFBUZZ_VERSION}.tar.xz DESTINATION ${CMAKE_BINARY_DIR})
add_library(freetypeharfbuzz STATIC
${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}/src/harfbuzz.cc
${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}/src/hb-ft.cc
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/autofit/autofit.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftbase.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftbbox.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftbdf.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftbitmap.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftcid.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftfstype.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftgasp.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftglyph.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftgxval.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftinit.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftmm.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftotval.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftpatent.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftpfr.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftstroke.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftsynth.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/fttype1.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftwinfnt.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/bdf/bdf.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/bzip2/ftbzip2.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/cache/ftcache.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/cff/cff.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/cid/type1cid.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/gzip/ftgzip.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/lzw/ftlzw.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/pcf/pcf.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/pfr/pfr.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/psaux/psaux.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/pshinter/pshinter.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/psnames/psnames.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/raster/raster.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/sdf/sdf.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/sfnt/sfnt.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/smooth/smooth.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/svg/svg.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/truetype/truetype.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/type1/type1.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/type42/type42.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/winfonts/winfnt.c
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/src/base/ftdebug.c
)
target_sources(freetypeharfbuzz PRIVATE
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/builds/unix/ftsystem.c)
target_include_directories(freetypeharfbuzz PUBLIC
${CMAKE_BINARY_DIR}/freetype-${FREETYPE_VERSION}/include
${CMAKE_BINARY_DIR}/harfbuzz-${HARFBUZZ_VERSION}/src)
target_compile_definitions(freetypeharfbuzz PRIVATE -DFT2_BUILD_LIBRARY=1 -DHAVE_FREETYPE=1 -DHAVE_UNISTD_H=1 -DHAVE_FCNTL_H=1)
set(deps_freetype freetypeharfbuzz)
endif()
if(USE_ANDROID_VALIDATION_LAYER)
set(VVL_VERSION "1.3.231.1")
set(VVL_ZIPFILE ${CMAKE_CURRENT_SOURCE_DIR}/Vulkan-ValidationLayers-${VVL_VERSION}.zip)
if(NOT EXISTS ${VVL_ZIPFILE})
file(DOWNLOAD https://github.com/KhronosGroup/Vulkan-ValidationLayers/releases/download/sdk-${VVL_VERSION}/android-binaries-${VVL_VERSION}.zip
${VVL_ZIPFILE})
endif()
file(ARCHIVE_EXTRACT INPUT ${VVL_ZIPFILE} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer)
add_library(vvl1 SHARED IMPORTED)
set_property(TARGET vvl1 PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libVkLayer_khronos_validation.so)
add_library(vvl2 SHARED IMPORTED)
set_property(TARGET vvl2 PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/Vulkan-ValidationLayer/${CMAKE_ANDROID_ARCH_ABI}/libc++_shared.so)
set(deps_vvl vvl1 vvl2) # Hack to get gradle to package the validation layer in the APK
endif()
FetchContent_MakeAvailable(spdlog boostpfr glm tinygltf ${fetch_content})
FetchContent_GetProperties(tinygltf SOURCE_DIR TinyGLTF_SOURCE_DIR)
find_package(Vulkan REQUIRED)
get_property(importTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY IMPORTED_TARGETS)
get_property(buildsystemTargets DIRECTORY "${CMAKE_SOURCE_DIR}" PROPERTY BUILDSYSTEM_TARGETS)
message("Imported targets: ${importTargets}")
message("Build system targets: ${buildsystemTargets}")
include(CompileGLSL)
if(ANDROID)
find_library(ANDROID_LIBRARY NAMES android)
find_library(MEDIA_LIBRARY NAMES mediandk)
if(OCULUS_SDK)
add_library(OpenXR SHARED IMPORTED)
target_include_directories(OpenXR INTERFACE ${OCULUS_SDK}/3rdParty/khronos/openxr/OpenXR-SDK/include)
if(CMAKE_BUILD_TYPE STREQUAL Debug)
set_property(TARGET OpenXR
PROPERTY IMPORTED_LOCATION ${OCULUS_SDK}/OpenXR/Libs/Android/${ANDROID_ABI}/Debug/libopenxr_loader.so)
else()
set_property(TARGET OpenXR
PROPERTY IMPORTED_LOCATION ${OCULUS_SDK}/OpenXR/Libs/Android/${ANDROID_ABI}/Release/libopenxr_loader.so)
endif()
else()
message(FATAL_ERROR "TODO: implement non-oculus android headsets")
endif()
add_library(wivrn MODULE)
target_link_libraries(wivrn ${ANDROID_LIBRARY})
target_link_libraries(wivrn ${MEDIA_LIBRARY})
target_link_libraries(wivrn native_app_glue)
target_link_libraries(wivrn OpenXR)
target_link_libraries(wivrn Boost::pfr)
target_compile_definitions(wivrn PRIVATE -DXR_USE_PLATFORM_ANDROID -DVK_USE_PLATFORM_ANDROID_KHR)
target_link_options(wivrn PRIVATE -Wl,--undefined=ANativeActivity_onCreate)
file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS
"src/decoder/android/*.cpp")
target_sources(wivrn PRIVATE ${PLATFORM_SOURCE})
else()
find_package(OpenXR REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil
libswscale)
add_executable(wivrn)
target_compile_definitions(wivrn PRIVATE -DXR_USE_PLATFORM_XLIB)
target_link_libraries(wivrn OpenXR::openxr_loader
OpenXR::headers PkgConfig::LIBAV)
file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS
"src/decoder/ffmpeg/*.cpp")
target_sources(wivrn PRIVATE ${PLATFORM_SOURCE})
endif()
target_compile_features(wivrn PRIVATE cxx_std_20)
target_compile_definitions(wivrn PRIVATE "XR_USE_TIMESPEC=1")
set_target_properties(wivrn PROPERTIES CXX_VISIBILITY_PRESET hidden)
file(GLOB LOCAL_SOURCE CONFIGURE_DEPENDS
"src/*.cpp"
"src/decoder/*.cpp"
"src/external/*.c"
"src/scenes/*.cpp"
"src/utils/*.cpp"
"src/vk/*.cpp"
"src/xr/*.cpp"
"src/render/*.cpp")
file(GLOB_RECURSE VULKAN_SHADERS CONFIGURE_DEPENDS "src/*.glsl")
target_sources(wivrn PRIVATE ${LOCAL_SOURCE} ${VULKAN_SHADERS})
target_link_libraries(wivrn Vulkan::Vulkan spdlog::spdlog glm::glm tinygltf ${deps_freetype} ${deps_vvl})
target_compile_definitions(wivrn PRIVATE -DXR_USE_GRAPHICS_API_VULKAN)
target_compile_options(wivrn PRIVATE -fdiagnostics-color -Wall -Wextra -pedantic) # -Werror
target_compile_options(wivrn PRIVATE -Wno-missing-field-initializers -Wno-unused-parameter
$<$<COMPILE_LANG_AND_ID:CXX,GNU>:-Wno-volatile>
$<$<COMPILE_LANG_AND_ID:CXX,Clang>:-Wno-deprecated-volatile>
)
target_include_directories(wivrn PRIVATE src)
target_link_libraries(wivrn wivrn-common)
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/vk_layer_settings.txt
"khronos_validation.debug_action = VK_DBG_LAYER_ACTION_LOG_MSG,VK_DBG_LAYER_ACTION_BREAK
khronos_validation.report_flags = error,warn
khronos_validation.log_filename = stdout
khronos_validation.disables =
khronos_validation.enables = VK_VALIDATION_FEATURE_ENABLE_THREAD_SAFETY_EXT
")
endif()
compile_glsl(wivrn ${VULKAN_SHADERS})
View File
View File
View File
View File
@@ -32,22 +32,8 @@
namespace xrt::drivers::wivrn
{
static const int announce_port = 9756;
static const int control_port = 9757;
static const int stream_port = 9757;
static const in6_addr announce_address = []() {
in6_addr address{};
address.s6_addr[0] = 0xff; // multicast
address.s6_addr[1] = 0x15; // not assigned by IANA, site-local
address.s6_addr[11] = 'W';
address.s6_addr[12] = 'i';
address.s6_addr[13] = 'V';
address.s6_addr[14] = 'R';
address.s6_addr[15] = 'n';
return address;
}();
enum class device_id : uint8_t
{
@@ -121,6 +121,7 @@ void xrt::drivers::wivrn::UDP::unsubscribe_multicast(in6_addr address)
throw std::system_error{errno, std::generic_category()};
}
}
void xrt::drivers::wivrn::UDP::set_receive_buffer_size(int size)
{
setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size));
@@ -187,6 +188,54 @@ xrt::drivers::wivrn::TCP::TCP(in_addr address, int port)
init();
}
xrt::drivers::wivrn::TCPListener::TCPListener(int port)
{
fd = socket(AF_INET6, SOCK_STREAM, 0);
if (fd < 0)
{
throw std::system_error{errno, std::generic_category()};
}
int reuse_addr = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr, sizeof(reuse_addr)) < 0)
{
::close(fd);
throw std::system_error{errno, std::generic_category()};
}
sockaddr_in6 addr{};
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(port);
addr.sin6_addr = in6addr_any;
if (bind(fd, (sockaddr *)&addr, sizeof(addr)) < 0)
{
::close(fd);
throw std::system_error{errno, std::generic_category()};
}
int backlog = 1;
if (listen(fd, backlog) < 0)
{
::close(fd);
throw std::system_error{errno, std::generic_category()};
}
}
std::pair<xrt::drivers::wivrn::TCP, sockaddr_in6>
xrt::drivers::wivrn::TCPListener::accept()
{
sockaddr_in6 addr{};
socklen_t addrlen = sizeof(addr);
int fd2 = ::accept(fd, (sockaddr *)&addr, &addrlen);
if (fd2 < 0)
throw std::system_error{errno, std::generic_category()};
return {TCP{fd2}, addr};
}
// std::pair<xrt::drivers::wivrn::deserialization_packet, sockaddr_in6> xrt::drivers::wivrn::UDP::receive_from_raw()
// {
// std::vector<uint8_t> buffer(2000);
@@ -110,6 +110,16 @@ public:
void send_raw(const std::vector<uint8_t> & data);
};
class TCPListener : public socket_base
{
public:
TCPListener(int port);
TCPListener(const TCPListener &) = delete;
TCPListener(TCPListener &&) = default;
std::pair<TCP, sockaddr_in6> accept();
};
template <typename Socket, typename ReceivedType, typename SentType>
class typed_socket : public Socket
{
View File
+16
View File
@@ -0,0 +1,16 @@
execute_process(COMMAND git describe --always OUTPUT_VARIABLE GIT_VERSION)
string(STRIP ${GIT_VERSION} GIT_VERSION)
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/version.cpp
COMMAND ${CMAKE_COMMAND}
-D GIT_EXECUTABLE=${GIT_EXECUTABLE}
-D INPUT_FILE=${CMAKE_SOURCE_DIR}/common/version.cpp.in
-D OUTPUT_FILE=${CMAKE_BINARY_DIR}/version.cpp
-P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake
)
file(GLOB LOCAL_SOURCE CONFIGURE_DEPENDS "*.cpp")
add_library(wivrn-common STATIC ${CMAKE_BINARY_DIR}/version.cpp ${LOCAL_SOURCES})
target_include_directories(wivrn-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+2 -2
View File
@@ -17,6 +17,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "version.h"
#cmakedefine GIT_VERSION "@GIT_VERSION@"
const char git_version[] = "@GIT_VERSION@";
+3
View File
@@ -0,0 +1,3 @@
#pragma once
extern const char git_version[];
-46
View File
@@ -1,46 +0,0 @@
#include "wivrn_sockets.h"
#include "wivrn_packets.h"
#include <iostream>
#include <sys/socket.h>
#include <netdb.h>
using namespace xrt::drivers::network;
sockaddr_in6 wait_announce()
{
typed_socket<UDP, from_headset::client_announce_packet, void> receiver;
receiver.subscribe_multicast(announce_address);
receiver.bind(announce_port);
while(true)
{
auto [packet, sender] = receiver.receive_from();
if (packet.magic == packet.magic_value)
{
receiver.unsubscribe_multicast(announce_address);
return sender;
}
}
}
int main()
{
try
{
auto headset_address = wait_announce();
char host[100];
getnameinfo((sockaddr*)&headset_address, sizeof(headset_address), host, sizeof(host), nullptr, 0, 0);
std::cout << "Sender: " << host << std::endl;
typed_socket<TCP, from_headset::control_packets, to_headset::control_packets> control{headset_address.sin6_addr, control_port};
}
catch(std::exception& e)
{
std::cerr << "Caught exception: " << e.what() << std::endl;
}
}