Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9be142917 | ||
|
|
2204fdd396 | ||
|
|
f55e52cc69 | ||
|
|
7253d4cc9f | ||
|
|
54929abae9 | ||
|
|
b641c66d25 | ||
|
|
0736fc3fc5 | ||
|
|
aa4ccfd0b0 | ||
|
|
73e86ed096 | ||
|
|
7bf9bac094 | ||
|
|
38e345025e | ||
|
|
e7c0c008a3 | ||
|
|
c2c70e0469 | ||
|
|
b687f83950 | ||
|
|
9b6531908c | ||
|
|
9b9a7b6f3f | ||
|
|
c7b94b6524 | ||
|
|
93bf067139 | ||
|
|
b6b3a4da80 | ||
|
|
41abd36e33 | ||
|
|
725aa9d9a8 | ||
|
|
24d718f916 | ||
|
|
bdec1f85cd | ||
|
|
7e5b9a7e4f | ||
|
|
de32f6e24f | ||
|
|
4adfe21987 | ||
|
|
149de4eeab | ||
|
|
cb1d0d7c2c | ||
|
|
33a5bf7494 | ||
|
|
f1b80a1ebd | ||
|
|
038622fd46 | ||
|
|
a9ad5195b7 | ||
|
|
7d76367d2c | ||
|
|
1e03b6e672 | ||
|
|
a9f774c67c | ||
|
|
7963efc034 | ||
|
|
17ac7ab7d9 | ||
|
|
b8c08f1feb | ||
|
|
045036f3a2 | ||
|
|
9fe7c5829b | ||
|
|
52be025d51 | ||
|
|
e584d9607f | ||
|
|
aad1bb6a1b | ||
|
|
1f6ea0d4ca | ||
|
|
e526d572c2 | ||
|
|
e0ff42800f | ||
|
|
7243092682 | ||
|
|
be6028982e | ||
|
|
8854b1b548 | ||
|
|
fb509361b6 | ||
|
|
60226e5346 | ||
|
|
a90ee6a018 | ||
|
|
44a5a889e1 | ||
|
|
61c5c871c1 | ||
|
|
50e1ecab37 | ||
|
|
b1ee9bad47 | ||
|
|
0e5b339b68 | ||
|
|
219d251d1b | ||
|
|
ab2671633a | ||
|
|
51c25624b7 | ||
|
|
275a8195eb | ||
|
|
4061119aef | ||
|
|
3e0f6bf6fa | ||
|
|
1dd0ed4fe3 | ||
|
|
56f32f4ae6 | ||
|
|
e3f35aad54 | ||
|
|
c1111fe036 | ||
|
|
14333ce208 | ||
|
|
2d5b619429 | ||
|
|
38efb9ff28 | ||
|
|
12e3df5b9c | ||
|
|
56a94bfc10 | ||
|
|
19d46db554 | ||
|
|
c6e05754c8 | ||
|
|
26f087c906 | ||
|
|
903a02d881 | ||
|
|
1365f4f527 | ||
|
|
cb7e6dabfc | ||
|
|
e4acf2401e | ||
|
|
5f373460a1 | ||
|
|
25a81b6f5f | ||
|
|
70ec7acbec | ||
|
|
421d935dde | ||
|
|
7ea256a4c2 | ||
|
|
db91edf4c1 | ||
|
|
aca45420dd | ||
|
|
98fc4ad4bb | ||
|
|
8e4e4c9596 | ||
|
|
34494f18e6 | ||
|
|
f4d66eb4e7 | ||
|
|
39b7c6c45a | ||
|
|
b81d010841 | ||
|
|
db70d3975c | ||
|
|
64355ff916 | ||
|
|
ed51bcc3b6 | ||
|
|
4baa98c8f1 | ||
|
|
4516beb2a5 | ||
|
|
092dbc893d | ||
|
|
2c1996eca1 | ||
|
|
fb3786fc2d | ||
|
|
190f4ae8bb | ||
|
|
79a34bcdd5 | ||
|
|
0ec2cd5a3e | ||
|
|
db66b0dbb7 | ||
|
|
ba18eac4a7 | ||
|
|
b0573c4265 | ||
|
|
46a36fcd55 | ||
|
|
a5bb9c2678 | ||
|
|
5b6e20bdbe | ||
|
|
1667065084 | ||
|
|
67918b7fe7 | ||
|
|
f03c460aa6 | ||
|
|
e7c69e9464 | ||
|
|
6e64dd03b3 | ||
|
|
7fb8f4c1a8 | ||
|
|
fcbdda9908 | ||
|
|
4e5eca204f | ||
|
|
6932f9461d |
@@ -0,0 +1,6 @@
|
||||
version: "1"
|
||||
rules:
|
||||
- base: master
|
||||
upstream: WiVRn:master
|
||||
mergeMethod: hardreset
|
||||
|
||||
@@ -2,7 +2,7 @@ name: Release APK Only
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
branches: [ "apk-build" ]
|
||||
|
||||
env:
|
||||
BUILD_TYPE: RelWithDebInfo
|
||||
@@ -22,7 +22,7 @@ jobs:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
# Checkout from upstream instead of WiVRn-APK to ensure the GIT_DESC variable is set correctly
|
||||
repository: 'WiVRn/WiVRn'
|
||||
repository: 'Vindicus999/WiVRn'
|
||||
ref: ${{ github.sha }}
|
||||
fetch-depth: 0
|
||||
|
||||
@@ -42,9 +42,10 @@ jobs:
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext
|
||||
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext npm
|
||||
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.4.0/KTX-Software-4.4.0-Linux-x86_64.deb
|
||||
sudo dpkg --install KTX-Software-4.4.0-Linux-x86_64.deb
|
||||
npm install --global @gltf-transform/cli@4.1.1
|
||||
|
||||
- name: Check for Secret availability
|
||||
id: secret-check
|
||||
@@ -70,7 +71,7 @@ jobs:
|
||||
sudo rm /usr/local/bin/cmake
|
||||
"${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager" --install "cmake;3.30.3"
|
||||
chmod +x gradlew
|
||||
./gradlew -Psuffix=".github.nightly" -Pwivrn_css=images/wivrn-nightly.css -Pwivrn_app_name="WiVRn Nightly" assemble${{ matrix.hmd }}${{ matrix.buildtype }}
|
||||
./gradlew -Psuffix=".github.nightly" -Pwivrn_css=images/wivrn-nightly.css -Pwivrn_app_name="WiVRn Nightly" -Pwivrn_compress_glb=ON assemble${{ matrix.hmd }}${{ matrix.buildtype }}
|
||||
|
||||
- name: Prepare before archiving artifacts
|
||||
run: |
|
||||
@@ -109,13 +110,13 @@ jobs:
|
||||
pattern: 'apk-*'
|
||||
merge-multiple: true
|
||||
|
||||
- name: Rename APK artifacts
|
||||
run: |
|
||||
cd apk
|
||||
for f in *.apk; do
|
||||
BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
|
||||
mv "${f}" "org.meumeu.wivrn-${BASENAME}"
|
||||
done
|
||||
# - name: Rename APK artifacts
|
||||
# run: |
|
||||
# cd apk
|
||||
# for f in *.apk; do
|
||||
# BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
|
||||
# mv "${f}" "org.meumeu.wivrn-${BASENAME}"
|
||||
# done
|
||||
|
||||
- name: Download APK debug artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
|
||||
@@ -156,7 +156,7 @@ jobs:
|
||||
|
||||
- uses: cachix/install-nix-action@v31
|
||||
- run: nix flake check
|
||||
- run: nix build
|
||||
- run: nix build --print-build-logs
|
||||
|
||||
build-test-client:
|
||||
name: Linux client
|
||||
@@ -181,8 +181,12 @@ jobs:
|
||||
vulkan-use-cache: true
|
||||
|
||||
- name: Install dependencies
|
||||
run: >
|
||||
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev libxcb-glx0-dev gettext libfontconfig-dev libboost-all-dev librsvg2-bin libssl-dev sway grim mesa-vulkan-drivers wayland-protocols fonts-noto-cjk fonts-roboto
|
||||
run: |
|
||||
sudo apt-get update && sudo apt-get install libvulkan-dev libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev libxcb-glx0-dev gettext libfontconfig-dev libboost-all-dev librsvg2-bin libssl-dev sway grim mesa-vulkan-drivers wayland-protocols fonts-noto-cjk fonts-roboto libcurl4-openssl-dev
|
||||
|
||||
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.4.0/KTX-Software-4.4.0-Linux-x86_64.deb
|
||||
sudo dpkg --install KTX-Software-4.4.0-Linux-x86_64.deb
|
||||
npm install --global @gltf-transform/cli@4.1.1
|
||||
|
||||
- name: install server dependencies
|
||||
run: >
|
||||
@@ -341,6 +345,7 @@ jobs:
|
||||
sudo apt-get update && sudo apt-get install glslang-tools librsvg2-bin gettext
|
||||
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
npm install --global @gltf-transform/cli
|
||||
|
||||
- name: Check for Secret availability
|
||||
id: secret-check
|
||||
@@ -402,7 +407,7 @@ jobs:
|
||||
echo Using stylesheet $CSS and name $APPNAME
|
||||
|
||||
chmod +x gradlew
|
||||
./gradlew -Pwivrn_version=$VERSION -Pwivrn_versionCode=$VERSION_CODE -Psuffix=$SUFFIX -Pwivrn_css=$CSS -Pwivrn_app_name="$APPNAME" assemble${{ matrix.hmd }}${{ matrix.buildtype }}
|
||||
./gradlew -Pwivrn_version=$VERSION -Pwivrn_versionCode=$VERSION_CODE -Psuffix=$SUFFIX -Pwivrn_css=$CSS -Pwivrn_app_name="$APPNAME" -Pwivrn_compress_glb=ON assemble${{ matrix.hmd }}${{ matrix.buildtype }}
|
||||
|
||||
- name: Upload build dir
|
||||
uses: actions/upload-artifact@v4
|
||||
@@ -470,7 +475,11 @@ jobs:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
apt update
|
||||
apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev
|
||||
apt install --yes libcjson-dev libx264-dev libavcodec-dev libavutil-dev libswscale-dev libavfilter-dev libbsd-dev libavahi-client-dev libavahi-glib-dev libeigen3-dev glslang-tools libudev-dev libwayland-dev libx11-xcb-dev libxrandr-dev libxcb-randr0-dev libgl-dev libglx-dev mesa-common-dev libgl1-mesa-dev libglu1-mesa-dev libsystemd-dev libva-dev nlohmann-json3-dev libpulse-dev xz-utils libpipewire-0.3-dev libcli11-dev qt6-base-dev qt6-tools-dev libcap-dev pkexec libboost-all-dev librsvg2-bin dpkg-dev pkg-config debhelper-compat build-essential lintian cmake libnotify-dev qt6-declarative-dev extra-cmake-modules libkirigami-dev libkf6i18n-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev jq sudo cmake gcc g++ git wget libssl-dev qcoro-qt6-dev librsvg2-dev libarchive-dev npm
|
||||
|
||||
wget https://github.com/KhronosGroup/KTX-Software/releases/download/v4.3.2/KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
sudo dpkg --install KTX-Software-4.3.2-Linux-x86_64.deb
|
||||
npm install --global @gltf-transform/cli
|
||||
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
name: Sync Fork with Upstream
|
||||
|
||||
env:
|
||||
UPSTREAM_URL: "https://github.com/wivrn/wivrn.git"
|
||||
WORKFLOW_TOKEN: ${{ secrets.DOWNSTREAM_GITHUB_TOKEN }}
|
||||
UPSTREAM_BRANCH: "master"
|
||||
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: GitHub Sync to Upstream Repository
|
||||
uses: dabreadman/sync-upstream-repo@v1.3.0
|
||||
with:
|
||||
upstream_repo: ${{ env.UPSTREAM_URL }}
|
||||
upstream_branch: ${{ env.UPSTREAM_BRANCH }}
|
||||
token: ${{ env.WORKFLOW_TOKEN }}
|
||||
|
||||
- name: Checkout stuff
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: Merge master -> apk-build
|
||||
uses: devmasx/merge-branch@master
|
||||
with:
|
||||
type: now
|
||||
from_branch: master
|
||||
target_branch: apk-build
|
||||
github_token: ${{ env.WORKFLOW_TOKEN }}
|
||||
|
||||
- name: Merge sneed -> apk-build
|
||||
uses: devmasx/merge-branch@master
|
||||
with:
|
||||
type: now
|
||||
from_branch: sneed
|
||||
target_branch: apk-build
|
||||
github_token: ${{ env.WORKFLOW_TOKEN }}
|
||||
|
||||
@@ -10,6 +10,10 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
if(ANDROID)
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/android)
|
||||
endif()
|
||||
|
||||
# Default to PIC code
|
||||
include(CheckPIESupported)
|
||||
check_pie_supported()
|
||||
@@ -23,7 +27,7 @@ option(WIVRN_USE_SYSTEM_FREETYPE "Use system FreeType" ON)
|
||||
option(WIVRN_USE_SYSTEM_BOOST "Use system Boost headers" ON)
|
||||
option(WIVRN_USE_SYSTEM_OPENXR "Use system OpenXR headers" ON)
|
||||
option(WIVRN_USE_SYSTEMD "Use libsystemd" ON)
|
||||
option(WIVRN_USE_LIBKTX "Use libktx" ${ANDROID})
|
||||
option(WIVRN_COMPRESS_GLB "Compress textures in GLB files with gltf-transform" OFF)
|
||||
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)
|
||||
@@ -65,6 +69,8 @@ endif()
|
||||
|
||||
option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON)
|
||||
|
||||
set(WIVRN_ENVIRONMENTS_URL "https://github.com/WiVRn/WiVRn-environments/releases/latest/download/index.json" CACHE STRING "URL hosting the custom environments json file")
|
||||
|
||||
if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_SERVER OR WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_DISSECTOR)
|
||||
set(NEED_COMMON TRUE)
|
||||
else()
|
||||
@@ -82,7 +88,7 @@ endif()
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Vulkan REQUIRED)
|
||||
find_package(Git)
|
||||
if (NEED_COMMON AND NOT ANDROID)
|
||||
if (NEED_COMMON)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
endif()
|
||||
include(VulkanVersion)
|
||||
@@ -151,6 +157,11 @@ endif()
|
||||
if (WIVRN_BUILD_DASHBOARD)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Quick Test Gui QuickControls2 Widgets Network)
|
||||
|
||||
if(Qt6_VERSION VERSION_GREATER_EQUAL 6.10.0)
|
||||
# QtCoro needs this for Qt 6.10 and (currently) doesn't do this by itself
|
||||
find_package(Qt6 REQUIRED COMPONENTS QmlPrivate)
|
||||
endif()
|
||||
|
||||
find_package(ECM 5.115 REQUIRED NO_MODULE)
|
||||
list(APPEND CMAKE_MODULE_PATH "${ECM_MODULE_PATH}")
|
||||
|
||||
@@ -174,6 +185,18 @@ if (WIVRN_BUILD_CLIENT OR WIVRN_BUILD_DASHBOARD)
|
||||
find_package(Gettext REQUIRED)
|
||||
endif()
|
||||
|
||||
if (WIVRN_BUILD_CLIENT)
|
||||
find_program(TOKTX toktx REQUIRED)
|
||||
|
||||
if (WIVRN_COMPRESS_GLB)
|
||||
find_program(GLTF_TRANSFORM gltf-transform REQUIRED)
|
||||
endif()
|
||||
|
||||
if(NOT ANDROID)
|
||||
find_package(CURL REQUIRED COMPONENTS HTTP HTTPS)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (WIVRN_BUILD_CLIENT AND NOT ANDROID)
|
||||
pkg_check_modules(LIBAV REQUIRED IMPORTED_TARGET libavcodec libavutil libswscale libavfilter)
|
||||
find_package(Fontconfig REQUIRED)
|
||||
@@ -212,29 +235,37 @@ FetchContent_Declare(boost EXCLUDE_FROM_ALL SYSTEM URL https://github.co
|
||||
# Client dependencies
|
||||
FetchContent_Declare(simdjson EXCLUDE_FROM_ALL SYSTEM URL https://github.com/simdjson/simdjson/archive/refs/tags/v3.10.1.tar.gz
|
||||
URL_HASH SHA256=1e8f881cb2c0f626c56cd3665832f1e97b9d4ffc648ad9e1067c134862bba060)
|
||||
FetchContent_Declare(fastgltf EXCLUDE_FROM_ALL SYSTEM URL https://github.com/spnda/fastgltf/archive/refs/tags/v0.7.1.tar.gz
|
||||
URL_HASH SHA256=44bcb025dd5cd480236a3bc7a3f8c9a708a801ed773b7859677440d22e0e1e7c)
|
||||
FetchContent_Declare(fastgltf EXCLUDE_FROM_ALL SYSTEM URL https://github.com/spnda/fastgltf/archive/refs/tags/v0.9.0.tar.gz
|
||||
URL_HASH SHA256=0bb564e127b14c22f062db50f89381dd2e0a20dbaf4987ca138a4ae8728712f9)
|
||||
FetchContent_Declare(glm EXCLUDE_FROM_ALL SYSTEM URL https://github.com/g-truc/glm/archive/refs/tags/1.0.1.tar.gz
|
||||
URL_HASH SHA256=9f3174561fd26904b23f0db5e560971cbf9b3cbda0b280f04d5c379d03bf234c)
|
||||
FetchContent_Declare(openxr_loader EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-1.1.48.tar.gz
|
||||
URL_HASH SHA256=c9372992dcdfac643e28796e41d4dbd36c4cdf0388d01fa89245628edae9d411)
|
||||
FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.com/gabime/spdlog/archive/refs/tags/v1.14.1.tar.gz
|
||||
URL_HASH SHA256=1586508029a7d0670dfcb2d97575dcdc242d3868a259742b69f100801ab4e16b)
|
||||
FetchContent_Declare(spdlog EXCLUDE_FROM_ALL SYSTEM URL https://github.com/gabime/spdlog/archive/refs/tags/v1.15.3.tar.gz
|
||||
URL_HASH SHA256=15a04e69c222eb6c01094b5c7ff8a249b36bb22788d72519646fb85feb267e67)
|
||||
FetchContent_Declare(stb EXCLUDE_FROM_ALL SYSTEM URL https://github.com/nothings/stb/archive/013ac3beddff3dbffafd5177e7972067cd2b5083.zip
|
||||
URL_HASH SHA256=b7f476902bbef1b30f8ecc2d9d95c459c32302c8b559d09b589b5955463b7af8)
|
||||
FetchContent_Declare(libktx EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/v4.4.0.tar.gz
|
||||
URL_HASH SHA256=3585d76edcdcbe3a671479686f8c81c1c10339f419e4b02a9a6f19cc6e4e0612)
|
||||
file(GLOB LIBKTX_PATCHES CONFIGURE_DEPENDS patches/libktx/*)
|
||||
set(KTX_GIT_VERSION_FULL "v4.4.0")
|
||||
FetchContent_Declare(libktx EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/KTX-Software/archive/refs/tags/${KTX_GIT_VERSION_FULL}.tar.gz
|
||||
URL_HASH SHA256=3585d76edcdcbe3a671479686f8c81c1c10339f419e4b02a9a6f19cc6e4e0612
|
||||
PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/patches/apply.sh ${LIBKTX_PATCHES}
|
||||
)
|
||||
FetchContent_Declare(implot EXCLUDE_FROM_ALL SYSTEM URL https://github.com/epezent/implot/archive/3da8bd34299965d3b0ab124df743fe3e076fa222.zip
|
||||
URL_HASH SHA256=e9b439a94aa6f09fcf12ed9c2cd784efe5e99e96242122aa683e690b29f7a59f)
|
||||
file(GLOB IMGUI_PATCHES CONFIGURE_DEPENDS patches/imgui/*)
|
||||
FetchContent_Declare(imgui EXCLUDE_FROM_ALL SYSTEM URL https://github.com/ocornut/imgui/archive/refs/tags/v1.92.1.tar.gz
|
||||
URL_HASH SHA256=32c237c2abf67a2ffccaac17192f711d4a787554b4133187a153d49057d6109c
|
||||
FetchContent_Declare(imgui EXCLUDE_FROM_ALL SYSTEM URL https://github.com/ocornut/imgui/archive/refs/tags/v1.92.3.tar.gz
|
||||
URL_HASH SHA256=9212ee7c4718b1466a5d99e64bce3ef1965704afea4ba651f8d978d0791b7c7c
|
||||
PATCH_COMMAND ${CMAKE_CURRENT_LIST_DIR}/patches/apply.sh ${IMGUI_PATCHES}
|
||||
)
|
||||
FetchContent_Declare(uni-algo EXCLUDE_FROM_ALL SYSTEM URL https://github.com/uni-algo/uni-algo/archive/v1.2.0.tar.gz
|
||||
URL_HASH SHA256=f2a1539cd8635bc6088d05144a73ecfe7b4d74ee0361fabed6f87f9f19e74ca9)
|
||||
FetchContent_Declare(entt EXCLUDE_FROM_ALL SYSTEM URL https://github.com/skypjack/entt/archive/refs/tags/v3.15.0.tar.gz
|
||||
URL_HASH SHA256=01466fcbf77618a79b62891510c0bbf25ac2804af5751c84982b413852234d66)
|
||||
FetchContent_Declare(curl EXCLUDE_FROM_ALL SYSTEM URL https://github.com/curl/curl/releases/download/curl-8_15_0/curl-8.15.0.tar.xz
|
||||
URL_HASH SHA256=6cd0a8a5b126ddfda61c94dc2c3fc53481ba7a35461cf7c5ab66aa9d6775b609)
|
||||
FetchContent_Declare(spirv-reflect EXCLUDE_FROM_ALL SYSTEM URL https://github.com/KhronosGroup/SPIRV-Reflect/archive/refs/tags/vulkan-sdk-1.4.321.0.tar.gz
|
||||
URL_HASH SHA256=254ed36128e7abe8fb12ef804319d0790e059093c116e9fe55d4003880515f85)
|
||||
|
||||
file(GLOB MONADO_PATCHES CONFIGURE_DEPENDS patches/monado/*)
|
||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS monado-rev)
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
WiVRn wirelessly connects a standalone VR headset to a Linux computer. You can then play PCVR games on the headset while processing is done on the computer.
|
||||
|
||||
It supports a wide range of headsets such as Quest 1 / 2 / Pro / 3 / 3S, Pico Neo 4, HTC Vive Focus 3, HTC Vive XR elite and most other Android based headsets.
|
||||
It supports a wide range of headsets such as Quest 1 / 2 / Pro / 3 / 3S, Pico Neo 3, Pico 4, HTC Vive Focus 3, HTC Vive XR elite and most other Android based headsets.
|
||||
|
||||
# Getting started
|
||||
|
||||
@@ -41,8 +41,8 @@ Avahi must be running:
|
||||
systemctl enable --now avahi-daemon
|
||||
```
|
||||
|
||||
If a firewall is installed, open port 5353/UDP for avahi.
|
||||
Open ports 9757/UDP+TCP for WiVRn itself.
|
||||
- If a firewall is installed, open port 5353/UDP for avahi and ports 9757/UDP+TCP for WiVRn itself.
|
||||
- In the case of ufw, use `ufw allow 5353/udp` and `ufw allow 9757`.
|
||||
|
||||
### Running
|
||||
- On your computer, run "WiVRn server" application, or `wivrn-dashboard` from the command line, it will show the connection wizard the first time you launch it.
|
||||
@@ -109,7 +109,7 @@ If the server list is empty in the headset app:
|
||||
|
||||
## My headset does not connect to my computer
|
||||
- If you have a firewall, check that port 9757 (UDP and TCP) is open
|
||||
- The server and client must be compatible:
|
||||
- The server and client must be compatible.
|
||||
|
||||
## How do I use a wired connection?
|
||||
|
||||
@@ -129,9 +129,20 @@ If the server list is empty in the headset app:
|
||||
|
||||
## How do I see server logs when using the dashboard?
|
||||
|
||||
```
|
||||
journalctl -f --no-hostname -u io.github.wivrn.wivrn.desktop
|
||||
```
|
||||
- Click Troubleshoot > Open server logs, or
|
||||
- Navigate to `${XDG_STATE_HOME}/wivrn/wivrn-dashboard` (with fallback to `${HOME}/.local/state` for `${XDG_STATE_HOME}`, or
|
||||
- For flatpak, navigate to `${HOME}/.var/app/io.github.wivrn.wivrn/.local/state/wivrn/wivrn-dashboard`.
|
||||
|
||||
## I have high motion latency, black borders following my view, hear corrupted audio or see a corrupted, pixelated image
|
||||
|
||||
- When connecting through USB, make sure the headset isn't connected through WiFi (switch off WiFi)
|
||||
- Reset the settings using the button at the bottom of the settings tab
|
||||
- Try switching to software encoding
|
||||
- Decrease the bitrate
|
||||
- Decrease the resolution in the WiVRn app
|
||||
- Connect through USB or use a better WiFi router.
|
||||
|
||||
Note: WiVRn isn't properly optimized for NVIDIA GPUs due to the lack of developers with NVIDIA hardware. Motion latency may be significantly worse at rendering resolutions higher than default.
|
||||
|
||||
# Contributing
|
||||
|
||||
@@ -155,7 +166,7 @@ WiVRn uses the following software:
|
||||
- [HarfBuzz](https://harfbuzz.github.io/)
|
||||
- [librsvg](https://wiki.gnome.org/Projects/LibRsvg)
|
||||
- [Monado](https://monado.freedesktop.org/)
|
||||
- [nvenc](https://developer.nvidia.com/nvidia-video-codec-sdk) optional, for hardware encoding on Nvidia
|
||||
- [nvenc](https://developer.nvidia.com/nvidia-video-codec-sdk) optional, for hardware encoding on NVIDIA
|
||||
- [qCoro](https://qcoro.dev/)
|
||||
- [Qt 6](https://www.qt.io/) optional, for the dashboard
|
||||
- [spdlog](https://github.com/gabime/spdlog)
|
||||
|
||||
|
Before Width: | Height: | Size: 1023 KiB After Width: | Height: | Size: 1023 KiB |
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
fill="#000000"
|
||||
height="800px"
|
||||
width="800px"
|
||||
version="1.1"
|
||||
id="Layer_1"
|
||||
viewBox="0 0 512 512"
|
||||
xml:space="preserve"
|
||||
sodipodi:docname="default-environment.svg"
|
||||
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"><defs
|
||||
id="defs2" /><sodipodi:namedview
|
||||
id="namedview2"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="2.235"
|
||||
inkscape:cx="400"
|
||||
inkscape:cy="400"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2058"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="g1" />
|
||||
<g
|
||||
id="g2">
|
||||
<g
|
||||
id="g1">
|
||||
<path
|
||||
d="M0,0v512h512V0H0z M460.075,30.417l-43.548,43.547L372.98,30.417H460.075z M481.583,51.925v117.512L336.264,314.755 l-58.756-58.756L481.583,51.925z M395.02,95.472L95.472,395.019l-58.756-58.756L336.264,36.717L395.02,95.472z M299.547,30.417 L175.736,154.228L116.98,95.472l65.055-65.055H299.547z M30.417,30.417H139.02L30.417,139.02V30.417z M30.417,182.036 l65.055-65.055l58.756,58.756L30.417,299.546V182.036z M30.417,372.979l43.547,43.547l-43.547,43.547V372.979z M51.925,481.583 L256,277.508l58.756,58.756L169.437,481.583H51.925z M212.453,481.583l269.13-269.129v117.51L329.964,481.583H212.453z M372.981,481.583l43.546-43.547l43.547,43.547H372.981z M481.583,460.075l-43.547-43.547l43.547-43.547V460.075z"
|
||||
id="path1"
|
||||
inkscape:label="path1"
|
||||
style="fill:#ffffff;fill-opacity:1" />
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 930 B After Width: | Height: | Size: 930 B |
@@ -70,9 +70,6 @@
|
||||
"generator": "Aspose.3D 24.1.0",
|
||||
"version": "2.0"
|
||||
},
|
||||
"extensionsUsed": [
|
||||
"KHR_texture_basisu"
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "data:application/octet-stream;base64,AAABAAIAAwAEAAUAAAAAAAAAIMEAAAAAAAAgwQAAAAAAAIA/AAAAACUAgD8AAAAAAAAgwQAAAAAAACBBAACgQAAAgD8AAAAAJQCAPwAAAAAAACBBAAAAAAAAIMEAAAAAAACAwAAAAAAlAIA/AAAAAAAAIEEAAAAAAAAgQQAAoEAAAIDAAAAAACUAgD8AAAAAAAAgQQAAAAAAACDBAAAAAAAAgMAAAAAAJQCAPwAAAAAAACDBAAAAAAAAIEEAAKBAAACAPwAAAAAlAIA/AAAAAAAAAAA=",
|
||||
@@ -82,9 +79,6 @@
|
||||
"images": [
|
||||
{
|
||||
"uri": "WoodFloor051_1K-JPG_Color.jpg"
|
||||
},
|
||||
{
|
||||
"uri": "WoodFloor051_1K-JPG_Color.ktx2"
|
||||
}
|
||||
],
|
||||
"bufferViews": [
|
||||
@@ -129,12 +123,7 @@
|
||||
"textures": [
|
||||
{
|
||||
"sampler": 0,
|
||||
"source": 0,
|
||||
"extensions": {
|
||||
"KHR_texture_basisu": {
|
||||
"source": 1
|
||||
}
|
||||
}
|
||||
"source": 0
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||
|
||||
<svg
|
||||
viewBox="0 0 576 512"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
sodipodi:docname="passthrough.svg"
|
||||
inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<defs
|
||||
id="defs1" />
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:zoom="3.4921875"
|
||||
inkscape:cx="288.07159"
|
||||
inkscape:cy="256"
|
||||
inkscape:window-width="3840"
|
||||
inkscape:window-height="2058"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="svg1" />
|
||||
<!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2025 Fonticons, Inc.-->
|
||||
<path
|
||||
d="M96 64c-35.3 0-64 28.7-64 64l0 256c0 35.3 28.7 64 64 64l256 0c35.3 0 64-28.7 64-64l0-256c0-35.3-28.7-64-64-64L96 64zM464 336l73.5 58.8c4.2 3.4 9.4 5.2 14.8 5.2 13.1 0 23.7-10.6 23.7-23.7l0-240.6c0-13.1-10.6-23.7-23.7-23.7-5.4 0-10.6 1.8-14.8 5.2L464 176 464 336z"
|
||||
id="path1"
|
||||
style="fill:#ffffff;fill-opacity:1" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.5 KiB |
@@ -1,148 +0,0 @@
|
||||
{
|
||||
"asset":{
|
||||
"generator":"Khronos glTF Blender I/O v4.2.70",
|
||||
"version":"2.0"
|
||||
},
|
||||
"scene":0,
|
||||
"scenes":[
|
||||
{
|
||||
"name":"Scene",
|
||||
"nodes":[
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"mesh":0,
|
||||
"name":"Cylinder",
|
||||
"rotation":[
|
||||
0.7071068286895752,
|
||||
0,
|
||||
0,
|
||||
0.7071068286895752
|
||||
],
|
||||
"translation":[
|
||||
0,
|
||||
0,
|
||||
-0.5
|
||||
],
|
||||
"scale":[0.7,1,0.7]
|
||||
}
|
||||
],
|
||||
"materials":[
|
||||
{
|
||||
"name":"Material.001",
|
||||
"pbrMetallicRoughness":{
|
||||
"baseColorFactor":[0,0,0,0.5]
|
||||
},
|
||||
"emissiveTexture":{
|
||||
"index":0
|
||||
},
|
||||
"emissiveFactor": [ 2.0, 2.0, 2.0 ]
|
||||
}
|
||||
],
|
||||
"meshes":[
|
||||
{
|
||||
"name":"Cylinder.001",
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"POSITION":0,
|
||||
"NORMAL":1,
|
||||
"TEXCOORD_0":2
|
||||
},
|
||||
"indices":3,
|
||||
"material":0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures":[
|
||||
{
|
||||
"sampler":0,
|
||||
"source":0
|
||||
}
|
||||
],
|
||||
"images":[
|
||||
{
|
||||
"mimeType":"image/png",
|
||||
"name":"Untitled",
|
||||
"uri":"ray.png"
|
||||
}
|
||||
],
|
||||
"accessors":[
|
||||
{
|
||||
"bufferView":0,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"max":[
|
||||
0.004000000189989805,
|
||||
0.5,
|
||||
0.004000000189989805
|
||||
],
|
||||
"min":[
|
||||
-0.004000000189989805,
|
||||
-0.5,
|
||||
-0.004000000189989805
|
||||
],
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":2,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"type":"VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView":3,
|
||||
"componentType":5123,
|
||||
"count":48,
|
||||
"type":"SCALAR"
|
||||
}
|
||||
],
|
||||
"bufferViews":[
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":216,
|
||||
"byteOffset":0,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":216,
|
||||
"byteOffset":216,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":144,
|
||||
"byteOffset":432,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":96,
|
||||
"byteOffset":576,
|
||||
"target":34963
|
||||
}
|
||||
],
|
||||
"samplers":[
|
||||
{
|
||||
"magFilter":9729,
|
||||
"minFilter":9987
|
||||
}
|
||||
],
|
||||
"buffers":[
|
||||
{
|
||||
"byteLength":672,
|
||||
"uri":"ray.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
{
|
||||
"asset":{
|
||||
"generator":"Khronos glTF Blender I/O v4.2.70",
|
||||
"version":"2.0"
|
||||
},
|
||||
"scene":0,
|
||||
"scenes":[
|
||||
{
|
||||
"name":"Scene",
|
||||
"nodes":[
|
||||
0
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes":[
|
||||
{
|
||||
"mesh":0,
|
||||
"name":"Cylinder",
|
||||
"rotation":[
|
||||
0.7071068286895752,
|
||||
0,
|
||||
0,
|
||||
0.7071068286895752
|
||||
],
|
||||
"translation":[
|
||||
0,
|
||||
0,
|
||||
-0.5
|
||||
],
|
||||
"scale":[0.7,1,0.7]
|
||||
}
|
||||
],
|
||||
"materials":[
|
||||
{
|
||||
"name":"Material.001",
|
||||
"pbrMetallicRoughness":{
|
||||
"baseColorFactor":[0,0,0,0]
|
||||
},
|
||||
"emissiveTexture":{
|
||||
"index":0
|
||||
},
|
||||
"emissiveFactor": [ 1.0, 1.0, 1.0 ]
|
||||
}
|
||||
],
|
||||
"meshes":[
|
||||
{
|
||||
"name":"Cylinder.001",
|
||||
"primitives":[
|
||||
{
|
||||
"attributes":{
|
||||
"POSITION":0,
|
||||
"NORMAL":1,
|
||||
"TEXCOORD_0":2
|
||||
},
|
||||
"indices":3,
|
||||
"material":0
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"textures":[
|
||||
{
|
||||
"sampler":0,
|
||||
"source":0
|
||||
}
|
||||
],
|
||||
"images":[
|
||||
{
|
||||
"mimeType":"image/png",
|
||||
"name":"Untitled",
|
||||
"uri":"ray.png"
|
||||
}
|
||||
],
|
||||
"accessors":[
|
||||
{
|
||||
"bufferView":0,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"max":[
|
||||
0.004000000189989805,
|
||||
0.5,
|
||||
0.004000000189989805
|
||||
],
|
||||
"min":[
|
||||
-0.004000000189989805,
|
||||
-0.5,
|
||||
-0.004000000189989805
|
||||
],
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":1,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"type":"VEC3"
|
||||
},
|
||||
{
|
||||
"bufferView":2,
|
||||
"componentType":5126,
|
||||
"count":18,
|
||||
"type":"VEC2"
|
||||
},
|
||||
{
|
||||
"bufferView":3,
|
||||
"componentType":5123,
|
||||
"count":48,
|
||||
"type":"SCALAR"
|
||||
}
|
||||
],
|
||||
"bufferViews":[
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":216,
|
||||
"byteOffset":0,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":216,
|
||||
"byteOffset":216,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":144,
|
||||
"byteOffset":432,
|
||||
"target":34962
|
||||
},
|
||||
{
|
||||
"buffer":0,
|
||||
"byteLength":96,
|
||||
"byteOffset":576,
|
||||
"target":34963
|
||||
}
|
||||
],
|
||||
"samplers":[
|
||||
{
|
||||
"magFilter":9729,
|
||||
"minFilter":9987
|
||||
}
|
||||
],
|
||||
"buffers":[
|
||||
{
|
||||
"byteLength":672,
|
||||
"uri":"ray.bin"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Before Width: | Height: | Size: 581 B |
@@ -114,6 +114,7 @@ android {
|
||||
versionCode = project.hasProperty('wivrn_versionCode') ? wivrn_versionCode.toInteger() : 1
|
||||
def showImguiDemo = project.hasProperty('wivrn_show_imgui_demo') ? wivrn_show_imgui_demo : 'OFF'
|
||||
def showDebugMenu = project.hasProperty('wivrn_show_debug_menu') ? wivrn_show_debug_menu : 'OFF'
|
||||
def compressGlb = project.hasProperty('wivrn_compress_glb') ? wivrn_compress_glb : 'OFF'
|
||||
|
||||
externalNativeBuild {
|
||||
def css = project.hasProperty('wivrn_css') ? project.wivrn_css: "images/wivrn-local.css"
|
||||
@@ -134,7 +135,8 @@ android {
|
||||
'-DWIVRN_WERROR=ON',
|
||||
'-DWIVRN_SHOW_IMGUI_DEMO_WINDOW=' + showImguiDemo,
|
||||
'-DWIVRN_CLIENT_DEBUG_MENU=' + showDebugMenu,
|
||||
'-DWIVRN_CSS=' + css
|
||||
'-DWIVRN_CSS=' + css,
|
||||
'-DWIVRN_COMPRESS_GLB=' + compressGlb
|
||||
resValue "string", "app_name", project.hasProperty('wivrn_app_name') ? project.wivrn_app_name : "WiVRn Local"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,18 +7,15 @@ set(KTX_FEATURE_LOADTEST_APPS OFF)
|
||||
|
||||
set(FASTGLTF_COMPILE_AS_CPP20 ON)
|
||||
|
||||
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo entt)
|
||||
set(SPIRV_REFLECT_EXECUTABLE OFF)
|
||||
set(SPIRV_REFLECT_STATIC_LIB ON)
|
||||
set(SPIRV_REFLECT_INSTALL OFF)
|
||||
|
||||
if (WIVRN_USE_LIBKTX)
|
||||
FetchContent_MakeAvailable(libktx)
|
||||
endif()
|
||||
|
||||
if (NOT WIVRN_USE_SYSTEM_BOOST)
|
||||
FetchContent_MakeAvailable(boost)
|
||||
endif()
|
||||
FetchContent_MakeAvailable(simdjson spdlog glm fastgltf imgui stb implot uni-algo entt libktx spirv-reflect)
|
||||
|
||||
include(FreetypeHarfbuzz)
|
||||
include(CompileGLSL)
|
||||
include(GenerateAssets)
|
||||
include(I18n)
|
||||
|
||||
add_library(stb INTERFACE)
|
||||
@@ -37,6 +34,16 @@ if(ANDROID)
|
||||
FetchContent_MakeAvailable(openxr_loader)
|
||||
target_link_libraries(wivrn openxr_loader)
|
||||
|
||||
# libcurl
|
||||
set(BUILD_CURL_EXE OFF)
|
||||
set(BUILD_TESTING OFF)
|
||||
set(CURL_DISABLE_INSTALL ON)
|
||||
set(CURL_USE_LIBPSL OFF)
|
||||
set(CURL_USE_LIBSSH2 OFF)
|
||||
set(BUILD_EXAMPLES OFF)
|
||||
|
||||
FetchContent_MakeAvailable(curl)
|
||||
target_link_libraries(wivrn libcurl_static)
|
||||
|
||||
target_link_libraries(wivrn native_app_glue)
|
||||
target_compile_definitions(wivrn PRIVATE -DXR_USE_PLATFORM_ANDROID -DVK_USE_PLATFORM_ANDROID_KHR)
|
||||
@@ -58,8 +65,7 @@ else()
|
||||
target_link_libraries(wivrn openxr_loader)
|
||||
endif()
|
||||
|
||||
target_link_libraries(wivrn PkgConfig::LIBAV Fontconfig::Fontconfig)
|
||||
|
||||
target_link_libraries(wivrn PkgConfig::LIBAV Fontconfig::Fontconfig CURL::libcurl)
|
||||
|
||||
file(GLOB PLATFORM_SOURCE CONFIGURE_DEPENDS
|
||||
"decoder/ffmpeg/*.cpp")
|
||||
@@ -99,8 +105,10 @@ target_link_libraries(wivrn
|
||||
FreetypeHarfbuzz
|
||||
glm::glm
|
||||
imspinner
|
||||
ktx
|
||||
simdjson
|
||||
spdlog::spdlog
|
||||
spirv-reflect-static
|
||||
stb
|
||||
uni-algo
|
||||
Vulkan::Vulkan
|
||||
@@ -108,10 +116,6 @@ target_link_libraries(wivrn
|
||||
wivrn-external
|
||||
)
|
||||
|
||||
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)
|
||||
@@ -224,61 +228,42 @@ endif()
|
||||
|
||||
|
||||
##############################################################################
|
||||
# Generate assets from SVGs
|
||||
# Generate assets
|
||||
#
|
||||
file(REAL_PATH ${WIVRN_CSS} WIVRN_CSS_ABS BASE_DIRECTORY "${CMAKE_SOURCE_DIR}")
|
||||
set(RSVG_OPTS "--stylesheet=${WIVRN_CSS_ABS}")
|
||||
|
||||
set(IMG_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../images)
|
||||
set(AST_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../assets)
|
||||
set(IMAGES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../images)
|
||||
set(ASSETS_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../assets-source)
|
||||
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.png
|
||||
COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn.png ${RSVG_OPTS}
|
||||
DEPENDS ${IMG_SRC_DIR}/wivrn.svg ${WIVRN_CSS_ABS})
|
||||
wivrn_rasterize_svg(SOURCE ${IMAGES_SRC_DIR}/wivrn.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png WIDTH 540 HEIGHT 540 CSS ${WIVRN_CSS_ABS})
|
||||
wivrn_rasterize_svg(SOURCE ${IMAGES_SRC_DIR}/wivrn-pride.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/wivrn-pride.png WIDTH 540 HEIGHT 540 CSS ${WIVRN_CSS_ABS})
|
||||
wivrn_rasterize_svg(SOURCE ${ASSETS_SRC_DIR}/passthrough.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/passthrough.png WIDTH 256 HEIGHT 256)
|
||||
wivrn_rasterize_svg(SOURCE ${ASSETS_SRC_DIR}/default-environment.svg DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/default-environment.png WIDTH 256 HEIGHT 256)
|
||||
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.png
|
||||
COMMAND ${RSVG_CONVERT} ${IMG_SRC_DIR}/wivrn-pride.svg -w 540 -h 540 -o ${ASSETS_DIR}/wivrn-pride.png ${RSVG_OPTS}
|
||||
DEPENDS ${IMG_SRC_DIR}/wivrn-pride.svg ${WIVRN_CSS_ABS})
|
||||
|
||||
add_custom_target(assets ALL DEPENDS
|
||||
${ASSETS_DIR}/wivrn.png
|
||||
${ASSETS_DIR}/wivrn-pride.png
|
||||
)
|
||||
|
||||
add_dependencies(wivrn assets)
|
||||
|
||||
if(ANDROID)
|
||||
find_program(TOKTX toktx REQUIRED)
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn.ktx2
|
||||
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn.ktx2 ${ASSETS_DIR}/wivrn.png
|
||||
DEPENDS ${ASSETS_DIR}/wivrn.png)
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/wivrn-pride.ktx2
|
||||
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/wivrn-pride.png
|
||||
DEPENDS ${ASSETS_DIR}/wivrn-pride.png)
|
||||
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/default_icon.ktx2
|
||||
COMMAND ${TOKTX} --encode astc --astc_blk_d 4x4 --astc_quality 100 --genmipmap ${ASSETS_DIR}/wivrn-pride.ktx2 ${ASSETS_DIR}/default_icon.png
|
||||
DEPENDS ${ASSETS_DIR}/default_icon.png)
|
||||
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
|
||||
COMMAND ${TOKTX} --encode astc --astc_blk_d 12x12 --astc_quality 100 --genmipmap ${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2 ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg
|
||||
DEPENDS ${AST_SRC_DIR}/WoodFloor051_1K-JPG_Color.jpg)
|
||||
|
||||
add_custom_command(OUTPUT ${ASSETS_DIR}/vr_splash.png
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${ASSETS_DIR}/wivrn.png ${ASSETS_DIR}/vr_splash.png
|
||||
DEPENDS ${ASSETS_DIR}/wivrn.png)
|
||||
|
||||
add_custom_target(assets-android ALL DEPENDS
|
||||
${ASSETS_DIR}/wivrn.ktx2
|
||||
${ASSETS_DIR}/wivrn-pride.ktx2
|
||||
${ASSETS_DIR}/WoodFloor051_1K-JPG_Color.ktx2
|
||||
${ASSETS_DIR}/vr_splash.png
|
||||
)
|
||||
add_dependencies(assets-android assets)
|
||||
add_dependencies(wivrn assets-android)
|
||||
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png DESTINATION ${ASSETS_DIR}/wivrn.ktx2 TARGET wivrn)
|
||||
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn-pride.png DESTINATION ${ASSETS_DIR}/wivrn-pride.ktx2 TARGET wivrn)
|
||||
wivrn_generate_ktx( SOURCE ${ASSETS_SRC_DIR}/default_icon.png DESTINATION ${ASSETS_DIR}/default_icon.ktx2 TARGET wivrn)
|
||||
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/passthrough.png DESTINATION ${ASSETS_DIR}/passthrough.ktx2 TARGET wivrn)
|
||||
wivrn_generate_ktx( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/default-environment.png DESTINATION ${ASSETS_DIR}/default-environment.ktx2 TARGET wivrn)
|
||||
if(WIVRN_COMPRESS_GLB)
|
||||
wivrn_gltf_transform_uastc(SOURCE ${ASSETS_SRC_DIR}/ground.glb DESTINATION ${ASSETS_DIR}/ground.glb TARGET wivrn ZSTD 20)
|
||||
else()
|
||||
wivrn_copy_file( SOURCE ${ASSETS_SRC_DIR}/ground.glb DESTINATION ${ASSETS_DIR}/ground.glb TARGET wivrn)
|
||||
endif()
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/generic-trigger-squeeze DESTINATION ${ASSETS_DIR}/controllers/generic-trigger-squeeze TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/htc-vive-focus-3 DESTINATION ${ASSETS_DIR}/controllers/htc-vive-focus-3 TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/meta-quest-touch-plus DESTINATION ${ASSETS_DIR}/controllers/meta-quest-touch-plus TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/meta-quest-touch-pro DESTINATION ${ASSETS_DIR}/controllers/meta-quest-touch-pro TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/oculus-touch-v2 DESTINATION ${ASSETS_DIR}/controllers/oculus-touch-v2 TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/oculus-touch-v3 DESTINATION ${ASSETS_DIR}/controllers/oculus-touch-v3 TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/pico-4 DESTINATION ${ASSETS_DIR}/controllers/pico-4 TARGET wivrn)
|
||||
wivrn_webxr_controller( SOURCE ${ASSETS_SRC_DIR}/controllers/pico-neo3 DESTINATION ${ASSETS_DIR}/controllers/pico-neo3 TARGET wivrn)
|
||||
|
||||
|
||||
# Add the VR splash screen (only used on Quest)
|
||||
if(ANDROID)
|
||||
wivrn_copy_file(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png DESTINATION ${ASSETS_DIR}/vr_splash.png TARGET wivrn)
|
||||
endif()
|
||||
|
||||
##############################################################################
|
||||
# Copy the assets to be able to find them when started from the build
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "intent.h"
|
||||
#include "application.h"
|
||||
#include <unordered_map>
|
||||
|
||||
static int next_request_code;
|
||||
static std::unordered_map<int, std::function<void(int, intent &&)>> callbacks;
|
||||
|
||||
intent::intent(const char * intent_type) :
|
||||
obj(jni::new_object<"android/content/Intent">(jni::string{intent_type}))
|
||||
{
|
||||
}
|
||||
|
||||
intent::intent(jobject jni_obj) :
|
||||
obj(jni_obj)
|
||||
{
|
||||
}
|
||||
|
||||
void intent::set_type(const char * type)
|
||||
{
|
||||
obj.call<jni::object<"android/content/Intent">>("setType", jni::string{type});
|
||||
}
|
||||
|
||||
void intent::add_category(const char * category)
|
||||
{
|
||||
obj.call<jni::object<"android/content/Intent">>("addCategory", jni::string{category});
|
||||
}
|
||||
|
||||
void intent::start(std::function<void(int, intent &&)> callback)
|
||||
{
|
||||
int request_code = next_request_code++;
|
||||
|
||||
callbacks.emplace(request_code, std::move(callback));
|
||||
|
||||
jni::object<""> activity(application::native_app()->activity->clazz);
|
||||
|
||||
activity.call<void>("startActivityForResult", obj, jni::Int{request_code});
|
||||
}
|
||||
|
||||
jni::object<"android/net/Uri"> intent::get_uri()
|
||||
{
|
||||
return obj.call<jni::object<"android/net/Uri">>("getData");
|
||||
}
|
||||
|
||||
extern "C" __attribute__((visibility("default"))) void Java_org_meumeu_wivrn_MainActivity_onActivityResult(JNIEnv * env, jobject instance, int request_code, int result_code, jobject data_obj)
|
||||
{
|
||||
auto it = callbacks.find(request_code);
|
||||
if (it == callbacks.end())
|
||||
return;
|
||||
|
||||
it->second(result_code, intent{data_obj});
|
||||
|
||||
callbacks.erase(it);
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "jnipp.h"
|
||||
#include <functional>
|
||||
|
||||
class intent
|
||||
{
|
||||
jni::object<"android/content/Intent"> obj;
|
||||
|
||||
public:
|
||||
intent(const char * intent_type);
|
||||
intent(jobject);
|
||||
|
||||
void set_type(const char * type);
|
||||
void add_category(const char * category);
|
||||
|
||||
void start(std::function<void(int, intent &&)> callback);
|
||||
|
||||
jni::object<"android/net/Uri"> get_uri();
|
||||
};
|
||||
@@ -85,6 +85,30 @@ struct Void
|
||||
constexpr static const auto call_static_method = &_JNIEnv::CallStaticVoidMethod;
|
||||
};
|
||||
|
||||
struct Int
|
||||
{
|
||||
constexpr static auto static_field = &_JNIEnv::GetStaticIntField;
|
||||
constexpr static const auto call_method = &_JNIEnv::CallIntMethod;
|
||||
constexpr static const auto call_static_method = &_JNIEnv::CallStaticIntMethod;
|
||||
|
||||
static std::string type()
|
||||
{
|
||||
return "I";
|
||||
}
|
||||
|
||||
int value;
|
||||
|
||||
int handle() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
operator int() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
namespace details
|
||||
{
|
||||
|
||||
@@ -139,6 +163,12 @@ struct type_map<void>
|
||||
using type = jni::Void;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct type_map<int>
|
||||
{
|
||||
using type = jni::Int;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
using type_map_t = type_map<T>::type;
|
||||
} // namespace details
|
||||
@@ -224,30 +254,6 @@ struct Bool
|
||||
}
|
||||
};
|
||||
|
||||
struct Int
|
||||
{
|
||||
constexpr static auto static_field = &_JNIEnv::GetStaticIntField;
|
||||
constexpr static const auto call_method = &_JNIEnv::CallIntMethod;
|
||||
constexpr static const auto call_static_method = &_JNIEnv::CallStaticIntMethod;
|
||||
|
||||
static std::string type()
|
||||
{
|
||||
return "I";
|
||||
}
|
||||
|
||||
int value;
|
||||
|
||||
int handle() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
operator int() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <details::string_literal Type>
|
||||
struct object
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "utils/i18n.h"
|
||||
#include "vk/check.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "xr/actionset.h"
|
||||
#include "xr/check.h"
|
||||
#include "xr/htc_exts.h"
|
||||
@@ -759,13 +759,14 @@ void application::initialize_vulkan()
|
||||
spdlog::info(" {} (version {})", extension_name, spec_version);
|
||||
|
||||
vk_device_extensions.push_back(VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_MULTIVIEW_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_IMG_FILTER_CUBIC_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME);
|
||||
optional_device_extensions.emplace(VK_EXT_FRAGMENT_DENSITY_MAP_EXTENSION_NAME);
|
||||
|
||||
#ifdef __ANDROID__
|
||||
vk_device_extensions.push_back(VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_EXT_QUEUE_FAMILY_FOREIGN_EXTENSION_NAME);
|
||||
vk_device_extensions.push_back(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME);
|
||||
@@ -880,28 +881,26 @@ void application::initialize_vulkan()
|
||||
.ppEnabledExtensionNames = vk_device_extensions.data(),
|
||||
.pEnabledFeatures = &device_features,
|
||||
},
|
||||
vk::PhysicalDeviceFragmentShadingRateFeaturesKHR{},
|
||||
#ifdef __ANDROID__
|
||||
vk::PhysicalDeviceSamplerYcbcrConversionFeaturesKHR{
|
||||
.samplerYcbcrConversion = VK_TRUE,
|
||||
.samplerYcbcrConversion = true,
|
||||
},
|
||||
vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR{
|
||||
.timelineSemaphore = true,
|
||||
},
|
||||
vk::PhysicalDeviceMultiviewFeaturesKHR{
|
||||
.multiview = true,
|
||||
},
|
||||
#endif
|
||||
};
|
||||
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
|
||||
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME))
|
||||
{
|
||||
auto [feat, fragment_feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
auto & create_feat = device_create_info.get<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
create_feat.primitiveFragmentShadingRate = fragment_feat.primitiveFragmentShadingRate;
|
||||
create_feat.attachmentFragmentShadingRate = fragment_feat.attachmentFragmentShadingRate;
|
||||
spdlog::info("Fragment shading rate features: primitive={} attachment={}",
|
||||
create_feat.primitiveFragmentShadingRate,
|
||||
create_feat.attachmentFragmentShadingRate);
|
||||
auto [_, feat] = vk_physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||
auto & create_feat = device_create_info.get<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||
create_feat.timelineSemaphore = feat.timelineSemaphore;
|
||||
}
|
||||
else
|
||||
{
|
||||
device_create_info.unlink<vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
device_create_info.unlink<vk::PhysicalDeviceTimelineSemaphoreFeaturesKHR>();
|
||||
}
|
||||
|
||||
vk_device = xr_system_id.create_device(vk_physical_device, device_create_info.get());
|
||||
@@ -1222,6 +1221,10 @@ void application::initialize()
|
||||
opt_extensions.push_back(XR_EXT_USER_PRESENCE_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_KHR_VISIBILITY_MASK_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_COMPOSITION_LAYER_SETTINGS_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_CONFIGURATION_EXTENSION_NAME);
|
||||
opt_extensions.push_back(XR_FB_FOVEATION_VULKAN_EXTENSION_NAME);
|
||||
|
||||
for (const auto & i: interaction_profiles)
|
||||
opt_extensions.insert(opt_extensions.end(), i.required_extensions.begin(), i.required_extensions.end());
|
||||
@@ -1376,7 +1379,7 @@ void application::load_locale()
|
||||
std::locale::global(loc);
|
||||
}
|
||||
|
||||
std::pair<XrAction, XrActionType> application::get_action(const std::string & requested_name)
|
||||
std::pair<XrAction, XrActionType> application::get_action(std::string_view requested_name)
|
||||
{
|
||||
for (const auto & [action, type, name]: instance().actions)
|
||||
{
|
||||
@@ -1574,15 +1577,21 @@ void application::loop()
|
||||
poll_events();
|
||||
|
||||
auto scene = current_scene();
|
||||
if (!is_session_running())
|
||||
if (not is_session_running())
|
||||
{
|
||||
if (scene)
|
||||
if (not timestamp_unsynchronized)
|
||||
timestamp_unsynchronized = std::chrono::steady_clock::now();
|
||||
|
||||
if (scene and std::chrono::steady_clock::now() - *timestamp_unsynchronized > 3s)
|
||||
scene->set_focused(false);
|
||||
|
||||
// Throttle loop since xrWaitFrame won't be called.
|
||||
std::this_thread::sleep_for(250ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
timestamp_unsynchronized.reset();
|
||||
|
||||
if (scene)
|
||||
{
|
||||
poll_actions();
|
||||
@@ -1605,6 +1614,7 @@ void application::loop()
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::info("Last scene was popped");
|
||||
exit_requested = true;
|
||||
}
|
||||
}
|
||||
@@ -1633,6 +1643,7 @@ void application::run()
|
||||
exit_requested = true;
|
||||
}
|
||||
}
|
||||
spdlog::info("Exiting application_thread");
|
||||
});
|
||||
|
||||
// Read all pending events.
|
||||
@@ -1651,10 +1662,13 @@ void application::run()
|
||||
|
||||
if (app_info.native_app->destroyRequested)
|
||||
{
|
||||
spdlog::info("app_info.native_app->destroyRequested is true");
|
||||
exit_requested = true;
|
||||
}
|
||||
}
|
||||
|
||||
spdlog::info("Exiting normally");
|
||||
|
||||
application_thread.join();
|
||||
}
|
||||
#else
|
||||
@@ -1851,6 +1865,7 @@ void application::poll_events()
|
||||
switch (e.header.type)
|
||||
{
|
||||
case XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING: {
|
||||
spdlog::info("Received XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING");
|
||||
exit_requested = true;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -132,6 +132,8 @@ class application : public singleton<application>
|
||||
bool session_running = false;
|
||||
bool session_focused = false;
|
||||
bool session_visible = false;
|
||||
std::optional<std::chrono::steady_clock::time_point> timestamp_unsynchronized; // Timestamp when session_synchronized becomes false
|
||||
|
||||
bool debug_extensions_found = false;
|
||||
std::vector<const char *> vk_device_extensions;
|
||||
std::atomic<bool> exit_requested = false;
|
||||
@@ -231,7 +233,7 @@ public:
|
||||
{
|
||||
return instance().actions;
|
||||
}
|
||||
static std::pair<XrAction, XrActionType> get_action(const std::string & name);
|
||||
static std::pair<XrAction, XrActionType> get_action(std::string_view name);
|
||||
|
||||
static std::optional<std::pair<glm::vec3, glm::quat>> locate_controller(XrSpace space, XrSpace reference, XrTime time)
|
||||
{
|
||||
@@ -357,6 +359,11 @@ public:
|
||||
return instance().vk_instance;
|
||||
}
|
||||
|
||||
static vk::raii::PhysicalDevice & get_physical_device()
|
||||
{
|
||||
return instance().vk_physical_device;
|
||||
}
|
||||
|
||||
static xr::system & get_system()
|
||||
{
|
||||
return instance().xr_system_id;
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "asset.h"
|
||||
#include "application.h"
|
||||
#include "utils/files.h"
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/asset_manager.h>
|
||||
|
||||
asset::asset(const std::filesystem::path & path)
|
||||
{
|
||||
spdlog::debug("Loading Android asset {}", path.string());
|
||||
android_asset = AAssetManager_open(application::asset_manager(), path.c_str(), AASSET_MODE_BUFFER);
|
||||
|
||||
if (!android_asset)
|
||||
throw std::runtime_error("Cannot open Android asset " + path.string());
|
||||
|
||||
bytes = std::span<const std::byte>{reinterpret_cast<const std::byte *>(AAsset_getBuffer(android_asset)), (size_t)AAsset_getLength64(android_asset)};
|
||||
}
|
||||
|
||||
asset::asset(asset && other) :
|
||||
android_asset(other.android_asset)
|
||||
{
|
||||
other.android_asset = nullptr;
|
||||
}
|
||||
|
||||
asset & asset::operator=(asset && other)
|
||||
{
|
||||
std::swap(android_asset, other.android_asset);
|
||||
return *this;
|
||||
}
|
||||
|
||||
asset::~asset()
|
||||
{
|
||||
if (android_asset)
|
||||
AAsset_close(android_asset);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static std::filesystem::path get_exe_path()
|
||||
{
|
||||
// Linux only: see https://stackoverflow.com/a/1024937
|
||||
return std::filesystem::read_symlink("/proc/self/exe");
|
||||
}
|
||||
|
||||
static std::filesystem::path get_asset_root()
|
||||
{
|
||||
const char * path = std::getenv("WIVRN_ASSET_ROOT");
|
||||
if (path && strcmp(path, ""))
|
||||
return path;
|
||||
|
||||
return get_exe_path().parent_path().parent_path() / "share" / "wivrn" / "assets";
|
||||
}
|
||||
|
||||
static std::filesystem::path get_locale_root()
|
||||
{
|
||||
const char * path = std::getenv("WIVRN_LOCALE_ROOT");
|
||||
if (path && strcmp(path, ""))
|
||||
return path;
|
||||
|
||||
return get_exe_path().parent_path().parent_path() / "share" / "locale";
|
||||
}
|
||||
|
||||
std::filesystem::path asset::asset_root()
|
||||
{
|
||||
static std::filesystem::path root = get_asset_root();
|
||||
return root;
|
||||
}
|
||||
|
||||
std::filesystem::path asset::locale_root()
|
||||
{
|
||||
static std::filesystem::path root = get_locale_root();
|
||||
return root;
|
||||
}
|
||||
|
||||
asset::asset(const std::filesystem::path & path)
|
||||
{
|
||||
assert(path.is_relative());
|
||||
|
||||
// TODO mmap
|
||||
// TODO load only once if it is already loaded
|
||||
|
||||
spdlog::debug("Loading file asset {}", path.string());
|
||||
|
||||
if (path.native().starts_with("locale/"))
|
||||
{
|
||||
bytes = utils::read_whole_file<std::byte>(locale_root() / path.native().substr(7));
|
||||
}
|
||||
else
|
||||
{
|
||||
bytes = utils::read_whole_file<std::byte>(asset_root() / path);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "configuration.h"
|
||||
#include "application.h"
|
||||
#include "utils/json_string.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -27,56 +28,6 @@
|
||||
#include "android/permissions.h"
|
||||
#endif
|
||||
|
||||
static std::string json_string(const std::string & in)
|
||||
{
|
||||
std::string out;
|
||||
out.reserve(in.size() + 2);
|
||||
|
||||
out += '"';
|
||||
|
||||
for (char c: in)
|
||||
{
|
||||
switch (c)
|
||||
{
|
||||
case '\b':
|
||||
out += "\\b";
|
||||
break;
|
||||
|
||||
case '\f':
|
||||
out += "\\f";
|
||||
break;
|
||||
|
||||
case '\n':
|
||||
out += "\\n";
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
out += "\\r";
|
||||
break;
|
||||
|
||||
case '\t':
|
||||
out += "\\t";
|
||||
break;
|
||||
|
||||
case '"':
|
||||
out += "\\\"";
|
||||
break;
|
||||
|
||||
case '\\':
|
||||
out += "\\\\";
|
||||
break;
|
||||
|
||||
default:
|
||||
out += c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out += '"';
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
bool configuration::check_feature(feature f) const
|
||||
{
|
||||
{
|
||||
@@ -221,6 +172,9 @@ configuration::configuration(xr::system & system)
|
||||
|
||||
if (auto val = root["locale"]; val.is_string())
|
||||
locale = val.get_string().value();
|
||||
|
||||
if (auto val = root["environment_model"]; val.is_string())
|
||||
environment_model = (std::string_view)val.get_string();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
@@ -308,5 +262,6 @@ void configuration::save()
|
||||
json << ",\"override_foveation_distance\":" << override_foveation_distance;
|
||||
json << ",\"first_run\":" << std::boolalpha << first_run;
|
||||
json << ",\"locale\":" << json_string(locale);
|
||||
json << ",\"environment_model\":" << json_string(environment_model);
|
||||
json << "}";
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
std::string virtual_keyboard_layout = "QWERTY";
|
||||
|
||||
std::string environment_model = "assets://ground.glb";
|
||||
|
||||
bool override_foveation_enable = false;
|
||||
float override_foveation_pitch = 10 * M_PI / 180;
|
||||
float override_foveation_distance = 3;
|
||||
|
||||
@@ -59,6 +59,8 @@ const char * mime(wivrn::video_codec codec)
|
||||
return "video/hevc";
|
||||
case c::av1:
|
||||
return "video/av01";
|
||||
case c::raw:
|
||||
break;
|
||||
}
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
@@ -562,7 +564,7 @@ static bool hardware_accelerated(AMediaCodec * media_codec)
|
||||
void decoder::supported_codecs(std::vector<wivrn::video_codec> & result)
|
||||
{
|
||||
// Make sure we update this code when codecs are changed
|
||||
static_assert(magic_enum::enum_count<wivrn::video_codec>() == 3);
|
||||
static_assert(magic_enum::enum_count<wivrn::video_codec>() == 4);
|
||||
|
||||
// In order or preference, from preferred to least preferred
|
||||
for (auto codec: {
|
||||
|
||||
@@ -23,36 +23,54 @@
|
||||
#else
|
||||
#include "decoder/ffmpeg/ffmpeg_decoder.h"
|
||||
#endif
|
||||
#include "decoder/raw_decoder.h"
|
||||
|
||||
wivrn::decoder::~decoder() = default;
|
||||
|
||||
std::shared_ptr<wivrn::decoder> wivrn::decoder::make(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & phys_dev,
|
||||
uint32_t vk_queue_family_index,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * acc)
|
||||
{
|
||||
switch (description.codec)
|
||||
{
|
||||
case h264:
|
||||
case h265:
|
||||
case av1:
|
||||
#ifdef __ANDROID__
|
||||
return std::make_shared<wivrn::android::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
fps,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
return std::make_shared<wivrn::android::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
fps,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
#else
|
||||
return std::make_shared<wivrn::ffmpeg::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
return std::make_shared<wivrn::ffmpeg::decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
description,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
#endif
|
||||
case raw:
|
||||
return std::make_shared<wivrn::raw_decoder>(
|
||||
device,
|
||||
phys_dev,
|
||||
vk_queue_family_index,
|
||||
description,
|
||||
stream_index,
|
||||
scene,
|
||||
acc);
|
||||
}
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
std::vector<wivrn::video_codec> wivrn::decoder::supported_codecs()
|
||||
@@ -63,5 +81,6 @@ std::vector<wivrn::video_codec> wivrn::decoder::supported_codecs()
|
||||
#else
|
||||
ffmpeg::decoder::supported_codecs(res);
|
||||
#endif
|
||||
res.push_back(video_codec::raw);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,8 @@ public:
|
||||
vk::ImageView image_view = nullptr;
|
||||
vk::Image image = nullptr;
|
||||
vk::ImageLayout & current_layout;
|
||||
vk::Semaphore semaphore = nullptr;
|
||||
uint64_t * semaphore_val = nullptr;
|
||||
};
|
||||
|
||||
const wivrn::to_headset::video_stream_description::item description;
|
||||
@@ -56,6 +58,7 @@ public:
|
||||
static std::shared_ptr<decoder> make(
|
||||
vk::raii::Device &,
|
||||
vk::raii::PhysicalDevice &,
|
||||
uint32_t vk_queue_family_index,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
uint8_t stream_index,
|
||||
|
||||
@@ -56,6 +56,8 @@ static AVCodecID codec_id(wivrn::video_codec codec)
|
||||
return AV_CODEC_ID_HEVC;
|
||||
case c::av1:
|
||||
return AV_CODEC_ID_AV1;
|
||||
case c::raw:
|
||||
break;
|
||||
}
|
||||
assert(false);
|
||||
__builtin_unreachable();
|
||||
|
||||
@@ -0,0 +1,353 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "raw_decoder.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "scenes/stream.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct raw_blit_handle : public wivrn::decoder::blit_handle
|
||||
{
|
||||
std::atomic_bool & free;
|
||||
|
||||
raw_blit_handle(
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info,
|
||||
vk::ImageView image_view,
|
||||
vk::Image image,
|
||||
vk::ImageLayout & current_layout,
|
||||
vk::Semaphore semaphore,
|
||||
uint64_t & semaphore_val,
|
||||
std::atomic_bool & free) :
|
||||
wivrn::decoder::blit_handle{feedback, view_info, image_view, image, current_layout, semaphore, &semaphore_val},
|
||||
free(free) {}
|
||||
~raw_blit_handle()
|
||||
{
|
||||
free = true;
|
||||
};
|
||||
};
|
||||
|
||||
vk::raii::Sampler make_sampler(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::SamplerYcbcrConversion & ycbcr_conversion,
|
||||
to_headset::video_stream_description::channels_t channels)
|
||||
{
|
||||
vk::StructureChain info{
|
||||
vk::SamplerCreateInfo{
|
||||
.magFilter = vk::Filter::eNearest,
|
||||
.minFilter = vk::Filter::eNearest,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eNearest,
|
||||
.addressModeU = vk::SamplerAddressMode::eClampToEdge,
|
||||
.addressModeV = vk::SamplerAddressMode::eClampToEdge,
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToEdge,
|
||||
.maxAnisotropy = 1,
|
||||
},
|
||||
vk::SamplerYcbcrConversionInfo{
|
||||
.conversion = *ycbcr_conversion,
|
||||
},
|
||||
};
|
||||
switch (channels)
|
||||
{
|
||||
case wivrn::to_headset::video_stream_description::channels_t::colour:
|
||||
break;
|
||||
case wivrn::to_headset::video_stream_description::channels_t::alpha:
|
||||
info.unlink<vk::SamplerYcbcrConversionInfo>();
|
||||
break;
|
||||
}
|
||||
return vk::raii::Sampler(device, info.get());
|
||||
}
|
||||
} // namespace
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
raw_decoder::raw_decoder(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
uint32_t vk_queue_family_index,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * accumulator) :
|
||||
decoder(description),
|
||||
device(device),
|
||||
ycbcr_conversion(device,
|
||||
{
|
||||
.format = vk::Format::eG8B8R82Plane420Unorm,
|
||||
.ycbcrModel = vk::SamplerYcbcrModelConversion(description.color_model.value_or(VK_SAMPLER_YCBCR_MODEL_CONVERSION_YCBCR_709)),
|
||||
.ycbcrRange = vk::SamplerYcbcrRange(description.range.value_or(VK_SAMPLER_YCBCR_RANGE_ITU_FULL)),
|
||||
.chromaFilter = vk::Filter::eNearest,
|
||||
}),
|
||||
sampler_(make_sampler(device, ycbcr_conversion, description.channels)),
|
||||
command_pool(device, vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||
.queueFamilyIndex = vk_queue_family_index,
|
||||
}),
|
||||
cmd(device.allocateCommandBuffers(vk::CommandBufferAllocateInfo{
|
||||
.commandPool = *command_pool,
|
||||
.commandBufferCount = 1,
|
||||
})[0]
|
||||
.release()),
|
||||
fence(device, vk::FenceCreateInfo{.flags = vk::FenceCreateFlagBits::eSignaled}),
|
||||
weak_scene(scene),
|
||||
accumulator(accumulator)
|
||||
{
|
||||
extent_ = vk::Extent2D{
|
||||
.width = description.width,
|
||||
.height = description.height,
|
||||
};
|
||||
vk::DeviceSize buffer_size = description.width * description.height;
|
||||
vk::Format format{};
|
||||
switch (description.channels)
|
||||
{
|
||||
case to_headset::video_stream_description::channels_t::colour:
|
||||
buffer_size += (description.width * description.height) / 2;
|
||||
format = vk::Format::eG8B8R82Plane420Unorm;
|
||||
break;
|
||||
case to_headset::video_stream_description::channels_t::alpha:
|
||||
format = vk::Format::eR8Unorm;
|
||||
break;
|
||||
}
|
||||
for (auto & i: input)
|
||||
{
|
||||
i = buffer_allocation(
|
||||
device,
|
||||
{
|
||||
.size = buffer_size,
|
||||
.usage = vk::BufferUsageFlagBits::eTransferSrc,
|
||||
},
|
||||
{
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
"raw stream buffer");
|
||||
}
|
||||
input_pos = (uint8_t *)input[0].map();
|
||||
|
||||
for (auto & item: image_pool)
|
||||
{
|
||||
item.image = image_allocation(
|
||||
device,
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
.format = format,
|
||||
.extent = {
|
||||
.width = description.width,
|
||||
.height = description.height,
|
||||
.depth = 1,
|
||||
},
|
||||
.mipLevels = 1,
|
||||
.arrayLayers = 1,
|
||||
.tiling = vk::ImageTiling::eOptimal,
|
||||
.usage = vk::ImageUsageFlagBits::eSampled | vk::ImageUsageFlagBits::eTransferDst,
|
||||
},
|
||||
{
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
"raw image");
|
||||
|
||||
vk::SamplerYcbcrConversionInfo conv{
|
||||
.conversion = *ycbcr_conversion,
|
||||
};
|
||||
vk::ImageViewCreateInfo view_info{
|
||||
.pNext = format == vk::Format::eG8B8R82Plane420Unorm ? &conv : nullptr,
|
||||
.image = item.image,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
item.view_full = vk::raii::ImageView(device, view_info);
|
||||
|
||||
item.semaphore = vk::raii::Semaphore(
|
||||
device,
|
||||
vk::StructureChain{
|
||||
vk::SemaphoreCreateInfo{},
|
||||
vk::SemaphoreTypeCreateInfo{
|
||||
.semaphoreType = vk::SemaphoreType::eTimeline,
|
||||
},
|
||||
}
|
||||
.get());
|
||||
}
|
||||
}
|
||||
|
||||
void raw_decoder::push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial)
|
||||
{
|
||||
if (frame_index != current_frame)
|
||||
{
|
||||
input_pos = (uint8_t *)input[0].map();
|
||||
current_frame = frame_index;
|
||||
}
|
||||
for (const auto & item: data)
|
||||
{
|
||||
memcpy(input_pos, item.data(), item.size_bytes());
|
||||
input_pos += item.size();
|
||||
}
|
||||
}
|
||||
|
||||
void raw_decoder::frame_completed(
|
||||
const from_headset::feedback & feedback,
|
||||
const to_headset::video_stream_data_shard::view_info_t & view_info)
|
||||
{
|
||||
auto item = get_free();
|
||||
if (not item)
|
||||
{
|
||||
spdlog::warn("No image available in pool, discard frame");
|
||||
return;
|
||||
}
|
||||
|
||||
auto handle = std::make_shared<raw_blit_handle>(
|
||||
feedback,
|
||||
view_info,
|
||||
*item->view_full,
|
||||
item->image,
|
||||
item->current_layout,
|
||||
*item->semaphore,
|
||||
item->semaphore_val,
|
||||
item->free);
|
||||
|
||||
auto res = device.waitForFences(*fence, true, UINT64_MAX);
|
||||
if (res != vk::Result::eSuccess)
|
||||
spdlog::warn("waitForFences failed");
|
||||
|
||||
cmd.reset();
|
||||
cmd.begin({.flags = vk::CommandBufferUsageFlagBits::eOneTimeSubmit});
|
||||
|
||||
if (item->current_layout != vk::ImageLayout::eTransferDstOptimal)
|
||||
{
|
||||
item->current_layout = vk::ImageLayout::eTransferDstOptimal;
|
||||
vk::ImageMemoryBarrier barrier{
|
||||
.srcAccessMask = vk::AccessFlagBits::eNone,
|
||||
.dstAccessMask = vk::AccessFlagBits::eMemoryWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = item->current_layout,
|
||||
.image = item->image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
cmd.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eAllCommands,
|
||||
vk::PipelineStageFlagBits::eTransfer,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
barrier);
|
||||
}
|
||||
|
||||
std::array regions{
|
||||
vk::BufferImageCopy{
|
||||
.imageSubresource = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::ePlane0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.imageExtent = {
|
||||
.width = description.width,
|
||||
.height = description.height,
|
||||
.depth = 1,
|
||||
},
|
||||
},
|
||||
vk::BufferImageCopy{
|
||||
.bufferOffset = vk::DeviceSize(description.width * description.height),
|
||||
.imageSubresource = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::ePlane1,
|
||||
.layerCount = 1,
|
||||
},
|
||||
.imageExtent = {
|
||||
.width = description.width / 2u,
|
||||
.height = description.height / 2u,
|
||||
.depth = 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
cmd.copyBufferToImage(
|
||||
input[0],
|
||||
item->image,
|
||||
item->current_layout,
|
||||
description.channels == to_headset::video_stream_description::channels_t::colour ? 2 : 1,
|
||||
regions.data());
|
||||
|
||||
vk::ImageMemoryBarrier barrier{
|
||||
.srcAccessMask = vk::AccessFlagBits::eMemoryWrite,
|
||||
.dstAccessMask = vk::AccessFlagBits::eMemoryRead,
|
||||
.oldLayout = item->current_layout,
|
||||
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
.image = item->image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.levelCount = 1,
|
||||
.layerCount = 1,
|
||||
},
|
||||
};
|
||||
item->current_layout = barrier.newLayout;
|
||||
cmd.pipelineBarrier(
|
||||
vk::PipelineStageFlagBits::eTransfer,
|
||||
vk::PipelineStageFlagBits::eFragmentShader,
|
||||
{},
|
||||
{},
|
||||
{},
|
||||
barrier);
|
||||
|
||||
cmd.end();
|
||||
|
||||
device.resetFences(*fence);
|
||||
application::get_queue().lock()->submit(
|
||||
vk::StructureChain{
|
||||
vk::SubmitInfo{
|
||||
.commandBufferCount = 1,
|
||||
.pCommandBuffers = &cmd,
|
||||
.signalSemaphoreCount = 1,
|
||||
.pSignalSemaphores = &*item->semaphore,
|
||||
},
|
||||
vk::TimelineSemaphoreSubmitInfo{
|
||||
.signalSemaphoreValueCount = 1,
|
||||
.pSignalSemaphoreValues = &++item->semaphore_val,
|
||||
},
|
||||
}
|
||||
.get(),
|
||||
*fence);
|
||||
|
||||
if (auto scene = weak_scene.lock())
|
||||
scene->push_blit_handle(accumulator, std::move(handle));
|
||||
|
||||
std::swap(input[0], input[1]);
|
||||
input_pos = (uint8_t *)input[0].map();
|
||||
}
|
||||
|
||||
raw_decoder::image * raw_decoder::get_free()
|
||||
{
|
||||
for (auto & item: image_pool)
|
||||
{
|
||||
if (item.free.exchange(false))
|
||||
return &item;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<wivrn::video_codec> raw_decoder::supported_codecs()
|
||||
{
|
||||
return {video_codec::raw};
|
||||
}
|
||||
} // namespace wivrn
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "decoder.h"
|
||||
|
||||
#include "vk/allocation.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
class raw_decoder : public decoder
|
||||
{
|
||||
private:
|
||||
static const int image_count = 5;
|
||||
struct image
|
||||
{
|
||||
image_allocation image;
|
||||
vk::raii::ImageView view_full = nullptr;
|
||||
vk::ImageLayout current_layout = vk::ImageLayout::eUndefined;
|
||||
std::atomic_bool free = true;
|
||||
vk::raii::Semaphore semaphore = nullptr;
|
||||
uint64_t semaphore_val = 0;
|
||||
};
|
||||
|
||||
vk::raii::Device & device;
|
||||
vk::raii::SamplerYcbcrConversion ycbcr_conversion;
|
||||
vk::raii::Sampler sampler_;
|
||||
|
||||
vk::raii::CommandPool command_pool;
|
||||
vk::CommandBuffer cmd;
|
||||
vk::raii::Fence fence;
|
||||
|
||||
std::array<image, image_count> image_pool;
|
||||
|
||||
std::weak_ptr<scenes::stream> weak_scene;
|
||||
shard_accumulator * accumulator;
|
||||
|
||||
uint64_t current_frame = 0;
|
||||
std::array<buffer_allocation, 2> input;
|
||||
uint8_t * input_pos;
|
||||
from_headset::feedback feedback;
|
||||
to_headset::video_stream_data_shard::view_info_t view_info;
|
||||
|
||||
public:
|
||||
raw_decoder(vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
uint32_t vk_queue_family_index,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
uint8_t stream_index,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
shard_accumulator * accumulator);
|
||||
|
||||
void push_data(std::span<std::span<const uint8_t>> data, uint64_t frame_index, bool partial) override;
|
||||
|
||||
void frame_completed(
|
||||
const wivrn::from_headset::feedback & feedback,
|
||||
const wivrn::to_headset::video_stream_data_shard::view_info_t & view_info) override;
|
||||
|
||||
vk::Sampler sampler() override
|
||||
{
|
||||
return *sampler_;
|
||||
}
|
||||
|
||||
vk::Extent2D image_size()
|
||||
{
|
||||
return {
|
||||
description.width,
|
||||
description.height,
|
||||
};
|
||||
}
|
||||
|
||||
static std::vector<wivrn::video_codec> supported_codecs();
|
||||
|
||||
private:
|
||||
image * get_free();
|
||||
};
|
||||
|
||||
} // namespace wivrn
|
||||
@@ -80,11 +80,12 @@ public:
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice & physical_device,
|
||||
xr::instance & instance,
|
||||
uint32_t vk_queue_family_index,
|
||||
const wivrn::to_headset::video_stream_description::item & description,
|
||||
float fps,
|
||||
std::weak_ptr<scenes::stream> scene,
|
||||
uint8_t stream_index) :
|
||||
decoder_(decoder::make(device, physical_device, description, fps, stream_index, scene, this)),
|
||||
decoder_(decoder::make(device, physical_device, vk_queue_family_index, description, fps, stream_index, scene, this)),
|
||||
current(stream_index),
|
||||
next(stream_index),
|
||||
weak_scene(scene),
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "file_picker.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include <exception>
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "android/intent.h"
|
||||
#endif
|
||||
|
||||
std::future<file_picker_result> file_picker::open()
|
||||
{
|
||||
// Put it in a shared_ptr because clang does not support std::move_only_function
|
||||
auto promise = std::make_shared<std::promise<file_picker_result>>();
|
||||
auto future = promise->get_future();
|
||||
|
||||
#ifdef __ANDROID__
|
||||
// https://developer.android.com/training/data-storage/shared/documents-files#open
|
||||
// https://developer.android.com/reference/android/content/Intent#ACTION_OPEN_DOCUMENT
|
||||
// https://developer.android.com/guide/components/intents-common#OpenFile
|
||||
|
||||
intent open_doc{"android.intent.action.OPEN_DOCUMENT"}; // Intent.ACTION_OPEN_DOCUMENT
|
||||
open_doc.set_type("*/*");
|
||||
open_doc.add_category("android.intent.category.OPENABLE"); // Intent.CATEGORY_OPENABLE
|
||||
open_doc.start([promise](int result_code, intent && data) mutable {
|
||||
try
|
||||
{
|
||||
if (result_code != -1 /* Activity.RESULT_OK */)
|
||||
return;
|
||||
|
||||
auto uri = data.get_uri();
|
||||
auto uri_string = (std::string)uri.call<jni::string>("toString");
|
||||
|
||||
jni::object<""> activity(application::native_app()->activity->clazz);
|
||||
auto content_resolver = activity.call<jni::object<"android/content/ContentResolver">>("getContentResolver");
|
||||
|
||||
content_resolver.call<void>("takePersistableUriPermission", uri, jni::Int{1} /* Intent.FLAG_GRANT_READ_URI_PERMISSION */);
|
||||
|
||||
auto pfd = content_resolver.call<jni::object<"android/os/ParcelFileDescriptor">>("openFileDescriptor", uri, jni::string{"r"});
|
||||
int fd = pfd.call<int>("getFd");
|
||||
|
||||
// The file descriptor is owned by the ParcelFileDescriptor, dup it before
|
||||
// passing it to mapped_file to ensure the original fd is not closed
|
||||
promise->set_value(file_picker_result{
|
||||
.path = uri_string,
|
||||
.file = utils::mapped_file{fd},
|
||||
});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
promise->set_exception(std::current_exception());
|
||||
}
|
||||
});
|
||||
#else
|
||||
// TODO
|
||||
#endif
|
||||
return future;
|
||||
}
|
||||
|
||||
void file_picker::display()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
// No-op on Android, the file picker is displayed by the OS
|
||||
#else
|
||||
// TODO
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/mapped_file.h"
|
||||
#include <future>
|
||||
|
||||
struct file_picker_result
|
||||
{
|
||||
std::filesystem::path path;
|
||||
utils::mapped_file file;
|
||||
};
|
||||
|
||||
class file_picker
|
||||
{
|
||||
public:
|
||||
[[nodiscard]] std::future<file_picker_result> open();
|
||||
void display();
|
||||
};
|
||||
@@ -403,9 +403,9 @@ std::string controller_ray_model_name()
|
||||
case model::htc_vive_xr_elite:
|
||||
// XR Elite's runtime always assume alpha is unpremultiplied in the composition layers
|
||||
// Assume it's the same for all HTC headsets
|
||||
return "ray-htc.gltf";
|
||||
return "assets://ray-htc.glb";
|
||||
|
||||
default:
|
||||
return "ray.gltf";
|
||||
return "assets://ray.glb";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ public class MainActivity extends android.app.NativeActivity
|
||||
@Override
|
||||
public native void onNewIntent(android.content.Intent intent);
|
||||
|
||||
@Override
|
||||
public native void onActivityResult(int requestCode, int resultCode, android.content.Intent data);
|
||||
|
||||
private android.content.BroadcastReceiver BatteryInfoReceiver = null;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "libcurl.h"
|
||||
|
||||
#include "utils/mapped_file.h"
|
||||
#include "utils/named_thread.h"
|
||||
#include "version.h"
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <curl/curl.h>
|
||||
#include <curl/easy.h>
|
||||
#include <curl/multi.h>
|
||||
#include <exception>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <magic_enum.hpp>
|
||||
#include <mutex>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <stdexcept>
|
||||
#include <system_error>
|
||||
#include <thread>
|
||||
|
||||
libcurl::transfer::~transfer() {}
|
||||
libcurl::transfer_file::~transfer_file() {}
|
||||
libcurl::transfer_buffer::~transfer_buffer() {}
|
||||
|
||||
libcurl::libcurl()
|
||||
{
|
||||
if (CURLcode rc = curl_global_init(CURL_GLOBAL_DEFAULT); rc != CURLE_OK)
|
||||
{
|
||||
throw std::runtime_error{fmt::format("Cannot initialize libcurl: {}", curl_easy_strerror(rc))};
|
||||
|
||||
curl_version_info_data * data = curl_version_info(CURLVERSION_NOW);
|
||||
if (not(data->features & CURL_VERSION_THREADSAFE))
|
||||
spdlog::warn("libcurl features do not include CURL_VERSION_THREADSAFE");
|
||||
}
|
||||
|
||||
multi = curl_multi_init();
|
||||
if (not multi)
|
||||
{
|
||||
spdlog::error("curl_multi_init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
curl_thread = utils::named_thread("curl_thread", &libcurl::curl_thread_fn, this);
|
||||
}
|
||||
|
||||
void libcurl::curl_thread_fn()
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
// For Android, read all the certificates at start-up, the file names are not
|
||||
// in the correct format for the current verion of OpenSSL.
|
||||
// See https://stackoverflow.com/questions/25253823/how-to-make-ssl-peer-verify-work-on-android
|
||||
std::string ca_bundle;
|
||||
for (const std::filesystem::directory_entry & entry: std::filesystem::directory_iterator{"/system/etc/security/cacerts"})
|
||||
{
|
||||
if (not entry.is_regular_file())
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
utils::mapped_file cert{entry.path()};
|
||||
ca_bundle += cert;
|
||||
|
||||
// Make sure there is a newline before the next certificate
|
||||
if (ca_bundle != "" and ca_bundle.back() != '\n')
|
||||
ca_bundle += '\n';
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// Ignore errors
|
||||
}
|
||||
}
|
||||
|
||||
curl_blob ca_bundle_info{
|
||||
.data = ca_bundle.data(),
|
||||
.len = ca_bundle.size(),
|
||||
.flags = CURL_BLOB_NOCOPY,
|
||||
};
|
||||
#endif
|
||||
|
||||
std::string user_agent = std::string("WiVRn/") + wivrn::git_version;
|
||||
|
||||
// We can't use auto here because of curl_easy_setopt
|
||||
size_t (*write_callback)(void *, size_t, size_t, void *) = [](void * buffer, size_t size, size_t nmemb, void * userp) -> size_t {
|
||||
auto & xfer = *reinterpret_cast<libcurl::transfer *>(userp);
|
||||
|
||||
if (xfer.content_length < 0)
|
||||
{
|
||||
curl_off_t content_length;
|
||||
curl_easy_getinfo(xfer.curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T, &content_length);
|
||||
xfer.content_length = content_length;
|
||||
}
|
||||
|
||||
xfer.progress += size * nmemb;
|
||||
return xfer.write(buffer, size * nmemb);
|
||||
};
|
||||
|
||||
std::vector<std::shared_ptr<transfer>> current_transfers;
|
||||
while (not quit)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Wait for something to happen (network, new download, cancelled download)
|
||||
int numfds;
|
||||
if (CURLMcode rc = curl_multi_poll(multi, NULL, 0, 10000, &numfds); rc != CURLM_OK)
|
||||
throw std::runtime_error{fmt::format("curl_multi_poll failed: ", curl_multi_strerror(rc))};
|
||||
|
||||
// Only lock the mutex after curl_multi_poll
|
||||
std::unique_lock _{lock};
|
||||
|
||||
int still_running;
|
||||
if (CURLMcode rc = curl_multi_perform(multi, &still_running); rc != CURLM_OK)
|
||||
throw std::runtime_error{fmt::format("curl_multi_perform failed: ", curl_multi_strerror(rc))};
|
||||
|
||||
CURLMsg * msg;
|
||||
int msgs_in_queue;
|
||||
while ((msg = curl_multi_info_read(multi, &msgs_in_queue)) != nullptr)
|
||||
{
|
||||
auto iter = std::ranges::find_if(
|
||||
current_transfers,
|
||||
[&](std::shared_ptr<transfer> & x) {
|
||||
return x->curl == msg->easy_handle;
|
||||
});
|
||||
|
||||
if (iter == current_transfers.end())
|
||||
{
|
||||
spdlog::error("Received {} ({}) for an unknown transfer", magic_enum::enum_name(msg->msg), (int)msg->msg);
|
||||
continue;
|
||||
}
|
||||
|
||||
auto & xfer = **iter;
|
||||
switch (msg->msg)
|
||||
{
|
||||
case CURLMSG_NONE: // Not used
|
||||
case CURLMSG_LAST: // Not used
|
||||
break;
|
||||
|
||||
case CURLMSG_DONE: // msg->easy_handle has finished
|
||||
xfer.curl_code = msg->data.result;
|
||||
curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &xfer.response_code);
|
||||
|
||||
if (msg->data.result == CURLE_OK)
|
||||
{
|
||||
xfer.current_state = state::done;
|
||||
xfer.finish();
|
||||
}
|
||||
else
|
||||
{
|
||||
xfer.current_state = state::error;
|
||||
xfer.cancel();
|
||||
}
|
||||
|
||||
curl_multi_remove_handle(multi, msg->easy_handle);
|
||||
curl_easy_cleanup(msg->easy_handle);
|
||||
current_transfers.erase(iter);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
for (std::shared_ptr<transfer> & xfer: pending_transfers)
|
||||
{
|
||||
// See https://curl.se/libcurl/c/libcurl-tutorial.html and https://curl.se/libcurl/c/curl_easy_setopt.html
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_URL, xfer->url.c_str());
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_FOLLOWLOCATION, 1); // Older versions of libcurl don't have the constant CURLFOLLOW_ALL
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_FILETIME, 1); // Request remote file time
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_FAILONERROR, 1); // CURLE_HTTP_RETURNED_ERROR on HTTP error
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_WRITEDATA, xfer.get());
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_USERAGENT, user_agent.c_str());
|
||||
|
||||
#ifdef __ANDROID__
|
||||
curl_easy_setopt(xfer->curl, CURLOPT_CAINFO_BLOB, &ca_bundle_info);
|
||||
#endif
|
||||
|
||||
curl_multi_add_handle(multi, xfer->curl);
|
||||
current_transfers.push_back(std::move(xfer));
|
||||
}
|
||||
|
||||
for (std::shared_ptr<transfer> handle: pending_cancellations)
|
||||
{
|
||||
auto iter = std::ranges::find(current_transfers, handle);
|
||||
|
||||
// If the transfer cannot be found, it means it has already finished, this is not an error
|
||||
if (iter != current_transfers.end())
|
||||
{
|
||||
auto & xfer = **iter;
|
||||
xfer.current_state = state::cancelled;
|
||||
xfer.cancel();
|
||||
|
||||
curl_multi_remove_handle(multi, handle->curl);
|
||||
curl_easy_cleanup(handle->curl);
|
||||
current_transfers.erase(iter);
|
||||
|
||||
spdlog::info("Cancelled transfer from {}", xfer.url);
|
||||
}
|
||||
}
|
||||
|
||||
pending_transfers.clear();
|
||||
pending_cancellations.clear();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::error("Exception in curl thread: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock _{lock};
|
||||
for (auto & xfer: current_transfers)
|
||||
{
|
||||
xfer->current_state = state::cancelled;
|
||||
xfer->cancel();
|
||||
curl_multi_remove_handle(multi, xfer->curl);
|
||||
curl_easy_cleanup(xfer->curl);
|
||||
}
|
||||
|
||||
if (CURLMcode rc = curl_multi_cleanup(multi); rc != CURLM_OK)
|
||||
spdlog::warn("curl_multi_cleanup failed: {}", curl_multi_strerror(rc));
|
||||
}
|
||||
|
||||
libcurl::~libcurl()
|
||||
{
|
||||
quit = true;
|
||||
curl_multi_wakeup(multi);
|
||||
|
||||
if (curl_thread.joinable())
|
||||
curl_thread.join();
|
||||
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
void libcurl::curl_handle::sync()
|
||||
{
|
||||
if (lib and handle)
|
||||
{
|
||||
std::unique_lock _{lib->lock};
|
||||
|
||||
current_state = handle->current_state;
|
||||
curl_code = handle->curl_code;
|
||||
response_code = handle->response_code;
|
||||
content_length = handle->content_length;
|
||||
progress = handle->progress;
|
||||
|
||||
if (current_state == state::done)
|
||||
{
|
||||
if (auto h = dynamic_cast<transfer_buffer *>(handle.get()))
|
||||
{
|
||||
response = h->buffer;
|
||||
}
|
||||
else if (auto h = dynamic_cast<transfer_file *>(handle.get()))
|
||||
{
|
||||
path = h->final_path;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void libcurl::curl_handle::cancel()
|
||||
{
|
||||
if (lib and handle)
|
||||
{
|
||||
{
|
||||
std::unique_lock _{lib->lock};
|
||||
lib->pending_cancellations.emplace_back(handle);
|
||||
if (handle->current_state == state::transferring)
|
||||
handle->current_state = state::cancelling;
|
||||
}
|
||||
|
||||
curl_multi_wakeup(lib->multi);
|
||||
}
|
||||
}
|
||||
|
||||
size_t libcurl::transfer_file::write(void * data, size_t size) noexcept
|
||||
{
|
||||
stream.write(reinterpret_cast<const char *>(data), size);
|
||||
if (not stream)
|
||||
return CURL_WRITEFUNC_ERROR;
|
||||
return size;
|
||||
}
|
||||
|
||||
void libcurl::transfer_file::finish() noexcept
|
||||
{
|
||||
stream.close();
|
||||
std::filesystem::rename(temporary_path, final_path);
|
||||
|
||||
curl_off_t remote_timestamp;
|
||||
if (curl_easy_getinfo(curl, CURLINFO_FILETIME_T, &remote_timestamp) == CURLE_OK)
|
||||
{
|
||||
auto time = std::chrono::file_clock::from_sys(std::chrono::system_clock::from_time_t(remote_timestamp));
|
||||
std::filesystem::last_write_time(final_path, time);
|
||||
}
|
||||
}
|
||||
|
||||
void libcurl::transfer_file::cancel() noexcept
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(temporary_path, ec);
|
||||
}
|
||||
|
||||
libcurl::curl_handle libcurl::download(std::string url, std::filesystem::path path)
|
||||
{
|
||||
auto xfer = std::make_shared<transfer_file>();
|
||||
xfer->curl = curl_easy_init();
|
||||
xfer->url = url;
|
||||
xfer->final_path = path;
|
||||
xfer->temporary_path = path.native() + ".partial";
|
||||
xfer->stream.open(xfer->temporary_path, std::ios::out);
|
||||
xfer->current_state = state::transferring;
|
||||
|
||||
std::unique_lock _{lock};
|
||||
pending_transfers.push_back(xfer);
|
||||
|
||||
// The curl thread needs to be woken up to pick up the newly added handle without waiting for the timeout
|
||||
curl_multi_wakeup(multi);
|
||||
|
||||
return {this, xfer, path};
|
||||
}
|
||||
|
||||
size_t libcurl::transfer_buffer::write(void * data, size_t size) noexcept
|
||||
{
|
||||
buffer.append(reinterpret_cast<const char *>(data), size);
|
||||
return size;
|
||||
}
|
||||
|
||||
void libcurl::transfer_buffer::finish() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
void libcurl::transfer_buffer::cancel() noexcept
|
||||
{
|
||||
}
|
||||
|
||||
libcurl::curl_handle libcurl::download(std::string url)
|
||||
{
|
||||
auto xfer = std::make_shared<transfer_buffer>();
|
||||
xfer->curl = curl_easy_init();
|
||||
xfer->url = url;
|
||||
xfer->current_state = state::transferring;
|
||||
|
||||
std::unique_lock _{lock};
|
||||
pending_transfers.push_back(xfer);
|
||||
|
||||
// The curl thread needs to be woken up to pick up the newly added handle without waiting for the timeout
|
||||
curl_multi_wakeup(multi);
|
||||
|
||||
return {this, xfer};
|
||||
}
|
||||
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <curl/curl.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
class libcurl
|
||||
{
|
||||
friend class curl_handle;
|
||||
|
||||
public:
|
||||
enum class state
|
||||
{
|
||||
reset,
|
||||
transferring,
|
||||
cancelling,
|
||||
cancelled,
|
||||
error,
|
||||
done,
|
||||
};
|
||||
|
||||
private:
|
||||
struct transfer
|
||||
{
|
||||
CURL * curl;
|
||||
std::string url;
|
||||
|
||||
state current_state = state::reset;
|
||||
CURLcode curl_code = CURLE_OK;
|
||||
long response_code = 0;
|
||||
int64_t content_length = -1;
|
||||
int64_t progress = 0;
|
||||
|
||||
transfer() = default;
|
||||
|
||||
// A pointer to a transfer struct is used as a user pointer for curl callbacks,
|
||||
// make sure it never moves
|
||||
transfer(const transfer &) = delete;
|
||||
transfer(transfer &&) = delete;
|
||||
transfer operator=(const transfer &) = delete;
|
||||
transfer operator=(transfer &&) = delete;
|
||||
virtual ~transfer();
|
||||
|
||||
virtual size_t write(void * data, size_t size) noexcept = 0;
|
||||
virtual void finish() noexcept = 0;
|
||||
virtual void cancel() noexcept = 0;
|
||||
};
|
||||
|
||||
struct transfer_file : transfer
|
||||
{
|
||||
virtual ~transfer_file();
|
||||
|
||||
std::filesystem::path temporary_path;
|
||||
std::filesystem::path final_path;
|
||||
std::fstream stream;
|
||||
|
||||
size_t write(void * data, size_t size) noexcept override;
|
||||
void finish() noexcept override;
|
||||
void cancel() noexcept override;
|
||||
};
|
||||
|
||||
struct transfer_buffer : transfer
|
||||
{
|
||||
virtual ~transfer_buffer();
|
||||
|
||||
std::string buffer;
|
||||
|
||||
size_t write(void * data, size_t size) noexcept override;
|
||||
void finish() noexcept override;
|
||||
void cancel() noexcept override;
|
||||
};
|
||||
|
||||
public:
|
||||
libcurl();
|
||||
libcurl(const libcurl &) = delete;
|
||||
libcurl(libcurl &&) = delete;
|
||||
libcurl operator=(const libcurl &) = delete;
|
||||
libcurl operator=(libcurl &&) = delete;
|
||||
~libcurl();
|
||||
|
||||
// Handle returned by the download() functions, it allows cancelling an ongoing transfer
|
||||
// by calling cancel() or destroying the handle
|
||||
class curl_handle
|
||||
{
|
||||
private:
|
||||
libcurl * lib = nullptr;
|
||||
std::shared_ptr<transfer> handle;
|
||||
|
||||
std::filesystem::path path;
|
||||
std::string response;
|
||||
|
||||
state current_state = state::reset;
|
||||
CURLcode curl_code = CURLE_OK;
|
||||
int response_code = 0;
|
||||
int64_t content_length = -1;
|
||||
int64_t progress = 0;
|
||||
|
||||
friend class libcurl;
|
||||
|
||||
curl_handle(libcurl * lib, std::shared_ptr<transfer> handle, std::filesystem::path path = {}) :
|
||||
lib(lib), handle(handle), path(std::move(path)) {}
|
||||
|
||||
public:
|
||||
curl_handle() = default;
|
||||
curl_handle(const curl_handle &) = delete;
|
||||
curl_handle & operator=(const curl_handle &) = delete;
|
||||
curl_handle(curl_handle && other) :
|
||||
lib(other.lib),
|
||||
handle(other.handle),
|
||||
path(std::move(other.path)),
|
||||
response(std::move(other.response)),
|
||||
current_state(other.current_state),
|
||||
curl_code(other.curl_code),
|
||||
response_code(other.response_code),
|
||||
content_length(other.content_length),
|
||||
progress(other.progress)
|
||||
{
|
||||
other.lib = nullptr;
|
||||
other.handle = nullptr;
|
||||
}
|
||||
|
||||
curl_handle & operator=(curl_handle && other)
|
||||
{
|
||||
std::swap(lib, other.lib);
|
||||
std::swap(handle, other.handle);
|
||||
path = std::move(other.path);
|
||||
response = std::move(other.response);
|
||||
current_state = other.current_state;
|
||||
curl_code = other.curl_code;
|
||||
response_code = other.response_code;
|
||||
content_length = other.content_length;
|
||||
progress = other.progress;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
~curl_handle()
|
||||
{
|
||||
cancel();
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
*this = curl_handle{};
|
||||
}
|
||||
|
||||
void sync();
|
||||
void cancel();
|
||||
|
||||
state get_state() const
|
||||
{
|
||||
return current_state;
|
||||
}
|
||||
|
||||
CURLcode get_curl_code() const
|
||||
{
|
||||
return curl_code;
|
||||
}
|
||||
|
||||
int get_response_code() const
|
||||
{
|
||||
return response_code;
|
||||
}
|
||||
|
||||
int64_t get_content_length() const
|
||||
{
|
||||
return content_length;
|
||||
}
|
||||
|
||||
int64_t get_progress() const
|
||||
{
|
||||
return progress;
|
||||
}
|
||||
|
||||
const std::string & get_response() const // Only if started by download(url) and state is done
|
||||
{
|
||||
assert(current_state == state::done);
|
||||
return response;
|
||||
}
|
||||
|
||||
std::span<const std::byte> get_response_bytes() const // Only if started by download(url) and state is done
|
||||
{
|
||||
assert(current_state == state::done);
|
||||
return {reinterpret_cast<const std::byte *>(response.data()), response.size()};
|
||||
}
|
||||
|
||||
const std::filesystem::path & get_path() const // Only if started by download(url, path) and state is done
|
||||
{
|
||||
assert(current_state == state::done);
|
||||
return path;
|
||||
}
|
||||
|
||||
const std::string & get_url() const
|
||||
{
|
||||
return handle->url;
|
||||
}
|
||||
};
|
||||
|
||||
// Start a download, data is saved on the filesystem
|
||||
// Keep the returned handle or the transfer will be immediately cancelled
|
||||
curl_handle download(std::string url, std::filesystem::path path);
|
||||
|
||||
// Start a download, data is buffered and can be fetched through the get_response() function of the curl_handle
|
||||
// Keep the returned handle or the transfer will be immediately cancelled
|
||||
curl_handle download(std::string url);
|
||||
|
||||
private:
|
||||
std::thread curl_thread;
|
||||
void curl_thread_fn();
|
||||
|
||||
std::atomic<bool> quit{false};
|
||||
CURLM * multi;
|
||||
|
||||
std::mutex lock; // Locks pending_transfers, pending_cancellations and all struct transfers created by this instance
|
||||
std::vector<std::shared_ptr<transfer>> pending_transfers;
|
||||
std::vector<std::shared_ptr<transfer>> pending_cancellations;
|
||||
};
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "animation.h"
|
||||
#include "render/scene_components.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <entt/entt.hpp>
|
||||
#include <glm/ext/quaternion_geometric.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
glm::vec3 interp(const glm::vec3 & a, const glm::vec3 & b, float t)
|
||||
{
|
||||
return a + t * (b - a);
|
||||
}
|
||||
|
||||
glm::quat interp(const glm::quat & a, const glm::quat & b, float t)
|
||||
{
|
||||
float d = glm::dot(a, b);
|
||||
|
||||
if (d > 0.99999)
|
||||
{
|
||||
return a + t * (b - a);
|
||||
}
|
||||
else
|
||||
{
|
||||
float θ = std::acos(std::abs(d));
|
||||
|
||||
float sinθ = std::sin(θ);
|
||||
float sinθt = std::sin(θ * t);
|
||||
float sinθ1_t = std::sin(θ * (1 - t));
|
||||
|
||||
return sinθ1_t / sinθ * a + std::copysign(sinθt / sinθ, d) * b;
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 cubic_spline(const glm::vec3 & a, const glm::vec3 & va, const glm::vec3 & vb, const glm::vec3 & b, float t, float td)
|
||||
{
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
|
||||
return (2 * t3 - 3 * t2 + 1) * a +
|
||||
td * (t3 - 2 * t2 + t) * va +
|
||||
(3 * t2 - 2 * t3) * b +
|
||||
td * (t3 - t2) * vb;
|
||||
}
|
||||
|
||||
glm::quat cubic_spline(const glm::quat & a, const glm::quat & vb, const glm::quat & va, const glm::quat & b, float t, float td)
|
||||
{
|
||||
float t2 = t * t;
|
||||
float t3 = t2 * t;
|
||||
|
||||
return glm::normalize((2 * t3 - 3 * t2 + 1) * a +
|
||||
td * (t3 - 2 * t2 + t) * vb +
|
||||
(3 * t2 - 2 * t3) * b +
|
||||
td * (t3 - t2) * va);
|
||||
}
|
||||
|
||||
template <auto components::node::*Field>
|
||||
void apply_track(entt::registry & scene, const components::animation_track_impl<Field> & track, float current_time)
|
||||
{
|
||||
entt::entity target = track.target;
|
||||
auto interpolation = track.interpolation;
|
||||
auto field = track.field;
|
||||
auto & value = scene.get<components::node>(track.target).*field;
|
||||
|
||||
// Find the first keyframe with a timestamp strictly greater than the current time
|
||||
size_t k = std::ranges::upper_bound(track.timestamp, current_time) - track.timestamp.begin();
|
||||
if (k == 0)
|
||||
{
|
||||
value = track.value[0];
|
||||
return;
|
||||
}
|
||||
|
||||
switch (interpolation)
|
||||
{
|
||||
case components::animation_track_base::interpolation_t::step:
|
||||
value = track.value[k - 1];
|
||||
break;
|
||||
|
||||
case components::animation_track_base::interpolation_t::linear:
|
||||
if (k == track.timestamp.size())
|
||||
value = track.value[k - 1];
|
||||
else
|
||||
{
|
||||
float t = (current_time - track.timestamp[k - 1]) / (track.timestamp[k] - track.timestamp[k - 1]);
|
||||
const auto & a = track.value[k - 1];
|
||||
const auto & b = track.value[k];
|
||||
value = interp(a, b, t);
|
||||
}
|
||||
break;
|
||||
|
||||
case components::animation_track_base::interpolation_t::cubic_spline:
|
||||
if (k == track.timestamp.size())
|
||||
value = track.value[k - 1];
|
||||
else
|
||||
{
|
||||
float t = (current_time - track.timestamp[k - 1]) / (track.timestamp[k] - track.timestamp[k - 1]);
|
||||
const auto & a = track.value[3 * k - 2]; // v_k in gltf spec
|
||||
const auto & vb = track.value[3 * k - 1]; // b_k
|
||||
const auto & va = track.value[3 * k]; // a_k+1
|
||||
const auto & b = track.value[3 * k + 1]; // v_k+1
|
||||
|
||||
value = cubic_spline(a, va, vb, b, t, track.timestamp[k] - track.timestamp[k - 1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void renderer::animate(entt::registry & scene, float dt)
|
||||
{
|
||||
for (auto && [entity, animation]: scene.view<components::animation>().each())
|
||||
{
|
||||
if (not animation.playing)
|
||||
continue;
|
||||
|
||||
animation.current_time += dt;
|
||||
if (animation.current_time > animation.duration)
|
||||
{
|
||||
if (animation.looping)
|
||||
animation.current_time = std::fmod(animation.current_time, animation.duration);
|
||||
else
|
||||
animation.current_time = animation.duration;
|
||||
}
|
||||
else if (animation.current_time < 0)
|
||||
animation.current_time = 0;
|
||||
|
||||
for (const auto & track: animation.tracks)
|
||||
std::visit([&](auto & track) { apply_track(scene, track, animation.current_time); }, track);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <entt/entity/fwd.hpp>
|
||||
|
||||
namespace renderer
|
||||
{
|
||||
void animate(entt::registry & registry, float dt);
|
||||
}
|
||||
@@ -18,18 +18,21 @@
|
||||
*/
|
||||
|
||||
#include "image_loader.h"
|
||||
#include "wivrn_config.h"
|
||||
|
||||
#if WIVRN_USE_LIBKTX
|
||||
#include <ktxvulkan.h>
|
||||
#endif
|
||||
#include "application.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/vk_allocator.h"
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ktx.h>
|
||||
#include <ktxvulkan.h>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <spdlog/fmt/chrono.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <stdexcept>
|
||||
#include <tuple>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
@@ -48,28 +51,150 @@ namespace
|
||||
{
|
||||
struct image_resources
|
||||
{
|
||||
image_allocation allocation;
|
||||
vk::Image image;
|
||||
image_allocation image;
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
};
|
||||
|
||||
#if WIVRN_USE_LIBKTX
|
||||
struct ktx_image_resources
|
||||
class KTXTexture2
|
||||
{
|
||||
ktxVulkanTexture ktx_texture;
|
||||
VkDevice device;
|
||||
vk::Image image;
|
||||
vk::raii::ImageView image_view = nullptr;
|
||||
private:
|
||||
ktxTexture2 * handle_ = nullptr;
|
||||
|
||||
ktx_image_resources() = default;
|
||||
ktx_image_resources(const ktx_image_resources &) = delete;
|
||||
ktx_image_resources & operator=(const ktx_image_resources &) = delete;
|
||||
~ktx_image_resources()
|
||||
public:
|
||||
KTXTexture2() = default;
|
||||
|
||||
explicit KTXTexture2(ktxTexture2 * handle) :
|
||||
handle_{handle} {}
|
||||
|
||||
KTXTexture2(const KTXTexture2 &) = delete;
|
||||
KTXTexture2 & operator=(const KTXTexture2 &) = delete;
|
||||
|
||||
KTXTexture2(KTXTexture2 && other) noexcept :
|
||||
handle_{other.handle_}
|
||||
{
|
||||
ktxVulkanTexture_Destruct(&ktx_texture, device, nullptr);
|
||||
other.handle_ = nullptr;
|
||||
}
|
||||
|
||||
KTXTexture2 & operator=(KTXTexture2 && other) &
|
||||
{
|
||||
std::swap(handle_, other.handle_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
~KTXTexture2()
|
||||
{
|
||||
if (handle_)
|
||||
{
|
||||
ktxTexture_Destroy(ktxTexture(handle_));
|
||||
handle_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ktxTexture2 ** operator&()
|
||||
{
|
||||
return &handle_;
|
||||
}
|
||||
|
||||
operator ktxTexture2 *()
|
||||
{
|
||||
return handle_;
|
||||
}
|
||||
|
||||
ktxTexture2 * operator->() const
|
||||
{
|
||||
return handle_;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
namespace libktx_vma_glue
|
||||
{
|
||||
thread_safe<std::map<uint64_t, VmaAllocation>> allocations;
|
||||
|
||||
uint64_t add(VmaAllocation allocation)
|
||||
{
|
||||
auto allocs = allocations.lock();
|
||||
|
||||
uint64_t allocation_id = allocs->empty() ? 1 : (allocs->rbegin()->first + 1);
|
||||
allocs->emplace(allocation_id, allocation);
|
||||
return allocation_id;
|
||||
}
|
||||
|
||||
VmaAllocation find(uint64_t allocation_id)
|
||||
{
|
||||
auto allocs = allocations.lock();
|
||||
auto iter = allocs->find(allocation_id);
|
||||
assert(iter != allocs->end());
|
||||
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
VmaAllocation release(uint64_t allocation_id)
|
||||
{
|
||||
auto allocs = allocations.lock();
|
||||
auto iter = allocs->find(allocation_id);
|
||||
assert(iter != allocs->end());
|
||||
|
||||
VmaAllocation allocation = iter->second;
|
||||
allocs->erase(iter);
|
||||
return allocation;
|
||||
}
|
||||
|
||||
VmaAllocation remove(uint64_t allocation_id)
|
||||
{
|
||||
auto allocs = allocations.lock();
|
||||
auto iter = allocs->find(allocation_id);
|
||||
assert(iter != allocs->end());
|
||||
|
||||
auto allocation = iter->second;
|
||||
allocs->erase(iter);
|
||||
|
||||
return allocation;
|
||||
}
|
||||
|
||||
ktxVulkanTexture_subAllocatorCallbacks suballocator_callbacks{
|
||||
// Adapted from https://github.com/KhronosGroup/KTX-Software/blob/main/tests/loadtests/vkloadtests/VulkanLoadTestSample.cpp
|
||||
.allocMemFuncPtr = [](VkMemoryAllocateInfo * allocation_info, VkMemoryRequirements * memory_requirements, uint64_t * number_of_pages) -> uint64_t {
|
||||
VmaAllocationCreateInfo info{};
|
||||
|
||||
static const vk::PhysicalDeviceMemoryProperties memory_properties = application::instance().get_physical_device().getMemoryProperties();
|
||||
|
||||
if ((memory_properties.memoryTypes[allocation_info->memoryTypeIndex].propertyFlags & vk::MemoryPropertyFlagBits::eHostVisible) ||
|
||||
(memory_properties.memoryTypes[allocation_info->memoryTypeIndex].propertyFlags & vk::MemoryPropertyFlagBits::eHostCoherent))
|
||||
{
|
||||
info.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
|
||||
info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
}
|
||||
|
||||
VmaAllocation allocation;
|
||||
VkResult result = vmaAllocateMemory(vk_allocator::instance(), memory_requirements, &info, &allocation, nullptr);
|
||||
if (result != VK_SUCCESS)
|
||||
return 0;
|
||||
|
||||
return add(allocation);
|
||||
},
|
||||
.bindBufferFuncPtr = [](VkBuffer buffer, uint64_t allocation_id) -> VkResult {
|
||||
return vmaBindBufferMemory(vk_allocator::instance(), find(allocation_id), buffer);
|
||||
},
|
||||
.bindImageFuncPtr = [](VkImage image, uint64_t allocation_id) -> VkResult {
|
||||
return vmaBindImageMemory(vk_allocator::instance(), find(allocation_id), image);
|
||||
},
|
||||
.memoryMapFuncPtr = [](uint64_t allocation_id, uint64_t, VkDeviceSize * map_length, void ** data) -> VkResult {
|
||||
auto allocation = find(allocation_id);
|
||||
|
||||
VmaAllocationInfo info{};
|
||||
vmaGetAllocationInfo(vk_allocator::instance(), allocation, &info);
|
||||
|
||||
*map_length = info.size;
|
||||
return vmaMapMemory(vk_allocator::instance(), allocation, data);
|
||||
},
|
||||
.memoryUnmapFuncPtr = [](uint64_t allocation_id, uint64_t) { vmaUnmapMemory(vk_allocator::instance(), find(allocation_id)); },
|
||||
.freeMemFuncPtr = [](uint64_t allocation_id) { vmaFreeMemory(vk_allocator::instance(), remove(allocation_id)); },
|
||||
};
|
||||
} // namespace libktx_vma_glue
|
||||
|
||||
template <typename T>
|
||||
constexpr vk::Format formats[4] = {vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined, vk::Format::eUndefined};
|
||||
@@ -162,24 +287,120 @@ int bytes_per_pixel(vk::Format format)
|
||||
}
|
||||
} // namespace
|
||||
|
||||
image_loader::image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, thread_safe<vk::raii::Queue> & queue, vk::raii::CommandPool & cb_pool) :
|
||||
image_loader::image_loader(vk::raii::Device & device, vk::raii::PhysicalDevice physical_device, thread_safe<vk::raii::Queue> & queue, uint32_t queue_family_index) :
|
||||
device(device),
|
||||
queue(queue),
|
||||
cb_pool(cb_pool)
|
||||
cb_pool(device,
|
||||
vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eTransient | vk::CommandPoolCreateFlagBits::eResetCommandBuffer,
|
||||
.queueFamilyIndex = queue_family_index,
|
||||
})
|
||||
{
|
||||
#if WIVRN_USE_LIBKTX
|
||||
ktxVulkanDeviceInfo_Construct(&vdi, *physical_device, *device, *queue.get_unsafe(), *cb_pool, nullptr);
|
||||
#endif
|
||||
// Assume we will always use the same queue
|
||||
static thread_safe<vk::raii::Queue> * q = &queue;
|
||||
|
||||
ktxVulkanFunctions vulkan_functions{
|
||||
.vkGetInstanceProcAddr = &vkGetInstanceProcAddr,
|
||||
.vkGetDeviceProcAddr = &vkGetDeviceProcAddr,
|
||||
.vkQueueSubmit = [](VkQueue queue,
|
||||
uint32_t submitCount,
|
||||
const VkSubmitInfo * pSubmits,
|
||||
VkFence fence) -> VkResult {
|
||||
assert(q and (VkQueue) * q->get_unsafe() == queue);
|
||||
auto _ = q->lock();
|
||||
|
||||
return vkQueueSubmit(queue, submitCount, pSubmits, fence);
|
||||
},
|
||||
.vkQueueWaitIdle = [](VkQueue queue) -> VkResult {
|
||||
// libktx only uses vkQueueWaitIdle when the tiling is not VK_IMAGE_TILING_OPTIMAL
|
||||
abort();
|
||||
},
|
||||
};
|
||||
|
||||
ktxVulkanDeviceInfo_ConstructEx(
|
||||
&vdi,
|
||||
*application::get_vulkan_instance(),
|
||||
*physical_device,
|
||||
*device,
|
||||
*queue.get_unsafe(),
|
||||
*cb_pool,
|
||||
nullptr, // Allocation callbacks
|
||||
&vulkan_functions);
|
||||
|
||||
std::array<std::tuple<vk::Format, ktx_transcode_fmt_e, bool>, 6> formats{{
|
||||
{vk::Format::eAstc4x4SrgbBlock, KTX_TTF_ASTC_4x4_RGBA, true},
|
||||
{vk::Format::eAstc4x4UnormBlock, KTX_TTF_ASTC_4x4_RGBA, false},
|
||||
{vk::Format::eBc7SrgbBlock, KTX_TTF_BC7_RGBA, true},
|
||||
{vk::Format::eBc7UnormBlock, KTX_TTF_BC7_RGBA, false},
|
||||
{vk::Format::eR8G8B8A8Srgb, KTX_TTF_RGBA32, true},
|
||||
{vk::Format::eR8G8B8Unorm, KTX_TTF_RGBA32, false},
|
||||
}};
|
||||
|
||||
for (auto [vk_format, ktx_format, srgb]: formats)
|
||||
{
|
||||
auto prop = physical_device.getFormatProperties(vk_format);
|
||||
|
||||
if (prop.optimalTilingFeatures & vk::FormatFeatureFlagBits::eSampledImage)
|
||||
{
|
||||
if (srgb)
|
||||
supported_srgb_formats.emplace_back(vk_format, ktx_format);
|
||||
else
|
||||
supported_linear_formats.emplace_back(vk_format, ktx_format);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
image_loader::~image_loader()
|
||||
{
|
||||
#if WIVRN_USE_LIBKTX
|
||||
ktxVulkanDeviceInfo_Destruct(&vdi);
|
||||
#endif
|
||||
}
|
||||
|
||||
void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format)
|
||||
template <typename T>
|
||||
float alpha_scale;
|
||||
template <>
|
||||
float alpha_scale<uint8_t> = 1. / 255.;
|
||||
template <>
|
||||
float alpha_scale<uint16_t> = 1. / 65535.;
|
||||
template <>
|
||||
float alpha_scale<float> = 1.;
|
||||
|
||||
template <typename T>
|
||||
void premultiply_alpha_aux(T * destination, const T * source, int n)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
float alpha = source[4 * i + 3] * alpha_scale<T>;
|
||||
|
||||
destination[4 * i + 0] = source[4 * i + 0] * alpha;
|
||||
destination[4 * i + 1] = source[4 * i + 1] * alpha;
|
||||
destination[4 * i + 2] = source[4 * i + 2] * alpha;
|
||||
destination[4 * i + 3] = source[4 * i + 3];
|
||||
}
|
||||
}
|
||||
|
||||
static void premultiply_alpha(void * destination, const void * source, vk::Extent3D extent, vk::Format format)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case vk::Format::eR8G8B8A8Srgb: // TODO: sRGB
|
||||
case vk::Format::eR8G8B8A8Unorm:
|
||||
premultiply_alpha_aux<uint8_t>((uint8_t *)destination, (const uint8_t *)source, extent.width * extent.height * extent.depth);
|
||||
break;
|
||||
|
||||
case vk::Format::eR16G16B16A16Unorm:
|
||||
premultiply_alpha_aux<uint16_t>((uint16_t *)destination, (const uint16_t *)source, extent.width * extent.height * extent.depth);
|
||||
break;
|
||||
|
||||
case vk::Format::eR32G32B32A32Sfloat:
|
||||
premultiply_alpha_aux<float>((float *)destination, (const float *)source, extent.width * extent.height * extent.depth);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
loaded_image image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format, const std::string & name, bool premultiply)
|
||||
{
|
||||
auto cb = std::move(device.allocateCommandBuffers({
|
||||
.commandPool = *cb_pool,
|
||||
@@ -191,14 +412,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
|
||||
assert(format != vk::Format::eUndefined);
|
||||
|
||||
this->format = format;
|
||||
this->extent = extent;
|
||||
if (extent.depth > 1)
|
||||
image_view_type = vk::ImageViewType::e3D;
|
||||
else
|
||||
image_view_type = vk::ImageViewType::e2D;
|
||||
|
||||
num_mipmaps = std::floor(std::log2(std::max(extent.width, extent.height))) + 1;
|
||||
uint32_t num_mipmaps = std::floor(std::log2(std::max(extent.width, extent.height))) + 1;
|
||||
|
||||
size_t byte_size = extent.width * extent.height * extent.depth * bytes_per_pixel(format);
|
||||
|
||||
@@ -212,14 +426,17 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO,
|
||||
},
|
||||
"image_loader::do_load (staging)"};
|
||||
name + " (staging)"};
|
||||
|
||||
if (premultiply)
|
||||
premultiply_alpha(staging_buffer.map(), pixels, extent, format);
|
||||
else
|
||||
memcpy(staging_buffer.map(), pixels, byte_size);
|
||||
|
||||
memcpy(staging_buffer.map(), pixels, byte_size);
|
||||
staging_buffer.unmap();
|
||||
|
||||
// Allocate image
|
||||
auto r = std::make_shared<image_resources>();
|
||||
r->allocation = image_allocation{
|
||||
image_allocation image{
|
||||
device,
|
||||
vk::ImageCreateInfo{
|
||||
.imageType = vk::ImageType::e2D,
|
||||
@@ -235,9 +452,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.flags = 0,
|
||||
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||
},
|
||||
"image_loader::do_load"};
|
||||
|
||||
r->image = (vk::Image)r->allocation;
|
||||
name};
|
||||
|
||||
// Transition all mipmap levels layout to eTransferDstOptimal
|
||||
cb.pipelineBarrier(
|
||||
@@ -251,7 +466,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.dstAccessMask = vk::AccessFlagBits::eTransferWrite,
|
||||
.oldLayout = vk::ImageLayout::eUndefined,
|
||||
.newLayout = vk::ImageLayout::eTransferDstOptimal,
|
||||
.image = r->image,
|
||||
.image = image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
@@ -264,7 +479,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
// Copy image data
|
||||
cb.copyBufferToImage(
|
||||
staging_buffer,
|
||||
r->image,
|
||||
image,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::BufferImageCopy{
|
||||
.bufferOffset = 0,
|
||||
@@ -300,7 +515,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
|
||||
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
|
||||
.newLayout = vk::ImageLayout::eTransferSrcOptimal,
|
||||
.image = r->image,
|
||||
.image = image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = level - 1,
|
||||
@@ -312,9 +527,9 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
|
||||
// Blit level n-1 to level n
|
||||
cb.blitImage(
|
||||
r->image,
|
||||
image,
|
||||
vk::ImageLayout::eTransferSrcOptimal,
|
||||
r->image,
|
||||
image,
|
||||
vk::ImageLayout::eTransferDstOptimal,
|
||||
vk::ImageBlit{
|
||||
.srcSubresource = {.aspectMask = vk::ImageAspectFlagBits::eColor, .mipLevel = level - 1, .baseArrayLayer = 0, .layerCount = 1},
|
||||
@@ -342,7 +557,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
|
||||
.oldLayout = vk::ImageLayout::eTransferSrcOptimal,
|
||||
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
.image = r->image,
|
||||
.image = image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = level - 1,
|
||||
@@ -368,7 +583,7 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
.dstAccessMask = vk::AccessFlagBits::eShaderRead,
|
||||
.oldLayout = vk::ImageLayout::eTransferDstOptimal,
|
||||
.newLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
.image = r->image,
|
||||
.image = image,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = num_mipmaps - 1,
|
||||
@@ -386,10 +601,16 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
if (auto result = device.waitForFences(*fence, true, 1'000'000'000); result != vk::Result::eSuccess)
|
||||
throw std::runtime_error("vkWaitForfences: " + vk::to_string(result));
|
||||
|
||||
r->image_view = vk::raii::ImageView{
|
||||
vk::ImageViewType image_view_type;
|
||||
if (extent.depth > 1)
|
||||
image_view_type = vk::ImageViewType::e3D;
|
||||
else
|
||||
image_view_type = vk::ImageViewType::e2D;
|
||||
|
||||
vk::raii::ImageView image_view{
|
||||
device,
|
||||
vk::ImageViewCreateInfo{
|
||||
.image = r->image,
|
||||
.image = image,
|
||||
.viewType = image_view_type,
|
||||
.format = format,
|
||||
.subresourceRange = {
|
||||
@@ -402,76 +623,89 @@ void image_loader::do_load_raw(const void * pixels, vk::Extent3D extent, vk::For
|
||||
},
|
||||
};
|
||||
|
||||
image_view = std::shared_ptr<vk::raii::ImageView>(r, &r->image_view);
|
||||
return loaded_image{
|
||||
.image = std::move(image),
|
||||
.image_view = std::move(image_view),
|
||||
.format = format,
|
||||
.extent = extent,
|
||||
.num_mipmaps = num_mipmaps,
|
||||
.image_view_type = image_view_type,
|
||||
.is_alpha_premultiplied = premultiply,
|
||||
};
|
||||
}
|
||||
|
||||
void image_loader::do_load_ktx(std::span<const std::byte> bytes)
|
||||
loaded_image image_loader::do_load_ktx(std::span<const std::byte> bytes, bool srgb, const std::string & name, const std::filesystem::path & output_file)
|
||||
{
|
||||
#if WIVRN_USE_LIBKTX
|
||||
ktxTexture * texture;
|
||||
KTXTexture2 texture{};
|
||||
// KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT checks that the file is compatible with the KHR_texture_basisu glTF extension
|
||||
// ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture);
|
||||
ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), 0, &texture);
|
||||
// ktxResult err = ktxTexture2_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT | KTX_TEXTURE_CREATE_LOAD_IMAGE_DATA_BIT, &texture);
|
||||
|
||||
if (err != KTX_SUCCESS)
|
||||
{
|
||||
spdlog::warn("ktxTexture2_CreateFromMemory: error {}", ktxErrorString(err));
|
||||
throw std::runtime_error("ktxTexture2_CreateFromMemory");
|
||||
}
|
||||
|
||||
if (ktxTexture2_NeedsTranscoding(texture))
|
||||
{
|
||||
auto format = srgb ? supported_srgb_formats.front() : supported_linear_formats.front();
|
||||
|
||||
if (ktxTexture2_TranscodeBasis(texture, format.second, 0) != KTX_SUCCESS)
|
||||
{
|
||||
spdlog::warn("ktxTexture2_TranscodeBasis: error {}", ktxErrorString(err));
|
||||
throw std::runtime_error("ktxTexture2_TranscodeBasis");
|
||||
}
|
||||
|
||||
if (output_file != "")
|
||||
{
|
||||
spdlog::debug("Saving transcoded texture to {}", output_file.native());
|
||||
const char writer[] = "WiVRn";
|
||||
ktxHashList_DeleteKVPair(&texture->kvDataHead, KTX_WRITER_KEY);
|
||||
ktxHashList_AddKVPair(&texture->kvDataHead, KTX_WRITER_KEY, sizeof(writer), writer);
|
||||
|
||||
err = ktxTexture2_WriteToNamedFile(texture, output_file.c_str());
|
||||
if (err != KTX_SUCCESS)
|
||||
{
|
||||
spdlog::warn("ktxTexture2_WriteToNamedFile: error {}", ktxErrorString(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ktxVulkanTexture vk_texture;
|
||||
|
||||
ktxResult err = ktxTexture_CreateFromMemory(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size(), /*KTX_TEXTURE_CREATE_CHECK_GLTF_BASISU_BIT*/ 0, &texture);
|
||||
|
||||
if (err != KTX_SUCCESS)
|
||||
{
|
||||
spdlog::warn("ktxTexture_CreateFromMemory: error {}", (int)err);
|
||||
throw std::runtime_error("ktxTexture_CreateFromMemory");
|
||||
}
|
||||
|
||||
if (ktxTexture_NeedsTranscoding(texture))
|
||||
{
|
||||
// TODO
|
||||
spdlog::warn("ktxTexture_NeedsTranscoding");
|
||||
throw std::runtime_error("ktxTexture_NeedsTranscoding");
|
||||
}
|
||||
|
||||
{
|
||||
auto _ = queue.lock(); // ktxTexture_VkUploadEx uses the queue internally (in ktxTexture_VkUploadEx_WithSuballocator)
|
||||
// TODO: patch vkloader.c to accept a mutex
|
||||
err = ktxTexture_VkUploadEx(texture, &vdi, &vk_texture, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
err = ktxTexture2_VkUploadEx_WithSuballocator(texture, &vdi, &vk_texture, VK_IMAGE_TILING_OPTIMAL, VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, &libktx_vma_glue::suballocator_callbacks);
|
||||
}
|
||||
|
||||
if (err != KTX_SUCCESS)
|
||||
{
|
||||
// TODO try uncompressing the texture
|
||||
ktxTexture_Destroy(texture);
|
||||
spdlog::warn("ktxTexture_CreateFromMemory: error {}", (int)err);
|
||||
throw std::runtime_error("ktxTexture_VkUploadEx");
|
||||
spdlog::warn("ktxTexture2_VkUploadEx: {}", ktxErrorString(err));
|
||||
throw std::runtime_error("ktxTexture2_VkUploadEx");
|
||||
}
|
||||
|
||||
format = vk::Format(vk_texture.imageFormat);
|
||||
extent = vk::Extent3D(texture->baseWidth, texture->baseHeight, texture->baseDepth);
|
||||
image_view_type = vk::ImageViewType(vk_texture.viewType);
|
||||
num_mipmaps = texture->numLevels;
|
||||
|
||||
ktxTexture_Destroy(texture);
|
||||
|
||||
auto r = std::make_shared<ktx_image_resources>();
|
||||
|
||||
r->ktx_texture = vk_texture;
|
||||
r->device = *device;
|
||||
r->image = vk::Image(vk_texture.image);
|
||||
r->image_view = vk::raii::ImageView{
|
||||
device,
|
||||
vk::ImageViewCreateInfo{
|
||||
.image = r->image,
|
||||
.viewType = image_view_type,
|
||||
.format = format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = num_mipmaps,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
},
|
||||
return loaded_image{
|
||||
.image{libktx_vma_glue::release(vk_texture.allocationId), device, vk_texture.image, name}, // Take over ownership of vk_texture, do not call ktxTexture2_destruct
|
||||
.image_view{
|
||||
device,
|
||||
vk::ImageViewCreateInfo{
|
||||
.image = vk_texture.image,
|
||||
.viewType = vk::ImageViewType(vk_texture.viewType),
|
||||
.format = vk::Format(vk_texture.imageFormat),
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = texture->numLevels,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
}},
|
||||
.format = vk::Format(vk_texture.imageFormat),
|
||||
.extent{vk::Extent3D(texture->baseWidth, texture->baseHeight, texture->baseDepth)},
|
||||
.num_mipmaps = texture->numLevels,
|
||||
.image_view_type = vk::ImageViewType(vk_texture.viewType),
|
||||
.is_alpha_premultiplied = ktxTexture2_GetPremultipliedAlpha(texture),
|
||||
};
|
||||
|
||||
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)
|
||||
@@ -479,102 +713,65 @@ static constexpr bool starts_with(std::span<const std::byte> data, std::span<con
|
||||
return data.size() >= prefix.size() && !memcmp(data.data(), prefix.data(), prefix.size());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void premultiply_alpha_aux(T * pixels, float alpha_scale, int width, int height)
|
||||
loaded_image image_loader::do_load_image(std::span<const std::byte> bytes, bool srgb, const std::string & name, bool premultiply)
|
||||
{
|
||||
for (int i = 0, n = width * height; i < n; i++)
|
||||
const stbi_uc * image_data = (const stbi_uc *)bytes.data();
|
||||
size_t image_size = bytes.size();
|
||||
|
||||
int w, h, num_channels, channels_in_file;
|
||||
stbi_ptr pixels;
|
||||
|
||||
if (!stbi_info_from_memory(image_data, image_size, &w, &h, &num_channels))
|
||||
throw std::runtime_error("Unsupported image format");
|
||||
|
||||
assert(num_channels >= 1 && num_channels <= 4);
|
||||
|
||||
if (num_channels == 3)
|
||||
num_channels = 4;
|
||||
|
||||
vk::Format format;
|
||||
if (stbi_is_hdr_from_memory(image_data, image_size))
|
||||
{
|
||||
float alpha = pixels[4 * i + 3] * alpha_scale;
|
||||
|
||||
pixels[4 * i + 0] = pixels[4 * i + 0] * alpha;
|
||||
pixels[4 * i + 1] = pixels[4 * i + 1] * alpha;
|
||||
pixels[4 * i + 2] = pixels[4 * i + 2] * alpha;
|
||||
pixels = stbi_ptr(stbi_loadf_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = get_format<float>(num_channels);
|
||||
}
|
||||
}
|
||||
|
||||
static void premultiply_alpha(void * pixels, vk::Extent3D extent, vk::Format format)
|
||||
{
|
||||
switch (format)
|
||||
else if (stbi_is_16_bit_from_memory(image_data, image_size))
|
||||
{
|
||||
case vk::Format::eR8G8B8A8Srgb: // TODO: sRGB
|
||||
case vk::Format::eR8G8B8A8Unorm:
|
||||
premultiply_alpha_aux<uint8_t>((uint8_t *)pixels, 1. / 255., extent.width, extent.height);
|
||||
break;
|
||||
|
||||
case vk::Format::eR16G16B16A16Unorm:
|
||||
premultiply_alpha_aux<uint16_t>((uint16_t *)pixels, 1. / 65535., extent.width, extent.height);
|
||||
break;
|
||||
|
||||
case vk::Format::eR32G32B32A32Sfloat:
|
||||
premultiply_alpha_aux<float>((float *)pixels, 1, extent.width, extent.height);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
pixels = stbi_ptr(stbi_load_16_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = get_format<uint16_t>(num_channels);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels = stbi_ptr(stbi_load_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = srgb ? get_format_srgb(num_channels) : get_format<uint8_t>(num_channels);
|
||||
}
|
||||
|
||||
vk::Extent3D extent{
|
||||
.width = uint32_t(w),
|
||||
.height = uint32_t(h),
|
||||
.depth = 1,
|
||||
};
|
||||
|
||||
return do_load_raw(pixels.get(), extent, format, name, premultiply);
|
||||
}
|
||||
|
||||
// Load a PNG/JPEG/KTX2 file
|
||||
void image_loader::load(std::span<const std::byte> bytes, bool srgb)
|
||||
loaded_image image_loader::load(std::span<const std::byte> bytes, bool srgb, const std::string & name, bool premultiply, const std::filesystem::path & output_file)
|
||||
{
|
||||
const uint8_t ktx1_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
const uint8_t ktx2_magic[] = {0xAB, 0x4B, 0x54, 0x58, 0x20, 0x32, 0x30, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
|
||||
if (starts_with(bytes, ktx1_magic) || starts_with(bytes, ktx2_magic))
|
||||
{
|
||||
do_load_ktx(bytes);
|
||||
}
|
||||
return do_load_ktx(bytes, srgb, name, output_file);
|
||||
else
|
||||
{
|
||||
const stbi_uc * image_data = (const stbi_uc *)bytes.data();
|
||||
size_t image_size = bytes.size();
|
||||
|
||||
int w, h, num_channels, channels_in_file;
|
||||
stbi_ptr pixels;
|
||||
|
||||
if (!stbi_info_from_memory(image_data, image_size, &w, &h, &num_channels))
|
||||
throw std::runtime_error("Unsupported image format");
|
||||
|
||||
assert(num_channels >= 1 && num_channels <= 4);
|
||||
|
||||
if (num_channels == 3)
|
||||
num_channels = 4;
|
||||
|
||||
if (stbi_is_hdr_from_memory(image_data, image_size))
|
||||
{
|
||||
pixels = stbi_ptr(stbi_loadf_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = get_format<float>(num_channels);
|
||||
}
|
||||
else if (stbi_is_16_bit_from_memory(image_data, image_size))
|
||||
{
|
||||
pixels = stbi_ptr(stbi_load_16_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = get_format<uint16_t>(num_channels);
|
||||
}
|
||||
else
|
||||
{
|
||||
pixels = stbi_ptr(stbi_load_from_memory(image_data, image_size, &w, &h, &channels_in_file, num_channels));
|
||||
format = srgb ? get_format_srgb(num_channels) : get_format<uint8_t>(num_channels);
|
||||
}
|
||||
|
||||
extent.width = w;
|
||||
extent.height = h;
|
||||
extent.depth = 1;
|
||||
|
||||
premultiply_alpha(pixels.get(), extent, format);
|
||||
|
||||
do_load_raw(pixels.get(), extent, format);
|
||||
}
|
||||
return do_load_image(bytes, srgb, name, premultiply);
|
||||
}
|
||||
|
||||
// Load raw pixel data
|
||||
void image_loader::load(const void * pixels, size_t size, vk::Extent3D extent_, vk::Format format_)
|
||||
loaded_image image_loader::load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format, const std::string & name, bool premultiply)
|
||||
{
|
||||
extent = extent_;
|
||||
format = format_;
|
||||
image_view_type = vk::ImageViewType::e2D;
|
||||
|
||||
if (size < extent.width * extent.height * extent.depth * bytes_per_pixel(format))
|
||||
throw std::invalid_argument("size");
|
||||
|
||||
do_load_raw(pixels, extent_, format_);
|
||||
return do_load_raw(pixels, extent, format, name, premultiply);
|
||||
}
|
||||
|
||||
@@ -22,73 +22,78 @@
|
||||
#include "utils/thread_safe.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/fwd.h"
|
||||
#include "wivrn_config.h"
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <memory>
|
||||
#include <ktxvulkan.h>
|
||||
#include <span>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
#if WIVRN_USE_LIBKTX
|
||||
#include <ktxvulkan.h>
|
||||
#endif
|
||||
struct loaded_image
|
||||
{
|
||||
image_allocation image;
|
||||
vk::raii::ImageView image_view;
|
||||
|
||||
vk::Format format;
|
||||
vk::Extent3D extent;
|
||||
uint32_t num_mipmaps;
|
||||
vk::ImageViewType image_view_type;
|
||||
bool is_alpha_premultiplied;
|
||||
};
|
||||
|
||||
struct image_loader
|
||||
{
|
||||
vk::Image image;
|
||||
vk::Format format;
|
||||
vk::Extent3D extent;
|
||||
vk::ImageViewType image_view_type;
|
||||
|
||||
std::shared_ptr<vk::raii::ImageView> image_view;
|
||||
|
||||
uint32_t num_mipmaps;
|
||||
|
||||
image_loader(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, thread_safe<vk::raii::Queue> & queue, vk::raii::CommandPool & cb_pool);
|
||||
image_loader(vk::raii::Device & device, vk::raii::PhysicalDevice physical_device, thread_safe<vk::raii::Queue> & queue, uint32_t queue_family_index);
|
||||
image_loader(const image_loader &) = delete;
|
||||
image_loader & operator=(const image_loader &) = delete;
|
||||
~image_loader();
|
||||
|
||||
// Load a PNG/JPEG/KTX2 file
|
||||
void load(std::span<const std::byte> bytes, bool srgb);
|
||||
loaded_image load(std::span<const std::byte> bytes, bool srgb, const std::string & name = "", bool premultiply = false, const std::filesystem::path & output_file = "");
|
||||
|
||||
// Load raw pixel data
|
||||
void load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format);
|
||||
loaded_image load(const void * pixels, size_t size, vk::Extent3D extent, vk::Format format, const std::string & name = "", bool premultiply = false);
|
||||
|
||||
template <typename T>
|
||||
void load(std::span<T> pixels, vk::Extent3D extent, vk::Format format)
|
||||
loaded_image load(std::span<T> pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "", bool premultiply = false)
|
||||
{
|
||||
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
|
||||
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
|
||||
}
|
||||
|
||||
template <typename T, size_t N>
|
||||
void load(const std::array<T, N> & pixels, vk::Extent3D extent, vk::Format format)
|
||||
loaded_image load(const std::array<T, N> & pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "", bool premultiply = false)
|
||||
{
|
||||
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
|
||||
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void load(const std::vector<T> & pixels, vk::Extent3D extent, vk::Format format)
|
||||
loaded_image load(const std::vector<T> & pixels, vk::Extent3D extent, vk::Format format, const std::string & name = "", bool premultiply = false)
|
||||
{
|
||||
load(pixels.data(), pixels.size() * sizeof(T), extent, format);
|
||||
return load(pixels.data(), pixels.size() * sizeof(T), extent, format, name);
|
||||
}
|
||||
|
||||
std::shared_ptr<loaded_image> operator()(std::span<const std::byte> bytes, bool srgb, const std::string & name = "", bool premultiply = false)
|
||||
{
|
||||
return std::make_shared<loaded_image>(load(bytes, srgb, name, premultiply));
|
||||
}
|
||||
|
||||
private:
|
||||
#if WIVRN_USE_LIBKTX
|
||||
ktxVulkanDeviceInfo vdi;
|
||||
#endif
|
||||
|
||||
vk::raii::Device & device;
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
vk::raii::CommandPool & cb_pool;
|
||||
vk::raii::CommandPool cb_pool;
|
||||
|
||||
std::vector<std::pair<vk::Format, ktx_transcode_fmt_e>> supported_srgb_formats;
|
||||
std::vector<std::pair<vk::Format, ktx_transcode_fmt_e>> supported_linear_formats;
|
||||
|
||||
buffer_allocation staging_buffer;
|
||||
|
||||
void do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format);
|
||||
loaded_image do_load_raw(const void * pixels, vk::Extent3D extent, vk::Format format, const std::string & name, bool premultiply);
|
||||
|
||||
void do_load_ktx(std::span<const std::byte> bytes);
|
||||
|
||||
void create_image_view();
|
||||
loaded_image do_load_image(std::span<const std::byte> bytes, bool srgb, const std::string & name, bool premultiply);
|
||||
loaded_image do_load_ktx(std::span<const std::byte> bytes, bool srgb, const std::string & name, const std::filesystem::path & output_file = "");
|
||||
};
|
||||
|
||||
@@ -16,15 +16,17 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "imgui_impl.h"
|
||||
#include "implot.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
#include "constants.h"
|
||||
#include "image_loader.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "utils/strings.h"
|
||||
#include "vulkan/vulkan_enums.hpp"
|
||||
#include "vulkan/vulkan_handles.hpp"
|
||||
#include "vulkan/vulkan_to_string.hpp"
|
||||
@@ -43,8 +45,6 @@
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <string_view>
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/font.h>
|
||||
#include <android/font_matcher.h>
|
||||
@@ -178,6 +178,36 @@ static float distance_to_window(ImGuiWindow * window, ImVec2 position)
|
||||
return std::hypot(dx, dy);
|
||||
}
|
||||
|
||||
static const std::array layout_bindings = {
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
}};
|
||||
|
||||
imgui_textures::imgui_textures(
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
vk::raii::Device & device,
|
||||
uint32_t queue_family_index,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
std::shared_ptr<image_cache_type> image_cache) :
|
||||
physical_device(physical_device),
|
||||
device(device),
|
||||
queue(queue),
|
||||
ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}),
|
||||
command_pool(device,
|
||||
vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
||||
.queueFamilyIndex = queue_family_index,
|
||||
}),
|
||||
image_cache(image_cache),
|
||||
descriptor_pool(device, ds_layout, layout_bindings)
|
||||
{
|
||||
if (not image_cache)
|
||||
this->image_cache = std::make_shared<image_cache_type>(device, physical_device, queue, queue_family_index);
|
||||
}
|
||||
|
||||
std::vector<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in) const
|
||||
{
|
||||
if (!in.active)
|
||||
@@ -289,39 +319,28 @@ imgui_context::imgui_frame & imgui_context::get_frame(vk::Image destination)
|
||||
return frame;
|
||||
}
|
||||
|
||||
static const std::array layout_bindings = {
|
||||
vk::DescriptorSetLayoutBinding{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment,
|
||||
}};
|
||||
|
||||
imgui_context::imgui_context(
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
vk::raii::Device & device,
|
||||
uint32_t queue_family_index,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
std::span<controller> controllers_,
|
||||
xr::swapchain & swapchain,
|
||||
std::vector<viewport> layers) :
|
||||
physical_device(physical_device),
|
||||
device(device),
|
||||
xr::swapchain && swapchain_,
|
||||
std::vector<viewport> layers,
|
||||
std::shared_ptr<image_cache_type> image_cache) :
|
||||
imgui_textures(
|
||||
physical_device,
|
||||
device,
|
||||
queue_family_index,
|
||||
queue,
|
||||
image_cache),
|
||||
queue_family_index(queue_family_index),
|
||||
queue(queue),
|
||||
ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = layout_bindings.size(), .pBindings = layout_bindings.data()}),
|
||||
descriptor_pool(device, ds_layout, layout_bindings),
|
||||
renderpass(create_renderpass(device, swapchain.format(), true)),
|
||||
command_pool(device,
|
||||
vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
||||
.queueFamilyIndex = queue_family_index,
|
||||
}),
|
||||
command_buffers(swapchain.images().size()),
|
||||
size(swapchain.extent().width, swapchain.extent().height),
|
||||
format(swapchain.format()),
|
||||
renderpass(create_renderpass(device, swapchain_.format(), true)),
|
||||
command_buffers(swapchain_.images().size()),
|
||||
size(swapchain_.extent().width, swapchain_.extent().height),
|
||||
format(swapchain_.format()),
|
||||
layers_(std::move(layers)),
|
||||
swapchain(swapchain),
|
||||
swapchain(std::move(swapchain_)),
|
||||
context(ImGui::CreateContext()),
|
||||
plot_context(ImPlot::CreateContext()),
|
||||
io((ImGui::SetCurrentContext(context), ImGui::GetIO())),
|
||||
@@ -349,13 +368,13 @@ imgui_context::imgui_context(
|
||||
.Device = *device,
|
||||
.QueueFamily = queue_family_index,
|
||||
.Queue = *queue.get_unsafe(),
|
||||
.RenderPass = *renderpass,
|
||||
.DescriptorPoolSize = 100,
|
||||
.MinImageCount = 2,
|
||||
.ImageCount = (uint32_t)swapchain.images().size(), // used to cycle between VkBuffers in ImGui_ImplVulkan_RenderDrawData
|
||||
.MSAASamples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.PipelineCache = *application::get_pipeline_cache(),
|
||||
.RenderPass = *renderpass,
|
||||
.Subpass = 0,
|
||||
.DescriptorPoolSize = 100,
|
||||
.MSAASamples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.Allocator = nullptr,
|
||||
.CheckVkResultFn = check_vk_result,
|
||||
};
|
||||
@@ -508,8 +527,8 @@ void imgui_context::initialize_fonts()
|
||||
}
|
||||
}
|
||||
|
||||
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
|
||||
asset font_awesome_solid("Font Awesome 6 Free-Solid-900.otf");
|
||||
utils::mapped_file font_awesome_regular("assets://Font Awesome 6 Free-Regular-400.otf");
|
||||
utils::mapped_file font_awesome_solid("assets://Font Awesome 6 Free-Solid-900.otf");
|
||||
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
@@ -1020,22 +1039,26 @@ imgui_context::~imgui_context()
|
||||
ImGui::DestroyContext(context);
|
||||
}
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
|
||||
ImTextureID imgui_textures::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
|
||||
{
|
||||
return load_texture(std::span<const std::byte>{asset{filename}}, std::move(sampler));
|
||||
return load_texture(utils::mapped_file{filename}, std::move(sampler), filename);
|
||||
}
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler)
|
||||
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler, const std::string & name)
|
||||
{
|
||||
bool srgb = true;
|
||||
image_loader loader(physical_device, device, queue, command_pool);
|
||||
loader.load(bytes, srgb);
|
||||
|
||||
std::shared_ptr<loaded_image> image;
|
||||
if (name == "")
|
||||
image = image_cache->load_uncached(bytes, srgb, "", true /* premultiply alpha */);
|
||||
else
|
||||
image = image_cache->load(name, bytes, srgb, name, true /* premultiply alpha */);
|
||||
|
||||
std::shared_ptr<vk::raii::DescriptorSet> ds = descriptor_pool.allocate();
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = **loader.image_view,
|
||||
.imageView = *image->image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
@@ -1053,15 +1076,14 @@ ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes
|
||||
id,
|
||||
texture_data{
|
||||
.sampler = std::move(sampler),
|
||||
// .image = std::move(loader.image),
|
||||
.image_view = std::move(loader.image_view),
|
||||
.image = image,
|
||||
.descriptor_set = std::move(ds),
|
||||
});
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes)
|
||||
ImTextureID imgui_textures::load_texture(const std::span<const std::byte> & bytes, const std::string & name)
|
||||
{
|
||||
return load_texture(
|
||||
bytes,
|
||||
@@ -1076,10 +1098,11 @@ ImTextureID imgui_context::load_texture(const std::span<const std::byte> & bytes
|
||||
.addressModeW = vk::SamplerAddressMode::eClampToEdge,
|
||||
.borderColor = vk::BorderColor::eFloatTransparentBlack,
|
||||
},
|
||||
});
|
||||
},
|
||||
name);
|
||||
}
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::string & filename)
|
||||
ImTextureID imgui_textures::load_texture(const std::string & filename)
|
||||
{
|
||||
return load_texture(
|
||||
filename,
|
||||
@@ -1097,15 +1120,8 @@ ImTextureID imgui_context::load_texture(const std::string & filename)
|
||||
});
|
||||
}
|
||||
|
||||
void imgui_context::free_texture(ImTextureID texture)
|
||||
void imgui_textures::free_texture(ImTextureID texture)
|
||||
{
|
||||
// Make sure we are done using the texture
|
||||
std::vector<vk::Fence> fences;
|
||||
for (auto & f: command_buffers)
|
||||
fences.push_back(*f.fence);
|
||||
if (auto result = device.waitForFences(fences, true, 1'000'000'000); result != vk::Result::eSuccess)
|
||||
spdlog::error("vkWaitForfences: {}", vk::to_string(result));
|
||||
|
||||
textures.erase(texture);
|
||||
}
|
||||
|
||||
@@ -1182,3 +1198,145 @@ void imgui_context::tooltip(std::string_view text)
|
||||
viewport->Pos = pos_backup;
|
||||
viewport->Size = size_backup;
|
||||
}
|
||||
|
||||
// https://github.com/ocornut/imgui/issues/3379#issuecomment-2943903877
|
||||
void ScrollWhenDragging()
|
||||
{
|
||||
ImVec2 delta{0.0f, -ImGui::GetIO().MouseDelta.y};
|
||||
const ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
|
||||
|
||||
ImGuiContext & g = *ImGui::GetCurrentContext();
|
||||
ImGuiWindow * window = g.CurrentWindow;
|
||||
ImGuiID id = window->GetID("##scrolldraggingoverlay");
|
||||
ImGui::KeepAliveID(id);
|
||||
|
||||
static int active_id;
|
||||
static ImVec2 cumulated_delta;
|
||||
|
||||
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
||||
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
||||
if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any))
|
||||
{
|
||||
active_id = id;
|
||||
|
||||
// Don't scroll on the first step, in case the active controller just changed
|
||||
delta = {};
|
||||
cumulated_delta = {};
|
||||
}
|
||||
|
||||
if (not g.IO.MouseDown[mouse_button])
|
||||
active_id = 0;
|
||||
|
||||
if (active_id == id)
|
||||
{
|
||||
if (delta.x != 0.0f)
|
||||
ImGui::SetScrollX(window, window->Scroll.x + delta.x);
|
||||
if (delta.y != 0.0f)
|
||||
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
|
||||
|
||||
cumulated_delta += delta;
|
||||
if (std::max(std::abs(cumulated_delta.x), std::abs(cumulated_delta.y)) > 50)
|
||||
ImGui::ClearActiveID();
|
||||
}
|
||||
|
||||
g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup;
|
||||
g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup;
|
||||
}
|
||||
|
||||
void CenterTextH(const std::string & text)
|
||||
{
|
||||
float win_width = ImGui::GetWindowSize().x;
|
||||
|
||||
std::vector<std::string> lines = utils::split(text);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
|
||||
for (const auto & i: lines)
|
||||
{
|
||||
float text_width = ImGui::CalcTextSize(i.c_str()).x;
|
||||
ImGui::SetCursorPosX((win_width - text_width) / 2);
|
||||
ImGui::Text("%s", i.c_str());
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Dummy({}); // Make sure the original vertical ItemSpacing is respected
|
||||
}
|
||||
|
||||
void CenterTextHV(const std::string & text)
|
||||
{
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
|
||||
std::vector<std::string> lines = utils::split(text);
|
||||
|
||||
float text_height = 0;
|
||||
for (const auto & i: lines)
|
||||
text_height += ImGui::CalcTextSize(i.c_str()).y;
|
||||
|
||||
ImGui::SetCursorPosY((size.y - text_height) / 2);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
|
||||
for (const auto & i: lines)
|
||||
{
|
||||
float text_width = ImGui::CalcTextSize(i.c_str()).x;
|
||||
ImGui::SetCursorPosX((size.x - text_width) / 2);
|
||||
ImGui::Text("%s", i.c_str());
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
void InputText(const char * label, std::string & text, const ImVec2 & size, ImGuiInputTextFlags flags)
|
||||
{
|
||||
auto callback = [](ImGuiInputTextCallbackData * data) -> int {
|
||||
std::string & text = *reinterpret_cast<std::string *>(data->UserData);
|
||||
|
||||
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
|
||||
{
|
||||
assert(text.data() == data->Buf);
|
||||
text.resize(data->BufTextLen);
|
||||
data->Buf = text.data();
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size() + 1, size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
}
|
||||
|
||||
bool RadioButtonWithoutCheckBox(const std::string & label, bool active, ImVec2 size_arg)
|
||||
{
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext & g = *GImGui;
|
||||
const ImGuiStyle & style = g.Style;
|
||||
const ImGuiID id = window->GetID(label.c_str());
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(label.c_str(), NULL, true);
|
||||
|
||||
const ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ImGui::ItemSize(bb, style.FramePadding.y);
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
ImGuiCol_ col;
|
||||
if ((held && hovered) || active)
|
||||
col = ImGuiCol_ButtonActive;
|
||||
else if (hovered)
|
||||
col = ImGuiCol_ButtonHovered;
|
||||
else
|
||||
col = ImGuiCol_Button;
|
||||
|
||||
ImGui::RenderNavHighlight(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
|
||||
|
||||
ImVec2 TextAlign{0, 0.5f};
|
||||
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label.c_str(), NULL, &label_size, TextAlign, &bb);
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label.c_str(), g.LastItemData.StatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "image_loader.h"
|
||||
#include "render/growable_descriptor_pool.h"
|
||||
#include "utils/cache.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "xr/hand_tracker.h"
|
||||
@@ -36,7 +38,44 @@
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
class imgui_context
|
||||
class imgui_textures
|
||||
{
|
||||
struct texture_data
|
||||
{
|
||||
vk::raii::Sampler sampler;
|
||||
std::shared_ptr<loaded_image> image;
|
||||
std::shared_ptr<vk::raii::DescriptorSet> descriptor_set;
|
||||
};
|
||||
|
||||
protected:
|
||||
vk::raii::PhysicalDevice physical_device;
|
||||
vk::raii::Device & device;
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
vk::raii::DescriptorSetLayout ds_layout;
|
||||
vk::raii::CommandPool command_pool;
|
||||
|
||||
using image_cache_type = utils::cache<std::string, loaded_image, image_loader>;
|
||||
std::shared_ptr<image_cache_type> image_cache;
|
||||
|
||||
private:
|
||||
growable_descriptor_pool descriptor_pool;
|
||||
std::unordered_map<ImTextureID, texture_data> textures;
|
||||
|
||||
public:
|
||||
imgui_textures(
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
vk::raii::Device & device,
|
||||
uint32_t queue_family_index,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
std::shared_ptr<image_cache_type> image_cache = {});
|
||||
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
|
||||
ImTextureID load_texture(const std::string & filename);
|
||||
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler, const std::string & name = "");
|
||||
ImTextureID load_texture(const std::span<const std::byte> & bytes, const std::string & name = "");
|
||||
void free_texture(ImTextureID);
|
||||
};
|
||||
|
||||
class imgui_context : public imgui_textures
|
||||
{
|
||||
struct command_buffer
|
||||
{
|
||||
@@ -44,13 +83,6 @@ class imgui_context
|
||||
vk::raii::Fence fence = nullptr;
|
||||
};
|
||||
|
||||
struct texture_data
|
||||
{
|
||||
vk::raii::Sampler sampler;
|
||||
std::shared_ptr<vk::raii::ImageView> image_view;
|
||||
std::shared_ptr<vk::raii::DescriptorSet> descriptor_set;
|
||||
};
|
||||
|
||||
public:
|
||||
struct imgui_frame
|
||||
{
|
||||
@@ -117,18 +149,10 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
vk::raii::PhysicalDevice physical_device;
|
||||
vk::raii::Device & device;
|
||||
uint32_t queue_family_index;
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
|
||||
vk::raii::Pipeline pipeline = nullptr;
|
||||
vk::raii::DescriptorSetLayout ds_layout;
|
||||
growable_descriptor_pool descriptor_pool;
|
||||
vk::raii::RenderPass renderpass;
|
||||
vk::raii::CommandPool command_pool;
|
||||
|
||||
std::unordered_map<ImTextureID, texture_data> textures;
|
||||
|
||||
std::vector<imgui_frame> frames;
|
||||
imgui_frame & get_frame(vk::Image destination);
|
||||
@@ -146,7 +170,7 @@ private:
|
||||
|
||||
std::vector<viewport> layers_;
|
||||
|
||||
xr::swapchain & swapchain;
|
||||
xr::swapchain swapchain;
|
||||
int image_index;
|
||||
|
||||
ImGuiContext * context;
|
||||
@@ -181,8 +205,9 @@ public:
|
||||
uint32_t queue_family_index,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
std::span<controller> controllers,
|
||||
xr::swapchain & swapchain,
|
||||
std::vector<viewport> layers);
|
||||
xr::swapchain && swapchain,
|
||||
std::vector<viewport> layers,
|
||||
std::shared_ptr<imgui_textures::image_cache_type> image_cache);
|
||||
|
||||
~imgui_context();
|
||||
|
||||
@@ -207,11 +232,6 @@ public:
|
||||
// Convert position from viewport coordinates to real-world
|
||||
glm::vec3 rw_from_vp(const ImVec2 & position);
|
||||
|
||||
ImTextureID load_texture(const std::string & filename, vk::raii::Sampler && sampler);
|
||||
ImTextureID load_texture(const std::string & filename);
|
||||
ImTextureID load_texture(const std::span<const std::byte> & bytes, vk::raii::Sampler && sampler);
|
||||
ImTextureID load_texture(const std::span<const std::byte> & bytes);
|
||||
void free_texture(ImTextureID);
|
||||
void set_current();
|
||||
|
||||
bool is_modal_popup_shown() const;
|
||||
@@ -221,3 +241,22 @@ public:
|
||||
void set_controllers_enabled(bool value);
|
||||
void tooltip(std::string_view text);
|
||||
};
|
||||
|
||||
void ScrollWhenDragging();
|
||||
|
||||
void CenterTextH(const std::string & text);
|
||||
|
||||
void CenterTextHV(const std::string & text);
|
||||
|
||||
void InputText(const char * label, std::string & text, const ImVec2 & size, ImGuiInputTextFlags flags);
|
||||
|
||||
bool RadioButtonWithoutCheckBox(const std::string & label, bool active, ImVec2 size_arg);
|
||||
|
||||
template <typename T, typename U>
|
||||
static bool RadioButtonWithoutCheckBox(const std::string & label, T & v, U v_button, ImVec2 size_arg)
|
||||
{
|
||||
const bool pressed = RadioButtonWithoutCheckBox(label, v == v_button, size_arg);
|
||||
if (pressed)
|
||||
v = v_button;
|
||||
return pressed;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
|
||||
#include <array>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include <entt/entity/entity.hpp>
|
||||
@@ -28,6 +31,7 @@
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "utils/magic_hash.h"
|
||||
#include "vertex_layout.h"
|
||||
#include "vk/allocation.h"
|
||||
|
||||
namespace renderer
|
||||
@@ -58,7 +62,8 @@ struct material
|
||||
float metallic_factor = 1;
|
||||
float roughness_factor = 1;
|
||||
float occlusion_strength = 0;
|
||||
float normal_scale = 0;
|
||||
float normal_scale = 1;
|
||||
float alpha_cutoff = 0.5;
|
||||
|
||||
uint32_t base_color_texcoord = 0;
|
||||
uint32_t metallic_roughness_texcoord = 0;
|
||||
@@ -78,9 +83,9 @@ struct material
|
||||
// Disable back face culling with this material
|
||||
bool double_sided = true;
|
||||
|
||||
// TODO transparency
|
||||
// fastgltf::AlphaMode alphaMode;
|
||||
// float alpha_cutoff;
|
||||
bool blend_enable = false;
|
||||
bool depth_test_enable = true;
|
||||
bool depth_write_enable = true;
|
||||
|
||||
gpu_data staging;
|
||||
|
||||
@@ -88,17 +93,8 @@ struct material
|
||||
std::shared_ptr<buffer_allocation> buffer;
|
||||
size_t offset;
|
||||
|
||||
// The descriptor set is managed by the scene renderer, it is updated whenever ds_dirty is true
|
||||
// Bindings 0-4: textures
|
||||
// Binding 5: uniform buffer
|
||||
std::shared_ptr<vk::raii::DescriptorSet> ds;
|
||||
|
||||
// Set to true to update the descriptor set at the next frame
|
||||
bool ds_dirty;
|
||||
|
||||
std::string name;
|
||||
std::string shader_name = "lit";
|
||||
bool blend_enable = true;
|
||||
std::string fragment_shader_name = "lit.frag";
|
||||
};
|
||||
|
||||
struct primitive
|
||||
@@ -108,7 +104,13 @@ struct primitive
|
||||
uint32_t vertex_count;
|
||||
vk::IndexType index_type;
|
||||
vk::DeviceSize index_offset;
|
||||
vk::DeviceSize vertex_offset;
|
||||
std::vector<vk::DeviceSize> vertex_offset; // TODO: inplace_vector
|
||||
vertex_layout layout;
|
||||
|
||||
glm::vec3 obb_min;
|
||||
glm::vec3 obb_max;
|
||||
|
||||
std::string vertex_shader;
|
||||
|
||||
// See also material::double_sided
|
||||
vk::CullModeFlagBits cull_mode = vk::CullModeFlagBits::eNone;
|
||||
@@ -118,34 +120,12 @@ struct primitive
|
||||
std::shared_ptr<material> material_;
|
||||
};
|
||||
|
||||
// TODO make sure the mesh cannot be changed while it is used
|
||||
struct mesh
|
||||
{
|
||||
std::vector<primitive> primitives;
|
||||
std::shared_ptr<buffer_allocation> buffer;
|
||||
};
|
||||
|
||||
// TODO move vertex class in .cpp, put vertex description in the primitive
|
||||
struct vertex
|
||||
{
|
||||
glm::vec3 position;
|
||||
glm::vec3 normal;
|
||||
glm::vec3 tangent;
|
||||
std::array<glm::vec2, 2> texcoord;
|
||||
glm::vec4 color;
|
||||
std::array<glm::vec4, 1> joints;
|
||||
std::array<glm::vec4, 1> weights;
|
||||
|
||||
struct description
|
||||
{
|
||||
vk::VertexInputBindingDescription binding;
|
||||
std::vector<vk::VertexInputAttributeDescription> attributes;
|
||||
std::vector<std::string> attribute_names;
|
||||
|
||||
vk::PipelineVertexInputStateCreateFlags flags{};
|
||||
};
|
||||
|
||||
static description describe();
|
||||
};
|
||||
} // namespace renderer
|
||||
|
||||
namespace std
|
||||
@@ -180,6 +160,55 @@ struct node
|
||||
bool reverse_side;
|
||||
uint32_t global_layer_mask;
|
||||
};
|
||||
|
||||
struct animation_track_base
|
||||
{
|
||||
enum class interpolation_t
|
||||
{
|
||||
step,
|
||||
linear,
|
||||
cubic_spline,
|
||||
};
|
||||
|
||||
entt::entity target;
|
||||
interpolation_t interpolation;
|
||||
};
|
||||
|
||||
template <auto node::*Field>
|
||||
struct animation_track_impl : animation_track_base
|
||||
{
|
||||
static const constexpr auto field = Field;
|
||||
using type = std::remove_reference_t<decltype(std::declval<node>().*field)>;
|
||||
|
||||
std::vector<float> timestamp;
|
||||
std::vector<type> value;
|
||||
};
|
||||
|
||||
using animation_track_position = animation_track_impl<&node::position>;
|
||||
using animation_track_orientation = animation_track_impl<&node::orientation>;
|
||||
using animation_track_scale = animation_track_impl<&node::scale>;
|
||||
|
||||
static_assert(std::is_same_v<animation_track_position::type, glm::vec3>);
|
||||
static_assert(std::is_same_v<animation_track_orientation::type, glm::quat>);
|
||||
static_assert(std::is_same_v<animation_track_scale::type, glm::vec3>);
|
||||
|
||||
struct animation
|
||||
{
|
||||
std::string name;
|
||||
std::vector<
|
||||
std::variant<
|
||||
animation_track_position,
|
||||
animation_track_orientation,
|
||||
animation_track_scale>>
|
||||
tracks;
|
||||
|
||||
float duration = 0;
|
||||
|
||||
float current_time = 0;
|
||||
bool playing = true;
|
||||
bool looping = true;
|
||||
};
|
||||
|
||||
} // namespace components
|
||||
|
||||
entt::entity find_node_by_name(entt::registry & scene, std::string_view name);
|
||||
|
||||
@@ -18,7 +18,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <entt/core/fwd.hpp>
|
||||
#include <filesystem>
|
||||
#include <functional>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
|
||||
#include "scene_components.h"
|
||||
@@ -31,17 +33,29 @@ class scene_loader
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
uint32_t queue_family_index;
|
||||
std::shared_ptr<renderer::material> default_material;
|
||||
std::filesystem::path texture_cache;
|
||||
|
||||
std::shared_ptr<entt::registry> operator()(
|
||||
std::span<const std::byte> data,
|
||||
const std::string & name = "",
|
||||
const std::filesystem::path & parent_path = "",
|
||||
const std::filesystem::path & gltf_texture_cache = "",
|
||||
std::function<void(float)> progress_cb = {});
|
||||
|
||||
public:
|
||||
scene_loader(vk::raii::Device & device, vk::raii::PhysicalDevice physical_device, thread_safe<vk::raii::Queue> & queue, uint32_t queue_family_index, std::shared_ptr<renderer::material> default_material) :
|
||||
device(device),
|
||||
physical_device(physical_device),
|
||||
queue(queue),
|
||||
queue_family_index(queue_family_index),
|
||||
default_material(default_material)
|
||||
{}
|
||||
scene_loader(
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
uint32_t queue_family_index,
|
||||
std::shared_ptr<renderer::material> default_material,
|
||||
std::filesystem::path texture_cache);
|
||||
|
||||
entt::registry operator()(const std::filesystem::path & gltf_path);
|
||||
scene_loader(const scene_loader &) = default;
|
||||
|
||||
void add_prefab(entt::registry & scene, const entt::registry & prefab, entt::entity root = entt::null);
|
||||
std::shared_ptr<entt::registry> operator()(
|
||||
const std::filesystem::path & gltf_path,
|
||||
std::function<void(float)> progress_cb = {});
|
||||
|
||||
void clear_texture_cache();
|
||||
};
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "render/vertex_layout.h"
|
||||
#include "utils/cache.h"
|
||||
#include "vk/shader.h"
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <glm/mat4x4.hpp>
|
||||
@@ -32,7 +35,6 @@
|
||||
|
||||
#include "vk/allocation.h"
|
||||
|
||||
#include "render/growable_descriptor_pool.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "utils/thread_safe.h"
|
||||
|
||||
@@ -42,6 +44,8 @@ struct renderpass_info
|
||||
vk::Format depth_format;
|
||||
bool keep_depth_buffer;
|
||||
vk::SampleCountFlagBits msaa_samples = vk::SampleCountFlagBits::e1;
|
||||
bool fragment_density_map;
|
||||
uint32_t multiview_count;
|
||||
|
||||
bool operator==(const renderpass_info & other) const noexcept = default;
|
||||
};
|
||||
@@ -50,7 +54,9 @@ struct pipeline_info
|
||||
{
|
||||
renderpass_info renderpass;
|
||||
|
||||
std::string shader_name;
|
||||
std::string vertex_shader_name;
|
||||
std::string fragment_shader_name;
|
||||
renderer::vertex_layout vertex_layout;
|
||||
|
||||
vk::CullModeFlags cull_mode = vk::CullModeFlagBits::eNone;
|
||||
vk::FrontFace front_face = vk::FrontFace::eClockwise;
|
||||
@@ -75,7 +81,7 @@ struct output_image_info
|
||||
vk::Extent2D output_size;
|
||||
VkImage color;
|
||||
VkImage depth;
|
||||
uint32_t base_array_layer;
|
||||
VkImage foveation;
|
||||
|
||||
bool operator==(const output_image_info & other) const noexcept = default;
|
||||
};
|
||||
@@ -99,12 +105,16 @@ struct hash<output_image_info> : utils::magic_hash<output_image_info>
|
||||
{};
|
||||
} // namespace std
|
||||
|
||||
struct image_loader;
|
||||
|
||||
class scene_renderer
|
||||
{
|
||||
vk::raii::PhysicalDevice physical_device;
|
||||
vk::raii::Device & device;
|
||||
vk::PhysicalDeviceProperties physical_device_properties;
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
uint32_t queue_family_index;
|
||||
vk::raii::CommandPool cb_pool;
|
||||
|
||||
// Destination images
|
||||
struct output_image
|
||||
@@ -117,32 +127,41 @@ class scene_renderer
|
||||
|
||||
image_allocation multisample_image;
|
||||
vk::raii::ImageView multisample_view = nullptr;
|
||||
|
||||
vk::raii::ImageView foveation_view = nullptr;
|
||||
};
|
||||
|
||||
struct renderpass
|
||||
{
|
||||
vk::raii::RenderPass renderpass = nullptr;
|
||||
vk::AttachmentReference color_attachment;
|
||||
vk::AttachmentReference depth_attachment;
|
||||
std::optional<vk::AttachmentReference> resolve_attachment; // Only used if MSAA is enabled
|
||||
std::optional<vk::AttachmentReference> fragment_density_attachment; // Only used if fragment density map is enabled
|
||||
int attachment_count;
|
||||
};
|
||||
|
||||
// Initialization functions
|
||||
output_image create_output_image_data(const output_image_info & info);
|
||||
vk::raii::RenderPass create_renderpass(const renderpass_info & info);
|
||||
renderpass create_renderpass(const renderpass_info & info);
|
||||
vk::raii::PipelineLayout create_pipeline_layout(std::span<vk::DescriptorSetLayout> layouts);
|
||||
vk::raii::Pipeline create_pipeline(const pipeline_info & info);
|
||||
|
||||
std::shared_ptr<renderer::texture> create_default_texture(vk::raii::CommandPool & cb_pool, std::vector<uint8_t> pixel);
|
||||
std::shared_ptr<renderer::texture> create_default_texture(image_loader & loader, std::vector<uint8_t> pixel, const std::string & name);
|
||||
std::shared_ptr<renderer::material> create_default_material(vk::raii::CommandPool & cb_pool);
|
||||
vk::raii::DescriptorSetLayout create_descriptor_set_layout(std::span<vk::DescriptorSetLayoutBinding> bindings, vk::DescriptorSetLayoutCreateFlags flags = {});
|
||||
|
||||
// Caches
|
||||
std::unordered_map<renderpass_info, vk::raii::RenderPass> renderpasses;
|
||||
std::unordered_map<renderpass_info, renderpass> renderpasses;
|
||||
std::unordered_map<output_image_info, output_image> output_images;
|
||||
std::unordered_map<pipeline_info, vk::raii::Pipeline> pipelines;
|
||||
utils::cache<std::string, shader, shader_loader> shader_cache;
|
||||
|
||||
output_image & get_output_image_data(const output_image_info & info);
|
||||
vk::raii::Pipeline & get_pipeline(const pipeline_info & info);
|
||||
vk::raii::RenderPass & get_renderpass(const renderpass_info & info);
|
||||
renderpass & get_renderpass(const renderpass_info & info);
|
||||
|
||||
vk::raii::DescriptorSetLayout layout_0; // Descriptor set 0: per-frame/view data (UBO) and per-instance data (UBO + SSBO)
|
||||
vk::raii::DescriptorSetLayout layout_1; // Descriptor set 1: per-material data (5 combined image samplers and 1 uniform buffer)
|
||||
|
||||
// Descriptor set 1: per-material data (5 combined image samplers and 1 uniform buffer)
|
||||
growable_descriptor_pool ds_pool_material;
|
||||
vk::raii::DescriptorSetLayout layout_0; // Descriptor set 0: per-frame/view data (UBO), per-instance data (UBO + SSBO), per-material data (5 combined image samplers and 1 uniform buffer)
|
||||
|
||||
vk::raii::PipelineLayout pipeline_layout = nullptr;
|
||||
|
||||
@@ -164,12 +183,12 @@ class scene_renderer
|
||||
// roughness_factor 1.0
|
||||
// occlusion_strength 0.0
|
||||
// normal_scale 0.0
|
||||
// alpha_cutoff 0.5
|
||||
std::shared_ptr<renderer::material> default_material;
|
||||
|
||||
struct frame_gpu_data
|
||||
{
|
||||
glm::mat4 view;
|
||||
glm::mat4 proj;
|
||||
std::array<glm::mat4, 2> view;
|
||||
glm::vec4 light_position;
|
||||
glm::vec4 ambient_color;
|
||||
glm::vec4 light_color;
|
||||
@@ -178,11 +197,29 @@ class scene_renderer
|
||||
struct instance_gpu_data
|
||||
{
|
||||
glm::mat4 model;
|
||||
glm::mat4 modelview;
|
||||
glm::mat4 modelviewproj;
|
||||
std::array<glm::mat4, 2> modelview;
|
||||
std::array<glm::mat4, 2> modelviewproj;
|
||||
std::array<glm::vec4, 4> clipping_planes;
|
||||
};
|
||||
|
||||
struct debug_draw_vertex
|
||||
{
|
||||
glm::vec4 position;
|
||||
glm::vec4 colour;
|
||||
};
|
||||
|
||||
std::vector<debug_draw_vertex> debug_draw_vertices;
|
||||
|
||||
public:
|
||||
struct stats
|
||||
{
|
||||
size_t count_primitives;
|
||||
size_t count_culled_primitives;
|
||||
size_t count_triangles;
|
||||
size_t count_culled_triangles;
|
||||
};
|
||||
|
||||
private:
|
||||
struct per_frame_resources
|
||||
{
|
||||
vk::raii::Fence fence = nullptr;
|
||||
@@ -194,6 +231,11 @@ class scene_renderer
|
||||
// device local, host visible, host coherent
|
||||
size_t uniform_buffer_offset;
|
||||
buffer_allocation uniform_buffer;
|
||||
|
||||
buffer_allocation debug_draw;
|
||||
|
||||
// Statistics
|
||||
stats frame_stats;
|
||||
};
|
||||
|
||||
std::vector<per_frame_resources> frame_resources;
|
||||
@@ -203,8 +245,6 @@ class scene_renderer
|
||||
|
||||
per_frame_resources & current_frame();
|
||||
|
||||
void update_material_descriptor_set(renderer::material & material);
|
||||
|
||||
public:
|
||||
static vk::Format find_usable_image_format(
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
@@ -219,7 +259,7 @@ public:
|
||||
vk::raii::Device & device,
|
||||
vk::raii::PhysicalDevice physical_device,
|
||||
thread_safe<vk::raii::Queue> & queue,
|
||||
vk::raii::CommandPool & cb_pool,
|
||||
uint32_t queue_family_index,
|
||||
int frames_in_flight = 2);
|
||||
|
||||
~scene_renderer();
|
||||
@@ -240,9 +280,20 @@ public:
|
||||
vk::Format depth_format,
|
||||
vk::Image color_buffer,
|
||||
vk::Image depth_buffer,
|
||||
std::span<frame_info> info);
|
||||
vk::Image foveation_image,
|
||||
std::span<frame_info> info,
|
||||
bool render_debug_draws = false);
|
||||
void end_frame();
|
||||
|
||||
void debug_draw_clear();
|
||||
// void debug_draw(std::span<glm::vec3> line, glm::vec4 color);
|
||||
void debug_draw_box(const glm::mat4 & model, glm::vec3 min, glm::vec3 max, glm::vec4 color);
|
||||
|
||||
const stats & last_frame_stats() const
|
||||
{
|
||||
return frame_resources[current_frame_index].frame_stats;
|
||||
}
|
||||
|
||||
double get_gpu_time() const
|
||||
{
|
||||
return gpu_time_s;
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "utils/magic_hash.h"
|
||||
#include <cstddef>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <glm/vec3.hpp>
|
||||
#include <glm/vec4.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
#include <vulkan/vulkan_format_traits.hpp>
|
||||
|
||||
namespace renderer
|
||||
{
|
||||
struct vertex_layout
|
||||
{
|
||||
std::vector<vk::VertexInputBindingDescription> bindings;
|
||||
std::vector<vk::VertexInputAttributeDescription> attributes;
|
||||
std::vector<std::string> attribute_names;
|
||||
|
||||
void add_attribute(std::string name, vk::Format format, uint32_t binding, uint32_t location, vk::VertexInputRate input_rate, int array_size = 1)
|
||||
{
|
||||
size_t texel_size = vk::blockSize(format);
|
||||
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (auto iter = std::ranges::find(bindings, binding, &vk::VertexInputBindingDescription::binding); iter == bindings.end())
|
||||
bindings.push_back(vk::VertexInputBindingDescription{
|
||||
.binding = binding,
|
||||
.stride = (uint32_t)(texel_size * array_size),
|
||||
.inputRate = input_rate,
|
||||
});
|
||||
else
|
||||
{
|
||||
offset = iter->stride;
|
||||
iter->stride += texel_size * array_size;
|
||||
}
|
||||
|
||||
for (int index = 0; index < array_size; index++)
|
||||
{
|
||||
attributes.push_back(vk::VertexInputAttributeDescription{
|
||||
.location = location + index,
|
||||
.binding = binding,
|
||||
.format = format,
|
||||
.offset = (uint32_t)(offset + index * texel_size),
|
||||
});
|
||||
|
||||
if (array_size == 1)
|
||||
attribute_names.push_back(name);
|
||||
else
|
||||
attribute_names.push_back(name + "_" + std::to_string(index));
|
||||
}
|
||||
}
|
||||
|
||||
void add_vertex_attribute(std::string name, vk::Format format, uint32_t binding, uint32_t location, int array_size = 1)
|
||||
{
|
||||
add_attribute(std::move(name), format, binding, location, vk::VertexInputRate::eVertex, array_size);
|
||||
}
|
||||
|
||||
bool operator==(const vertex_layout & other) const noexcept = default;
|
||||
};
|
||||
} // namespace renderer
|
||||
|
||||
namespace std
|
||||
{
|
||||
template <>
|
||||
struct hash<renderer::vertex_layout> : utils::magic_hash<renderer::vertex_layout>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct hash<vk::VertexInputBindingDescription> : utils::magic_hash<vk::VertexInputBindingDescription>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct hash<vk::VertexInputAttributeDescription> : utils::magic_hash<vk::VertexInputAttributeDescription>
|
||||
{};
|
||||
} // namespace std
|
||||
@@ -19,15 +19,15 @@
|
||||
|
||||
#include "scene.h"
|
||||
#include "application.h"
|
||||
#include "render/scene_loader.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/ranges.h"
|
||||
#include <entt/core/fwd.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <vulkan/vulkan_structs.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
// TODO remove constants
|
||||
@@ -37,7 +37,7 @@ std::vector<scene::meta *> scene::scene_registry;
|
||||
|
||||
scene::~scene() {}
|
||||
|
||||
scene::scene(key, const meta & current_meta, std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats) :
|
||||
scene::scene(key, const meta & current_meta, std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats, scene * parent_scene) :
|
||||
instance(application::instance().xr_instance),
|
||||
system(application::instance().xr_system_id),
|
||||
session(application::instance().xr_session),
|
||||
@@ -47,8 +47,8 @@ scene::scene(key, const meta & current_meta, std::span<const vk::Format> support
|
||||
device(application::instance().vk_device),
|
||||
physical_device(application::instance().vk_physical_device),
|
||||
queue(application::instance().vk_queue),
|
||||
commandpool(application::instance().vk_cmdpool),
|
||||
queue_family_index(application::instance().vk_queue_family_index),
|
||||
commandpool(application::instance().vk_cmdpool),
|
||||
current_meta(current_meta)
|
||||
{
|
||||
swapchain_format = vk::Format::eUndefined;
|
||||
@@ -87,6 +87,19 @@ scene::scene(key, const meta & current_meta, std::span<const vk::Format> support
|
||||
instance.has_extension(XR_FB_COMPOSITION_LAYER_DEPTH_TEST_EXTENSION_NAME);
|
||||
|
||||
composition_layer_color_scale_bias_supported = instance.has_extension(XR_KHR_COMPOSITION_LAYER_COLOR_SCALE_BIAS_EXTENSION_NAME);
|
||||
|
||||
if (parent_scene)
|
||||
{
|
||||
renderer = parent_scene->renderer;
|
||||
gltf_cache = parent_scene->gltf_cache;
|
||||
image_cache = parent_scene->image_cache;
|
||||
}
|
||||
else
|
||||
{
|
||||
renderer = std::make_shared<scene_renderer>(device, physical_device, queue, queue_family_index);
|
||||
gltf_cache = std::make_shared<gltf_cache_type>(device, physical_device, queue, queue_family_index, renderer->get_default_material(), application::get_cache_path() / "textures");
|
||||
image_cache = std::make_shared<image_cache_type>(device, physical_device, queue, queue_family_index);
|
||||
}
|
||||
}
|
||||
|
||||
void scene::set_focused(bool status)
|
||||
@@ -140,7 +153,9 @@ void scene::render_world(
|
||||
uint32_t height,
|
||||
bool keep_depth_buffer,
|
||||
uint32_t layer_mask,
|
||||
XrColor4f clear_color)
|
||||
XrColor4f clear_color,
|
||||
const std::optional<xr::foveation_profile> & foveation,
|
||||
bool render_debug_draws)
|
||||
{
|
||||
std::vector<scene_renderer::frame_info> frames;
|
||||
frames.reserve(views.size());
|
||||
@@ -153,13 +168,14 @@ void scene::render_world(
|
||||
if (keep_depth_buffer)
|
||||
composition_layer_depth.reserve(views.size());
|
||||
|
||||
auto [color_swapchain, color_image] = [&]() -> std::pair<XrSwapchain, vk::Image> {
|
||||
xr::swapchain & color_swapchain = get_swapchain(swapchain_format, width, height, 1, views.size());
|
||||
auto [color_swapchain, color_image, foveation_image] = [&]() -> std::tuple<XrSwapchain, vk::Image, vk::Image> {
|
||||
xr::swapchain & color_swapchain = get_swapchain(swapchain_format, width, height, 1, views.size(), foveation);
|
||||
|
||||
int color_image_index = color_swapchain.acquire();
|
||||
vk::Image color_image = color_swapchain.images()[color_image_index].image;
|
||||
vk::Image foveation_image = color_swapchain.images()[color_image_index].foveation;
|
||||
color_swapchain.wait();
|
||||
return {color_swapchain, color_image};
|
||||
return {color_swapchain, color_image, foveation_image};
|
||||
}();
|
||||
|
||||
auto [depth_swapchain, depth_image] = [&]() -> std::pair<XrSwapchain, vk::Image> {
|
||||
@@ -228,7 +244,9 @@ void scene::render_world(
|
||||
depth_format,
|
||||
color_image,
|
||||
depth_image,
|
||||
frames);
|
||||
foveation_image,
|
||||
frames,
|
||||
render_debug_draws);
|
||||
|
||||
add_projection_layer(
|
||||
XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
@@ -237,8 +255,40 @@ void scene::render_world(
|
||||
std::move(composition_layer_depth));
|
||||
}
|
||||
|
||||
xr::swapchain & scene::get_swapchain(vk::Format format, int32_t width, int32_t height, int sample_count, uint32_t array_size)
|
||||
xr::swapchain & scene::get_swapchain(vk::Format format, int32_t width, int32_t height, int sample_count, uint32_t array_size, const std::optional<xr::foveation_profile> & foveation)
|
||||
{
|
||||
XrFoveationProfileFB foveation_profile = XR_NULL_HANDLE;
|
||||
XrFoveationLevelFB foveation_level = XR_FOVEATION_LEVEL_NONE_FB;
|
||||
float foveation_vertical_offset_degrees = 0;
|
||||
bool foveation_dynamic = false;
|
||||
|
||||
if (foveation)
|
||||
{
|
||||
foveation_profile = *foveation;
|
||||
foveation_level = foveation->level();
|
||||
foveation_vertical_offset_degrees = foveation->vertical_offset_degrees();
|
||||
foveation_dynamic = foveation->dynamic();
|
||||
}
|
||||
|
||||
// Look for an exact match
|
||||
for (swapchain_entry & entry: swapchains)
|
||||
{
|
||||
if (not entry.used and
|
||||
entry.format == format and
|
||||
entry.width == width and
|
||||
entry.height == height and
|
||||
entry.sample_count == sample_count and
|
||||
entry.array_size == array_size and
|
||||
entry.foveation_level == foveation_level and
|
||||
entry.foveation_vertical_offset_degrees == foveation_vertical_offset_degrees and
|
||||
entry.foveation_dynamic == foveation_dynamic)
|
||||
{
|
||||
entry.used = true;
|
||||
return entry.swapchain;
|
||||
}
|
||||
}
|
||||
|
||||
// Look for a swapchain with a different foveation profile
|
||||
for (swapchain_entry & entry: swapchains)
|
||||
{
|
||||
if (not entry.used and
|
||||
@@ -248,23 +298,41 @@ xr::swapchain & scene::get_swapchain(vk::Format format, int32_t width, int32_t h
|
||||
entry.sample_count == sample_count and
|
||||
entry.array_size == array_size)
|
||||
{
|
||||
spdlog::info("Updating swapchain foveation profile to {}, {:.1f} deg", magic_enum::enum_name(foveation_level), foveation_vertical_offset_degrees);
|
||||
entry.foveation_level = foveation_level;
|
||||
entry.foveation_vertical_offset_degrees = foveation_vertical_offset_degrees;
|
||||
entry.foveation_dynamic = foveation_dynamic;
|
||||
|
||||
entry.used = true;
|
||||
entry.swapchain.update_foveation(*foveation);
|
||||
return entry.swapchain;
|
||||
}
|
||||
}
|
||||
|
||||
spdlog::info("Creating new swapchain: {}, {}x{}, {} sample(s), {} level(s)", magic_enum::enum_name(format), width, height, sample_count, array_size);
|
||||
swapchain_entry new_swapchain{
|
||||
.format = format,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.sample_count = sample_count,
|
||||
.array_size = array_size,
|
||||
.foveation_level = foveation_level,
|
||||
.foveation_vertical_offset_degrees = foveation_vertical_offset_degrees,
|
||||
.foveation_dynamic = foveation_dynamic,
|
||||
.used = true,
|
||||
.swapchain = xr::swapchain(
|
||||
instance,
|
||||
session,
|
||||
device,
|
||||
format,
|
||||
width,
|
||||
height,
|
||||
sample_count,
|
||||
array_size,
|
||||
foveation_profile)};
|
||||
spdlog::info("Created swapchain");
|
||||
|
||||
return swapchains.emplace_back(swapchain_entry{
|
||||
.format = format,
|
||||
.width = width,
|
||||
.height = height,
|
||||
.sample_count = sample_count,
|
||||
.array_size = array_size,
|
||||
.used = true,
|
||||
.swapchain = xr::swapchain(session, device, format, width, height, sample_count, array_size),
|
||||
})
|
||||
.swapchain;
|
||||
return swapchains.emplace_back(std::move(new_swapchain)).swapchain;
|
||||
}
|
||||
|
||||
void scene::clear_swapchains()
|
||||
@@ -434,18 +502,110 @@ void scene::render_end()
|
||||
session.end_frame(predicted_display_time, openxr_layers, blend_mode);
|
||||
}
|
||||
|
||||
std::pair<entt::entity, components::node &> scene::load_gltf(const std::filesystem::path & path, uint32_t layer_mask)
|
||||
template <typename T>
|
||||
void copy_components(entt::registry & scene, const entt::registry & prefab, const std::unordered_map<entt::entity, entt::entity> & entity_map)
|
||||
{
|
||||
auto entity = world.create();
|
||||
auto & node = world.emplace<components::node>(entity);
|
||||
for (const auto & [entity, component]: prefab.view<T>().each())
|
||||
{
|
||||
scene.emplace<T>(entity_map.at(entity), component);
|
||||
}
|
||||
}
|
||||
|
||||
std::pair<entt::entity, components::node &> scene::add_gltf(std::shared_ptr<entt::registry> gltf, uint32_t layer_mask)
|
||||
{
|
||||
auto root = world.create();
|
||||
auto & node = world.emplace<components::node>(root);
|
||||
node.layer_mask = layer_mask;
|
||||
|
||||
assert(renderer);
|
||||
scene_loader loader(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
auto prefab_entities = gltf->view<entt::entity>();
|
||||
|
||||
loader.add_prefab(world, loader(path), entity);
|
||||
std::vector<entt::entity> scene_entities{prefab_entities.size()};
|
||||
world.create(scene_entities.begin(), scene_entities.end());
|
||||
|
||||
return {entity, node};
|
||||
std::unordered_map<entt::entity, entt::entity> entity_map; // key: prefab entity, value: scene entity
|
||||
|
||||
entity_map.emplace(entt::null, root);
|
||||
for (auto [prefab_entity, scene_entity]: std::ranges::zip_view(prefab_entities, scene_entities))
|
||||
entity_map.emplace(prefab_entity, scene_entity);
|
||||
|
||||
copy_components<components::node>(world, *gltf, entity_map);
|
||||
copy_components<components::animation>(world, *gltf, entity_map);
|
||||
|
||||
// update links
|
||||
for (auto [prefab_entity, scene_entity]: entity_map)
|
||||
{
|
||||
if (prefab_entity == entt::null)
|
||||
continue;
|
||||
|
||||
auto * node = world.try_get<components::node>(scene_entity);
|
||||
auto * anim = world.try_get<components::animation>(scene_entity);
|
||||
|
||||
if (node)
|
||||
{
|
||||
node->parent = entity_map.at(node->parent);
|
||||
|
||||
for (auto & joint: node->joints)
|
||||
{
|
||||
joint.first = entity_map.at(joint.first);
|
||||
}
|
||||
}
|
||||
|
||||
if (anim)
|
||||
{
|
||||
for (auto & track: anim->tracks)
|
||||
{
|
||||
std::visit(utils::overloaded{[&](auto & t) { t.target = entity_map.at(t.target); }}, track);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {root, node};
|
||||
}
|
||||
|
||||
std::shared_ptr<entt::registry> scene::load_gltf(const std::filesystem::path & path, std::function<void(float)> progress_cb)
|
||||
{
|
||||
return gltf_cache->load(path, path, progress_cb);
|
||||
}
|
||||
|
||||
void scene::unload_gltf(const std::filesystem::path & path)
|
||||
{
|
||||
gltf_cache->remove(path);
|
||||
}
|
||||
|
||||
std::pair<entt::entity, components::node &> scene::add_gltf(const std::filesystem::path & path, uint32_t layer_mask)
|
||||
{
|
||||
return add_gltf(load_gltf(path), layer_mask);
|
||||
}
|
||||
|
||||
void scene::remove(entt::entity entity)
|
||||
{
|
||||
std::vector to_be_removed{entity};
|
||||
|
||||
while (not to_be_removed.empty())
|
||||
{
|
||||
entt::entity parent = to_be_removed.back();
|
||||
to_be_removed.pop_back();
|
||||
world.destroy(parent);
|
||||
|
||||
for (auto [e, node]: world.view<components::node>().each())
|
||||
{
|
||||
if (node.parent == parent)
|
||||
to_be_removed.push_back(e);
|
||||
}
|
||||
|
||||
for (auto [e, anim]: world.view<components::animation>().each())
|
||||
{
|
||||
if (std::ranges::any_of(anim.tracks,
|
||||
[&](const auto & track) { return std::visit(
|
||||
[&](const components::animation_track_base & track) {
|
||||
return track.target == parent;
|
||||
},
|
||||
track); }))
|
||||
{
|
||||
to_be_removed.push_back(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void scene::on_unfocused() {}
|
||||
|
||||
@@ -19,23 +19,24 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "render/image_loader.h"
|
||||
#include "render/scene_loader.h"
|
||||
#include "render/scene_renderer.h"
|
||||
#include "utils/cache.h"
|
||||
#include "xr/actionset.h"
|
||||
#include "xr/foveation_profile.h"
|
||||
#include "xr/instance.h"
|
||||
#include "xr/session.h"
|
||||
#include "xr/swapchain.h"
|
||||
#include "xr/system.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <filesystem>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "render/imgui_impl.h"
|
||||
#include "render/scene_renderer.h"
|
||||
#include <entt/entity/registry.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
// See http://www.nirfriedman.com/2018/04/29/unforgettable-factory/
|
||||
@@ -86,21 +87,26 @@ protected:
|
||||
XrViewConfigurationType viewconfig;
|
||||
bool focused = false;
|
||||
|
||||
public:
|
||||
vk::raii::Instance & vk_instance;
|
||||
vk::raii::Device & device;
|
||||
vk::raii::PhysicalDevice & physical_device;
|
||||
thread_safe<vk::raii::Queue> & queue;
|
||||
vk::raii::CommandPool & commandpool;
|
||||
uint32_t queue_family_index;
|
||||
|
||||
protected:
|
||||
vk::raii::CommandPool & commandpool;
|
||||
|
||||
const meta & current_meta;
|
||||
|
||||
std::optional<scene_renderer> renderer;
|
||||
std::shared_ptr<scene_renderer> renderer;
|
||||
|
||||
public:
|
||||
std::optional<scene_loader> loader;
|
||||
using gltf_cache_type = utils::cache<std::string, entt::registry, scene_loader>;
|
||||
std::shared_ptr<gltf_cache_type> gltf_cache;
|
||||
|
||||
using image_cache_type = utils::cache<std::string, loaded_image, image_loader>;
|
||||
std::shared_ptr<image_cache_type> image_cache;
|
||||
|
||||
protected:
|
||||
vk::Format swapchain_format;
|
||||
vk::Format depth_format;
|
||||
bool composition_layer_depth_test_supported;
|
||||
@@ -148,13 +154,17 @@ protected:
|
||||
int sample_count;
|
||||
uint32_t array_size;
|
||||
|
||||
XrFoveationLevelFB foveation_level;
|
||||
float foveation_vertical_offset_degrees;
|
||||
bool foveation_dynamic;
|
||||
|
||||
bool used;
|
||||
xr::swapchain swapchain;
|
||||
};
|
||||
std::vector<swapchain_entry> swapchains;
|
||||
|
||||
// The returned reference is valid until the next call to get_swapchain
|
||||
xr::swapchain & get_swapchain(vk::Format format, int32_t width, int32_t height, int sample_count, uint32_t array_size);
|
||||
xr::swapchain & get_swapchain(vk::Format format, int32_t width, int32_t height, int sample_count, uint32_t array_size, const std::optional<xr::foveation_profile> & foveation = std::nullopt);
|
||||
void clear_swapchains();
|
||||
|
||||
void render_start(bool passthrough, XrTime predicted_display_time);
|
||||
@@ -181,7 +191,9 @@ protected:
|
||||
uint32_t height,
|
||||
bool keep_depth_buffer,
|
||||
uint32_t layer_mask,
|
||||
XrColor4f clear_color);
|
||||
XrColor4f clear_color,
|
||||
const std::optional<xr::foveation_profile> & foveation = std::nullopt,
|
||||
bool render_debug_draws = false);
|
||||
|
||||
void set_color_scale_bias(XrColor4f scale, XrColor4f bias);
|
||||
void set_depth_test(bool write, XrCompareOpFB op);
|
||||
@@ -193,7 +205,7 @@ protected:
|
||||
virtual void on_focused();
|
||||
|
||||
public:
|
||||
scene(key, const meta &, std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats);
|
||||
scene(key, const meta &, std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats, scene * parent_scene);
|
||||
|
||||
virtual ~scene();
|
||||
|
||||
@@ -202,8 +214,22 @@ public:
|
||||
virtual void on_xr_event(const xr::event &);
|
||||
|
||||
entt::registry world;
|
||||
std::pair<entt::entity, components::node &> load_gltf(const std::filesystem::path & path, uint32_t layer_mask = -1);
|
||||
void remove(entt::entity entity); // TODO
|
||||
|
||||
std::shared_ptr<entt::registry> load_gltf(const std::filesystem::path & path, std::function<void(float)> progress_cb = {});
|
||||
void unload_gltf(const std::filesystem::path & path);
|
||||
std::pair<entt::entity, components::node &> add_gltf(std::shared_ptr<entt::registry> gltf, uint32_t layer_mask = -1);
|
||||
std::pair<entt::entity, components::node &> add_gltf(const std::filesystem::path & path, uint32_t layer_mask = -1);
|
||||
void clear_texture_cache()
|
||||
{
|
||||
gltf_cache->loader().clear_texture_cache();
|
||||
}
|
||||
|
||||
void clear_gltf_cache()
|
||||
{
|
||||
gltf_cache->clear();
|
||||
}
|
||||
|
||||
void remove(entt::entity entity);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -221,8 +247,14 @@ class scene_impl : public scene
|
||||
|
||||
static inline bool registered = scene_impl<T>::register_scene();
|
||||
|
||||
scene_impl(std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats = {}) :
|
||||
scene(key{}, T::get_meta_scene(), supported_color_formats, supported_depth_formats)
|
||||
scene_impl(std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats, scene & parent_scene) :
|
||||
scene(key{}, T::get_meta_scene(), supported_color_formats, supported_depth_formats, &parent_scene)
|
||||
{
|
||||
(void)registered;
|
||||
}
|
||||
|
||||
scene_impl(std::span<const vk::Format> supported_color_formats, std::span<const vk::Format> supported_depth_formats) :
|
||||
scene(key{}, T::get_meta_scene(), supported_color_formats, supported_depth_formats, nullptr)
|
||||
{
|
||||
(void)registered;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
#include "app_launcher.h"
|
||||
|
||||
#include "constants.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "scenes/stream.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/ranges.h"
|
||||
|
||||
#include <imspinner.h>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <uni_algo/case.h>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// Display a button with an image and a text centred horizontally
|
||||
static bool icon(
|
||||
const std::string & text,
|
||||
ImTextureRef tex_ref,
|
||||
const ImVec2 & image_size,
|
||||
ImGuiButtonFlags flags = 0,
|
||||
const ImVec2 & size_arg = ImVec2(0, 0),
|
||||
const ImVec2 & uv0 = ImVec2(0, 0),
|
||||
const ImVec2 & uv1 = ImVec2(1, 1),
|
||||
const ImVec4 & tint_col = ImVec4(1, 1, 1, 1))
|
||||
{
|
||||
// Based on ImGui::ButtonEx and ImGui::ImageButtonEx
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true);
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(
|
||||
size_arg,
|
||||
std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f,
|
||||
image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||
|
||||
ImRect image_pos(
|
||||
{(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y},
|
||||
{(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y});
|
||||
|
||||
ImRect label_pos(
|
||||
{bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y},
|
||||
{bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y});
|
||||
|
||||
ImGui::ItemSize(bb);
|
||||
|
||||
ImGuiID id = window->GetID(text.c_str());
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
// Render
|
||||
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered
|
||||
: ImGuiCol_Button);
|
||||
ImGui::RenderNavCursor(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
|
||||
window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col));
|
||||
ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
app_launcher::app_launcher(
|
||||
scenes::stream & stream,
|
||||
std::string server_name) :
|
||||
server_name(std::move(server_name)),
|
||||
stream(stream),
|
||||
textures(
|
||||
stream.physical_device,
|
||||
stream.device,
|
||||
stream.queue_family_index,
|
||||
stream.queue)
|
||||
{
|
||||
default_icon = textures.load_texture("assets://default_icon.ktx2");
|
||||
}
|
||||
|
||||
app_launcher::~app_launcher()
|
||||
{
|
||||
stream.device.waitIdle();
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
textures.free_texture(app_icon);
|
||||
textures.free_texture(default_icon);
|
||||
}
|
||||
|
||||
app_launcher::clicked app_launcher::draw_gui(imgui_context & imgui_ctx, const std::string & cancel)
|
||||
{
|
||||
auto res = clicked::None;
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
bool app_starting = start_time != std::chrono::steady_clock::time_point{} and
|
||||
t0 - start_time < 10s and
|
||||
stream.current_state() != scenes::stream::state::streaming;
|
||||
|
||||
auto cancel_size = ImGui::CalcTextSize(cancel.c_str());
|
||||
|
||||
auto apps = applications.lock();
|
||||
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
if (server_name.empty())
|
||||
CenterTextH(_("Connected to WiVRn server"));
|
||||
else
|
||||
CenterTextH(fmt::format(_F("Connected to {}"), server_name));
|
||||
ImGui::PopFont();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
if (apps->empty())
|
||||
{
|
||||
CenterTextHV(_("Start an application on the server to start streaming."));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
||||
ImGui::BeginDisabled(app_starting);
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, cancel_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
||||
|
||||
ImGui::Indent(20);
|
||||
if (server_name.empty())
|
||||
ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming."));
|
||||
else
|
||||
ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str());
|
||||
ImGui::Unindent();
|
||||
|
||||
float icon_width = 400;
|
||||
float icon_spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||
float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x;
|
||||
|
||||
int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing);
|
||||
float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing;
|
||||
|
||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
{
|
||||
ImTextureID texture = [&]() -> ImTextureID {
|
||||
if (app.image.empty())
|
||||
return default_icon;
|
||||
else
|
||||
{
|
||||
auto it = app_icons.find(app.id);
|
||||
if (it == app_icons.end())
|
||||
{
|
||||
// Don't load too many textures at the same time to keep the GUI responsive
|
||||
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
||||
return default_icon;
|
||||
|
||||
try
|
||||
{
|
||||
it = app_icons.emplace(app.id, textures.load_texture(app.image)).first;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Unable to load icon for \"{}\": {}", app.id, e.what());
|
||||
|
||||
app.image.clear();
|
||||
return default_icon;
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
}();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||
{
|
||||
res = clicked::Start;
|
||||
start_time = t0;
|
||||
stream.start_application(app.id);
|
||||
}
|
||||
imgui_ctx.vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
|
||||
if ((index + 1) % icons_per_line)
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
{
|
||||
if (not std::ranges::contains(*apps, app_id, &app::id))
|
||||
to_be_removed.emplace_back(app_id, app_icon);
|
||||
}
|
||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||
{
|
||||
imgui_ctx.free_texture(app_icon);
|
||||
app_icons.erase(app_id);
|
||||
}
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (app_starting)
|
||||
{
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||
ImSpinner::SpinnerAng("App starting spinner",
|
||||
200, // Radius
|
||||
40, // Thickness
|
||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||
6, // Velocity
|
||||
0.75f * 2 * M_PI // Angle
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - cancel_size - ImVec2{50, 50});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(cancel.c_str()))
|
||||
res = clicked::Cancel;
|
||||
imgui_ctx.vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
||||
ImGui::PopStyleVar(2);
|
||||
return res;
|
||||
}
|
||||
|
||||
void app_launcher::operator()(to_headset::application_list && apps)
|
||||
{
|
||||
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
|
||||
return una::casesens::collate_utf8(l.name, r.name) < 0;
|
||||
});
|
||||
|
||||
auto locked = applications.lock();
|
||||
|
||||
locked->clear();
|
||||
locked->reserve(apps.applications.size());
|
||||
for (const auto & i: apps.applications)
|
||||
{
|
||||
locked->push_back(app{
|
||||
.id = std::move(i.id),
|
||||
.name = std::move(i.name),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void app_launcher::operator()(to_headset::application_icon && icon)
|
||||
{
|
||||
auto locked = applications.lock();
|
||||
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
|
||||
it->image = std::move(icon.image);
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2025 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "imgui.h"
|
||||
#include "render/imgui_impl.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include <chrono>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace scenes
|
||||
{
|
||||
class stream;
|
||||
}
|
||||
|
||||
class app_launcher
|
||||
{
|
||||
struct app
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image;
|
||||
};
|
||||
|
||||
std::chrono::steady_clock::time_point start_time{};
|
||||
std::string server_name;
|
||||
scenes::stream & stream;
|
||||
imgui_textures textures;
|
||||
ImTextureID default_icon;
|
||||
std::unordered_map<std::string, ImTextureID> app_icons;
|
||||
// Last application list received from server
|
||||
thread_safe<std::vector<app>> applications;
|
||||
|
||||
public:
|
||||
app_launcher(scenes::stream &, std::string server_name);
|
||||
~app_launcher();
|
||||
enum clicked
|
||||
{
|
||||
None,
|
||||
Cancel,
|
||||
Start,
|
||||
};
|
||||
// cancel: text to display on the quit/disconnect/cancel button
|
||||
clicked draw_gui(imgui_context &, const std::string & cancel);
|
||||
|
||||
void operator()(wivrn::to_headset::application_list && apps);
|
||||
void operator()(wivrn::to_headset::application_icon && icon);
|
||||
};
|
||||
@@ -257,8 +257,8 @@ void blitter::push_image(vk::raii::CommandBuffer & cmd, uint8_t stream, vk::Samp
|
||||
VkBool32(alpha));
|
||||
|
||||
// Create graphics pipeline
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, "stream.vert");
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "stream.frag");
|
||||
auto vertex_shader = load_shader(device, "stream.vert");
|
||||
auto fragment_shader = load_shader(device, "stream.frag");
|
||||
|
||||
p.layout = device.createPipelineLayout(vk::PipelineLayoutCreateInfo{
|
||||
.setLayoutCount = 1,
|
||||
|
||||
@@ -67,7 +67,7 @@ void hand_model::add_hand(scene & scene,
|
||||
const std::filesystem::path & gltf_path,
|
||||
uint32_t layer_mask)
|
||||
{
|
||||
auto && [entity, node] = scene.load_gltf(gltf_path, layer_mask);
|
||||
auto && [entity, node] = scene.add_gltf(gltf_path, layer_mask);
|
||||
|
||||
node.name = gltf_path.stem();
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include "input_profile.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
#include "hardware.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include "xr/space.h"
|
||||
#include <entt/entt.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
@@ -175,14 +175,14 @@ struct json_visual_response
|
||||
|
||||
input_profile::input_profile(scene & scene, const std::filesystem::path & json_profile, uint32_t layer_mask_controller, uint32_t layer_mask_ray)
|
||||
{
|
||||
std::string json = asset(json_profile);
|
||||
utils::mapped_file json{json_profile};
|
||||
|
||||
simdjson::dom::parser parser;
|
||||
simdjson::dom::element root = parser.parse(json);
|
||||
simdjson::dom::element root = parser.parse(reinterpret_cast<const char *>(json.data()), json.size());
|
||||
|
||||
id = std::string(root["profileId"]);
|
||||
|
||||
std::vector<std::tuple<std::string, entt::entity, entt::registry>> models;
|
||||
std::vector<std::tuple<std::string, entt::entity, std::shared_ptr<entt::registry>>> models;
|
||||
std::vector<json_visual_response> json_responses;
|
||||
|
||||
// Fill models with the different models to be loaded and their name ("left" or "right")
|
||||
@@ -193,9 +193,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
// std::string user_path = "/user/hand/" + std::string(layout.key);
|
||||
std::filesystem::path asset_path = json_profile.parent_path() / std::string(layout.value["assetPath"]);
|
||||
|
||||
// scene.load_gltf(asset_path);
|
||||
|
||||
entt::registry & data = std::get<2>(models.emplace_back(layout.key, entt::null, (*scene.loader)(asset_path)));
|
||||
std::shared_ptr<entt::registry> data = std::get<2>(models.emplace_back(layout.key, entt::null, scene.load_gltf(asset_path)));
|
||||
|
||||
for (simdjson::dom::key_value_pair component: simdjson::dom::object(layout.value["components"]))
|
||||
{
|
||||
@@ -221,14 +219,14 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
vr.component_subpath = component_subpath;
|
||||
|
||||
// Check if the node exists
|
||||
find_node_by_name(data, vr.target_node);
|
||||
find_node_by_name(*data, vr.target_node);
|
||||
|
||||
auto node_property = parse_value_node_property(response.value["valueNodeProperty"]);
|
||||
switch (node_property)
|
||||
{
|
||||
case value_node_property::transform: {
|
||||
auto min_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["minNodeName"])));
|
||||
auto max_node = data.get<components::node>(find_node_by_name(data, std::string(response.value["maxNodeName"])));
|
||||
auto min_node = data->get<components::node>(find_node_by_name(*data, std::string(response.value["minNodeName"])));
|
||||
auto max_node = data->get<components::node>(find_node_by_name(*data, std::string(response.value["maxNodeName"])));
|
||||
|
||||
components::details::node_state_transform min{
|
||||
min_node.position,
|
||||
@@ -265,14 +263,10 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
else
|
||||
continue;
|
||||
|
||||
entity = scene.world.create();
|
||||
scene.world.emplace<bound_space>(entity, space);
|
||||
scene.world.emplace<components::node>(entity, components::node{
|
||||
.name = layout,
|
||||
.layer_mask = layer_mask_controller,
|
||||
});
|
||||
|
||||
scene.loader->add_prefab(scene.world, std::move(model), entity);
|
||||
auto [e, node] = scene.add_gltf(model, layer_mask_controller);
|
||||
node.name = layout;
|
||||
entity = e;
|
||||
scene.world.emplace<bound_space>(e, space);
|
||||
|
||||
spdlog::debug("Created entity {}", layout);
|
||||
}
|
||||
@@ -287,7 +281,7 @@ input_profile::input_profile(scene & scene, const std::filesystem::path & json_p
|
||||
else
|
||||
continue;
|
||||
|
||||
auto && [entity, node] = scene.load_gltf(controller_ray_model_name(), layer_mask_ray);
|
||||
auto && [entity, node] = scene.add_gltf(controller_ray_model_name(), layer_mask_ray);
|
||||
node.name = (std::string)layout.key + "_ray";
|
||||
spdlog::debug("Created entity {}", node.name);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "lobby.h"
|
||||
#include "application.h"
|
||||
#include "configuration.h"
|
||||
#include "constants.h"
|
||||
#include "glm/geometric.hpp"
|
||||
#include "hand_model.h"
|
||||
@@ -26,18 +27,23 @@
|
||||
#include "imgui.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "protocol_version.h"
|
||||
#include "render/scene_data.h"
|
||||
#include "render/animation.h"
|
||||
#include "render/scene_components.h"
|
||||
#include "stream.h"
|
||||
#include "utils/files.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "wivrn_client.h"
|
||||
#include "wivrn_discover.h"
|
||||
#include "wivrn_sockets.h"
|
||||
#include "xr/passthrough.h"
|
||||
#include "xr/space.h"
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
|
||||
#include <chrono> // IWYU pragma: keep
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <glm/ext.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/matrix.hpp>
|
||||
#include <magic_enum.hpp>
|
||||
@@ -53,6 +59,11 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "wivrn_config.h"
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
#include "vk/renderdoc.h"
|
||||
#endif
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
static bool force_autoconnect = false;
|
||||
@@ -110,7 +121,7 @@ scenes::lobby::lobby() :
|
||||
scene_impl<lobby>(supported_color_formats, supported_depth_formats)
|
||||
{
|
||||
spdlog::info("Using formats {} and {}", vk::to_string(swapchain_format), vk::to_string(depth_format));
|
||||
// composition_layer_depth_test_supported = false;
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
spdlog::info("Composition layer depth test supported");
|
||||
else
|
||||
@@ -121,6 +132,15 @@ scenes::lobby::lobby() :
|
||||
else
|
||||
spdlog::info("Composition layer color scale/bias NOT supported");
|
||||
|
||||
if (instance.has_extension(XR_FB_FOVEATION_VULKAN_EXTENSION_NAME) and
|
||||
instance.has_extension(XR_FB_FOVEATION_CONFIGURATION_EXTENSION_NAME))
|
||||
{
|
||||
spdlog::info("Foveation image supported");
|
||||
foveation = xr::foveation_profile(instance, session, XR_FOVEATION_LEVEL_NONE_FB, -10, false);
|
||||
}
|
||||
else
|
||||
spdlog::info("Foveation image NOT supported");
|
||||
|
||||
if (std::getenv("WIVRN_AUTOCONNECT"))
|
||||
force_autoconnect = true;
|
||||
|
||||
@@ -572,7 +592,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
{
|
||||
auto session = async_session.get();
|
||||
if (session)
|
||||
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod);
|
||||
next_scene = stream::create(std::move(session), 1'000'000'000.f / frame_state.predictedDisplayPeriod, server_name, *this);
|
||||
|
||||
async_session.reset();
|
||||
}
|
||||
@@ -631,6 +651,9 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
session.begin_frame();
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_begin(*vk_instance);
|
||||
#endif
|
||||
|
||||
XrSpace world_space = application::space(xr::spaces::world);
|
||||
auto [flags, views] = session.locate_views(viewconfig, frame_state.predictedDisplayTime, world_space);
|
||||
@@ -713,8 +736,21 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
}
|
||||
#endif
|
||||
|
||||
renderer->debug_draw_clear();
|
||||
std::vector<std::pair<int, XrCompositionLayerQuad>> imgui_layers = draw_gui(frame_state.predictedDisplayTime);
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
if (auto * node = world.try_get<components::node>(debug_primitive_to_highlight.first);
|
||||
node and
|
||||
node->mesh and
|
||||
debug_primitive_to_highlight.second < node->mesh->primitives.size())
|
||||
{
|
||||
const auto & primitive = node->mesh->primitives[debug_primitive_to_highlight.second];
|
||||
// FIXME: transform_to_root is 1 frame late
|
||||
renderer->debug_draw_box(node->transform_to_root, primitive.obb_min, primitive.obb_max, glm::vec4(1, 1, 1, 1));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Get the planes that limit the ray size from the composition layers
|
||||
std::vector<glm::vec4> ray_limits;
|
||||
for (auto & [z_index, layer]: imgui_layers)
|
||||
@@ -725,6 +761,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
|
||||
input->apply(world, world_space, frame_state.predictedDisplayTime, hide_left_controller, hide_right_controller, ray_limits);
|
||||
|
||||
renderer::animate(world, frame_state.predictedDisplayPeriod * 1.0e-9);
|
||||
|
||||
assert(renderer);
|
||||
|
||||
world.get<components::node>(lobby_entity).visible = not application::get_config().passthrough_enabled;
|
||||
@@ -740,7 +778,9 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
height,
|
||||
composition_layer_depth_test_supported,
|
||||
composition_layer_depth_test_supported ? layer_lobby | layer_controllers : layer_lobby,
|
||||
clear_color);
|
||||
clear_color,
|
||||
foveation,
|
||||
true);
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
set_depth_test(true, XR_COMPARE_OP_ALWAYS_FB);
|
||||
@@ -770,7 +810,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
height,
|
||||
composition_layer_depth_test_supported,
|
||||
composition_layer_depth_test_supported ? layer_rays : layer_rays | layer_controllers,
|
||||
{0, 0, 0, 0});
|
||||
{0, 0, 0, 0},
|
||||
foveation);
|
||||
|
||||
if (composition_layer_depth_test_supported)
|
||||
set_depth_test(true, XR_COMPARE_OP_LESS_OR_EQUAL_FB);
|
||||
@@ -782,6 +823,10 @@ void scenes::lobby::render(const XrFrameState & frame_state)
|
||||
}
|
||||
|
||||
render_end();
|
||||
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_end(*vk_instance);
|
||||
#endif
|
||||
}
|
||||
|
||||
void scenes::lobby::on_focused()
|
||||
@@ -797,15 +842,24 @@ void scenes::lobby::on_focused()
|
||||
// assert(std::ranges::all_of(views, [width](const XrViewConfigurationView & view) { return view.recommendedImageRectWidth == width; }));
|
||||
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
auto & config = application::get_config();
|
||||
|
||||
lobby_entity = load_gltf("ground.gltf", layer_lobby).first;
|
||||
try
|
||||
{
|
||||
lobby_entity = add_gltf(config.environment_model, layer_lobby).first;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Cannot load environment from {}: {}, reverting to default", config.environment_model, e.what());
|
||||
config.environment_model = configuration{}.environment_model;
|
||||
lobby_entity = add_gltf(config.environment_model, layer_lobby).first;
|
||||
config.save();
|
||||
}
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
*this,
|
||||
"controllers/" + profile + "/profile.json",
|
||||
"assets://controllers/" + profile + "/profile.json",
|
||||
layer_controllers,
|
||||
layer_rays);
|
||||
|
||||
@@ -831,8 +885,8 @@ void scenes::lobby::on_focused()
|
||||
offset_orientation = glm::degrees(glm::eulerAngles(input->offset[xr::spaces::grip_left].second));
|
||||
ray_offset = input->offset[xr::spaces::aim_left].first.z;
|
||||
|
||||
xyz_axes_left_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
xyz_axes_right_controller = load_gltf("xyz-arrows.glb", layer_controllers).first;
|
||||
xyz_axes_left_controller = add_gltf("assets://xyz-arrows.glb", layer_controllers).first;
|
||||
xyz_axes_right_controller = add_gltf("assets://xyz-arrows.glb", layer_controllers).first;
|
||||
#endif
|
||||
|
||||
recenter_left_action = get_action("recenter_left").first;
|
||||
@@ -861,8 +915,8 @@ void scenes::lobby::on_focused()
|
||||
{
|
||||
left_hand = session.create_hand_tracker(XR_HAND_LEFT_EXT);
|
||||
right_hand = session.create_hand_tracker(XR_HAND_RIGHT_EXT);
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "right-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_LEFT_EXT, "assets://left-hand.glb", layer_controllers);
|
||||
hand_model::add_hand(*this, XR_HAND_RIGHT_EXT, "assets://right-hand.glb", layer_controllers);
|
||||
imgui_inputs.push_back({.hand = &*left_hand});
|
||||
imgui_inputs.push_back({.hand = &*right_hand});
|
||||
}
|
||||
@@ -882,16 +936,16 @@ void scenes::lobby::on_focused()
|
||||
{
|
||||
// Pop up window
|
||||
.space = xr::spaces::world,
|
||||
.size = {0.6, 0.28},
|
||||
.size = {0.6, 0.4},
|
||||
.vp_origin = {1500, 0},
|
||||
.vp_size = {1500, 700},
|
||||
.vp_size = {1500, 1000},
|
||||
.z_index = constants::lobby::zindex_gui,
|
||||
},
|
||||
{
|
||||
// Virtual keyboard
|
||||
.space = xr::spaces::world,
|
||||
.size = {0.6, 0.2},
|
||||
.vp_origin = {1500, 700},
|
||||
.vp_origin = {1500, 1000},
|
||||
.vp_size = {1500, 500},
|
||||
.always_show_cursor = true,
|
||||
.z_index = constants::lobby::zindex_gui,
|
||||
@@ -907,31 +961,66 @@ void scenes::lobby::on_focused()
|
||||
.z_index = constants::lobby::zindex_recenter_tip,
|
||||
}};
|
||||
|
||||
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 3000, 1300);
|
||||
xr::swapchain swapchain_imgui(instance, session, device, swapchain_format, 3000, 1500);
|
||||
|
||||
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps);
|
||||
imgui_ctx.emplace(
|
||||
physical_device,
|
||||
device,
|
||||
queue_family_index,
|
||||
queue,
|
||||
imgui_inputs,
|
||||
std::move(swapchain_imgui),
|
||||
vps,
|
||||
image_cache);
|
||||
|
||||
auto t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||
auto tm = std::localtime(&t);
|
||||
std::string image = tm->tm_mon == 5 ? "wivrn-pride" : "wivrn";
|
||||
try
|
||||
{
|
||||
about_picture = imgui_ctx->load_texture(image + ".ktx2");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
about_picture = imgui_ctx->load_texture(image + ".png");
|
||||
}
|
||||
|
||||
about_picture = imgui_ctx->load_texture("assets://" + image + ".ktx2");
|
||||
|
||||
default_environment_screenshot = imgui_ctx->load_texture("assets://default-environment.ktx2");
|
||||
|
||||
try
|
||||
{
|
||||
default_icon = imgui_ctx->load_texture("default_icon.ktx2");
|
||||
local_environments = load_environment_json(utils::read_whole_file<std::string>(application::get_config_path() / "environments.json"));
|
||||
|
||||
// Remove environments if the model file is deleted
|
||||
std::erase_if(local_environments, [&](const environment_model & model) {
|
||||
std::filesystem::path path = model.local_gltf_path;
|
||||
return not std::filesystem::exists(path);
|
||||
});
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
default_icon = imgui_ctx->load_texture("default_icon.png");
|
||||
}
|
||||
|
||||
local_environments.push_back(
|
||||
environment_model{
|
||||
.name = gettext_noop("Passthrough"),
|
||||
.author = "",
|
||||
.description = "",
|
||||
.screenshot_url = "",
|
||||
.gltf_url = "passthrough", // This needs to be unique because it is used as a key, even if there is no actual URL
|
||||
.builtin = true,
|
||||
.override_order = -2,
|
||||
.local_gltf_path = "",
|
||||
.screenshot = imgui_ctx->load_texture("assets://passthrough.ktx2")});
|
||||
|
||||
local_environments.push_back(
|
||||
environment_model{
|
||||
.name = gettext_noop("Default environment"),
|
||||
.author = "",
|
||||
.description = "",
|
||||
.screenshot_url = "",
|
||||
.gltf_url = "default",
|
||||
.builtin = true,
|
||||
.override_order = -1,
|
||||
.local_gltf_path = configuration{}.environment_model,
|
||||
.screenshot = imgui_ctx->load_texture("assets://default-environment.ktx2")});
|
||||
|
||||
std::ranges::sort(local_environments, std::less{});
|
||||
|
||||
setup_passthrough();
|
||||
session.set_refresh_rate(application::get_config().preferred_refresh_rate.value_or(0));
|
||||
multicast = application::get_wifi_lock().get_multicast_lock();
|
||||
@@ -952,20 +1041,18 @@ void scenes::lobby::on_unfocused()
|
||||
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
|
||||
|
||||
about_picture = 0;
|
||||
default_icon = 0;
|
||||
app_icons.clear();
|
||||
default_environment_screenshot = 0;
|
||||
local_environments.clear();
|
||||
|
||||
imgui_ctx.reset();
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
world = entt::registry{};
|
||||
|
||||
input.reset();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
face_tracker.emplace<std::monostate>();
|
||||
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
multicast.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,21 +19,25 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "asset.h"
|
||||
#include "configuration.h"
|
||||
#include "crypto.h"
|
||||
#include "file_picker.h"
|
||||
#include "libcurl.h"
|
||||
#include "scene.h"
|
||||
#include "scenes/lobby_keyboard.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include "utils/thread_safe.h"
|
||||
#include "wifi_lock.h"
|
||||
#include "wivrn_config.h"
|
||||
#include "wivrn_discover.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "xr/face_tracker.h"
|
||||
#include "xr/foveation_profile.h"
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <openxr/openxr.h>
|
||||
|
||||
#include <compare>
|
||||
#include <optional>
|
||||
#include <uni_algo/case.h>
|
||||
#include <vector>
|
||||
|
||||
#include "input_profile.h"
|
||||
@@ -65,6 +69,9 @@ class lobby : public scene_impl<lobby>
|
||||
std::optional<input_profile> input;
|
||||
entt::entity lobby_entity;
|
||||
|
||||
file_picker lobby_file_picker;
|
||||
std::future<file_picker_result> lobby_file_picker_future;
|
||||
|
||||
std::optional<imgui_context> imgui_ctx;
|
||||
|
||||
std::optional<xr::hand_tracker> left_hand;
|
||||
@@ -72,8 +79,10 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
xr::face_tracker face_tracker;
|
||||
|
||||
std::optional<xr::foveation_profile> foveation;
|
||||
|
||||
std::string selected_item;
|
||||
std::unique_ptr<asset> license;
|
||||
std::unique_ptr<utils::mapped_file> license;
|
||||
|
||||
static inline const uint32_t layer_lobby = 1 << 0;
|
||||
static inline const uint32_t layer_controllers = 1 << 1;
|
||||
@@ -81,7 +90,6 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
xr::swapchain swapchain_imgui;
|
||||
XrViewConfigurationView stream_view;
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
@@ -101,8 +109,7 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
XrAction recenter_left_action = XR_NULL_HANDLE;
|
||||
XrAction recenter_right_action = XR_NULL_HANDLE;
|
||||
// std::optional<glm::vec3> gui_recenter_position;
|
||||
// std::optional<float> gui_recenter_distance;
|
||||
|
||||
// Which controller is used for recentering, position of the pointed point in the GUI, in GUI axes, and distance between the controller and the pointed point during recentering
|
||||
std::optional<std::tuple<xr::spaces, glm::vec3, float>> recentering_context;
|
||||
bool recenter_gui = true;
|
||||
@@ -114,6 +121,7 @@ class lobby : public scene_impl<lobby>
|
||||
server_list,
|
||||
settings,
|
||||
post_processing,
|
||||
customize,
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
debug,
|
||||
#endif
|
||||
@@ -127,9 +135,6 @@ class lobby : public scene_impl<lobby>
|
||||
tab last_current_tab = tab::server_list;
|
||||
int optional_feature_index = 0; // Which step of the first run screen are we in
|
||||
ImTextureID about_picture;
|
||||
ImTextureID default_icon;
|
||||
std::unordered_map<std::string, ImTextureID> app_icons;
|
||||
std::optional<XrTime> timestamp_start_application;
|
||||
|
||||
virtual_keyboard keyboard;
|
||||
|
||||
@@ -143,6 +148,75 @@ class lobby : public scene_impl<lobby>
|
||||
thread_safe_notifyable<pin_request_data> pin_request;
|
||||
std::string pin_buffer;
|
||||
|
||||
struct environment_model
|
||||
{
|
||||
// Data from the JSON
|
||||
std::string name;
|
||||
std::string author;
|
||||
std::string description;
|
||||
std::string screenshot_url;
|
||||
std::string gltf_url;
|
||||
size_t size{};
|
||||
|
||||
bool builtin = false;
|
||||
int override_order = 0;
|
||||
std::filesystem::path local_screenshot_path;
|
||||
std::filesystem::path local_gltf_path;
|
||||
std::vector<std::byte> screenshot_png;
|
||||
ImTextureID screenshot{};
|
||||
|
||||
std::strong_ordering operator<=>(const environment_model & other) const
|
||||
{
|
||||
// Reverse order for the builtin member: we want the built-in models first
|
||||
if (auto cmp = override_order <=> other.override_order; cmp != std::strong_ordering::equal)
|
||||
return cmp;
|
||||
|
||||
return una::casesens::collate_utf8(name, other.name) <=> 0;
|
||||
}
|
||||
};
|
||||
|
||||
ImTextureID default_environment_screenshot;
|
||||
std::vector<environment_model> downloadable_environments;
|
||||
std::vector<environment_model> local_environments;
|
||||
environment_model * environment_to_be_deleted = nullptr;
|
||||
|
||||
libcurl curl; // needs to be before current_transfers
|
||||
std::map<std::string, std::pair<libcurl::curl_handle, std::function<void(libcurl::curl_handle & handle)>>> current_transfers;
|
||||
|
||||
void update_file_picker();
|
||||
void update_transfers();
|
||||
void download(const std::string & url, const std::filesystem::path & path, std::function<void(libcurl::curl_handle & handle)> = {});
|
||||
void download(const std::string & url, std::function<void(libcurl::curl_handle & handle)> = {});
|
||||
libcurl::curl_handle * try_get_download_handle(const std::string & url);
|
||||
|
||||
std::string downloadable_environment_list_status;
|
||||
|
||||
std::vector<environment_model> load_environment_json(const std::string & json, std::string_view base_url = "");
|
||||
void save_environment_json();
|
||||
void download_environment(const environment_model & model, bool use_after_downloading);
|
||||
void delete_environment(const environment_model & model);
|
||||
enum class environment_item_action
|
||||
{
|
||||
none,
|
||||
delete_model,
|
||||
download_model,
|
||||
use_model,
|
||||
};
|
||||
environment_item_action environment_item(environment_model & model, bool download_screenshot);
|
||||
void environment_list(std::vector<environment_model> & model, bool download_screenshot);
|
||||
void use_environment(const environment_model & model);
|
||||
XrTime popup_load_environment_display_time = 0;
|
||||
void popup_load_environment(XrTime predicted_display_time);
|
||||
utils::future<std::pair<std::string, std::shared_ptr<entt::registry>>, float> future_environment;
|
||||
std::string load_environment_status;
|
||||
|
||||
void download_environment_list();
|
||||
libcurl::curl_handle * parse_environment_list();
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
std::pair<entt::entity, int> debug_primitive_to_highlight = {entt::null, 0};
|
||||
#endif
|
||||
|
||||
void draw_features_status(XrTime predicted_display_time);
|
||||
void gui_connecting(locked_notifiable<pin_request_data> & request);
|
||||
void gui_enter_pin(locked_notifiable<pin_request_data> & request);
|
||||
@@ -151,6 +225,8 @@ class lobby : public scene_impl<lobby>
|
||||
void gui_new_server();
|
||||
void gui_settings();
|
||||
void gui_post_processing();
|
||||
void gui_customize(XrTime predicted_display_time);
|
||||
void gui_debug_node_hierarchy(entt::entity root = entt::null);
|
||||
void gui_debug();
|
||||
void gui_about();
|
||||
void gui_licenses();
|
||||
|
||||
@@ -17,21 +17,20 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <uni_algo/case.h>
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include "android/battery.h"
|
||||
#endif
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
#include "configuration.h"
|
||||
#include "constants.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "lobby.h"
|
||||
#include "stream.h"
|
||||
#include "scenes/stream.h" // IWYU pragma: keep
|
||||
#include "utils/async.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/mapped_file.h"
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "version.h"
|
||||
@@ -39,112 +38,28 @@
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <chrono>
|
||||
#include <entt/entity/fwd.hpp>
|
||||
#include <fastgltf/math.hpp>
|
||||
#include <fastgltf/types.hpp>
|
||||
#include <filesystem>
|
||||
#include <glm/geometric.hpp>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <imspinner.h>
|
||||
#include <magic_enum.hpp>
|
||||
#include <memory>
|
||||
#include <ranges>
|
||||
#include <spdlog/fmt/fmt.h>
|
||||
#include <string>
|
||||
#include <uni_algo/case.h>
|
||||
#include <utility>
|
||||
#include <utils/strings.h>
|
||||
#include <vulkan/vulkan_to_string.hpp>
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
// https://github.com/ocornut/imgui/issues/3379#issuecomment-2943903877
|
||||
static void ScrollWhenDragging()
|
||||
{
|
||||
ImVec2 delta{0.0f, -ImGui::GetIO().MouseDelta.y};
|
||||
const ImGuiMouseButton mouse_button = ImGuiMouseButton_Left;
|
||||
|
||||
ImGuiContext & g = *ImGui::GetCurrentContext();
|
||||
ImGuiWindow * window = g.CurrentWindow;
|
||||
ImGuiID id = window->GetID("##scrolldraggingoverlay");
|
||||
ImGui::KeepAliveID(id);
|
||||
|
||||
static int active_id;
|
||||
static ImVec2 cumulated_delta;
|
||||
|
||||
bool HoveredIdAllowOverlap_backup = std::exchange(g.HoveredIdAllowOverlap, true);
|
||||
bool ActiveIdAllowOverlap_backup = std::exchange(g.ActiveIdAllowOverlap, true);
|
||||
if (active_id == 0 and ImGui::ItemHoverable(window->Rect(), 0, g.CurrentItemFlags) and ImGui::IsMouseClicked(mouse_button, ImGuiInputFlags_None, /*id*/ ImGuiKeyOwner_Any))
|
||||
{
|
||||
active_id = id;
|
||||
|
||||
// Don't scroll on the first step, in case the active controller just changed
|
||||
delta = {};
|
||||
cumulated_delta = {};
|
||||
}
|
||||
|
||||
if (not g.IO.MouseDown[mouse_button])
|
||||
active_id = 0;
|
||||
|
||||
if (active_id == id)
|
||||
{
|
||||
if (delta.x != 0.0f)
|
||||
ImGui::SetScrollX(window, window->Scroll.x + delta.x);
|
||||
if (delta.y != 0.0f)
|
||||
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
|
||||
|
||||
cumulated_delta += delta;
|
||||
if (std::max(std::abs(cumulated_delta.x), std::abs(cumulated_delta.y)) > 50)
|
||||
ImGui::ClearActiveID();
|
||||
}
|
||||
|
||||
g.HoveredIdAllowOverlap = HoveredIdAllowOverlap_backup;
|
||||
g.ActiveIdAllowOverlap = ActiveIdAllowOverlap_backup;
|
||||
}
|
||||
|
||||
static void CenterTextH(const std::string & text)
|
||||
{
|
||||
float win_width = ImGui::GetWindowSize().x;
|
||||
float text_width = ImGui::CalcTextSize(text.c_str()).x;
|
||||
ImGui::SetCursorPosX((win_width - text_width) / 2);
|
||||
|
||||
ImGui::Text("%s", text.c_str());
|
||||
}
|
||||
|
||||
static void CenterTextHV(const std::string & text)
|
||||
{
|
||||
ImVec2 size = ImGui::GetWindowSize();
|
||||
|
||||
std::vector<std::string> lines = utils::split(text);
|
||||
|
||||
float text_height = 0;
|
||||
for (const auto & i: lines)
|
||||
text_height += ImGui::CalcTextSize(i.c_str()).y;
|
||||
|
||||
ImGui::SetCursorPosY((size.y - text_height) / 2);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {0, 0});
|
||||
for (const auto & i: lines)
|
||||
{
|
||||
float text_width = ImGui::CalcTextSize(i.c_str()).x;
|
||||
ImGui::SetCursorPosX((size.x - text_width) / 2);
|
||||
ImGui::Text("%s", i.c_str());
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
|
||||
static void InputText(const char * label, std::string & text, const ImVec2 & size, ImGuiInputTextFlags flags)
|
||||
{
|
||||
auto callback = [](ImGuiInputTextCallbackData * data) -> int {
|
||||
std::string & text = *reinterpret_cast<std::string *>(data->UserData);
|
||||
|
||||
if (data->EventFlag == ImGuiInputTextFlags_CallbackResize)
|
||||
{
|
||||
assert(text.data() == data->Buf);
|
||||
text.resize(data->BufTextLen);
|
||||
data->Buf = text.data();
|
||||
}
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
ImGui::InputTextEx(label, nullptr, text.data(), text.size() + 1, size, flags | ImGuiInputTextFlags_CallbackResize, callback, &text);
|
||||
}
|
||||
|
||||
static void display_recentering_tip(imgui_context & ctx, const std::string & tip)
|
||||
{
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
@@ -175,54 +90,6 @@ static void display_recentering_tip(imgui_context & ctx, const std::string & tip
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
// Display a button with an image and a text centred horizontally
|
||||
static bool icon(const std::string & text, ImTextureRef tex_ref, const ImVec2 & image_size, ImGuiButtonFlags flags = 0, const ImVec2 & size_arg = ImVec2(0, 0), const ImVec2 & uv0 = ImVec2(0, 0), const ImVec2 & uv1 = ImVec2(1, 1), const ImVec4 & tint_col = ImVec4(1, 1, 1, 1))
|
||||
{
|
||||
// Based on ImGui::ButtonEx and ImGui::ImageButtonEx
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(text.c_str(), nullptr, true);
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(
|
||||
size_arg,
|
||||
std::max(image_size.x, label_size.x) + style.FramePadding.x * 2.0f,
|
||||
image_size.y + style.ItemInnerSpacing.y + label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
|
||||
|
||||
ImRect image_pos(
|
||||
{(bb.Min.x + bb.Max.x - image_size.x) / 2, bb.Min.y + style.FramePadding.y},
|
||||
{(bb.Min.x + bb.Max.x + image_size.x) / 2, bb.Min.y + style.FramePadding.y + image_size.y});
|
||||
|
||||
ImRect label_pos(
|
||||
{bb.Min.x + style.FramePadding.x, image_pos.Max.y + style.ItemInnerSpacing.y},
|
||||
{bb.Max.x - style.FramePadding.x, bb.Max.y - style.FramePadding.y});
|
||||
|
||||
ImGui::ItemSize(bb);
|
||||
|
||||
ImGuiID id = window->GetID(text.c_str());
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held, flags);
|
||||
|
||||
// Render
|
||||
const ImU32 col = ImGui::GetColorU32((held && hovered) ? ImGuiCol_ButtonActive : hovered ? ImGuiCol_ButtonHovered
|
||||
: ImGuiCol_Button);
|
||||
ImGui::RenderNavCursor(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, col, true, style.FrameRounding);
|
||||
|
||||
window->DrawList->AddImage(tex_ref, image_pos.Min, image_pos.Max, uv0, uv1, ImGui::GetColorU32(tint_col));
|
||||
ImGui::RenderTextClipped(label_pos.Min, label_pos.Max, text.c_str(), NULL, &label_size, style.ButtonTextAlign, &bb);
|
||||
|
||||
return pressed;
|
||||
}
|
||||
|
||||
std::string openxr_post_processing_flag_name(XrCompositionLayerSettingsFlagsFB flag)
|
||||
{
|
||||
switch (flag)
|
||||
@@ -248,7 +115,6 @@ void scenes::lobby::gui_connecting(locked_notifiable<pin_request_data> & pin_req
|
||||
if (next_scene)
|
||||
{
|
||||
current_tab = tab::connected;
|
||||
timestamp_start_application.reset();
|
||||
ImGui::CloseCurrentPopup();
|
||||
return;
|
||||
}
|
||||
@@ -384,144 +250,14 @@ void scenes::lobby::gui_connected(XrTime predicted_display_time)
|
||||
if (not next_scene)
|
||||
{
|
||||
current_tab = tab::server_list;
|
||||
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
imgui_ctx->free_texture(app_icon);
|
||||
app_icons.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
if (server_name.empty())
|
||||
CenterTextH(_("Connected to WiVRn server"));
|
||||
else
|
||||
CenterTextH(fmt::format(_F("Connected to {}"), server_name));
|
||||
ImGui::PopFont();
|
||||
|
||||
auto disconnect = _("Disconnect");
|
||||
auto disconnect_size = ImGui::CalcTextSize(disconnect.c_str());
|
||||
|
||||
auto apps = next_scene->get_applications();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
if (apps->empty())
|
||||
{
|
||||
CenterTextHV(_("Start an application on the server to start streaming."));
|
||||
}
|
||||
else
|
||||
{
|
||||
bool app_starting = timestamp_start_application and (predicted_display_time - *timestamp_start_application < 10'000'000'000);
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {20, 0});
|
||||
ImGui::BeginDisabled(app_starting);
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, disconnect_size.y + 80), 0, app_starting ? ImGuiWindowFlags_NoScrollWithMouse : 0);
|
||||
|
||||
ImGui::Indent(20);
|
||||
if (server_name.empty())
|
||||
ImGui::Text("%s", _S("Start an application on your computer or select one to start streaming."));
|
||||
else
|
||||
ImGui::Text("%s", fmt::format(_F("Start an application on {} or select one to start streaming."), server_name).c_str());
|
||||
ImGui::Unindent();
|
||||
|
||||
float icon_width = 400;
|
||||
float icon_spacing = ImGui::GetStyle().ItemSpacing.x;
|
||||
float usable_window_width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x;
|
||||
|
||||
int icons_per_line = (usable_window_width + icon_spacing) / (icon_width + icon_spacing);
|
||||
float icon_line_width = icons_per_line * icon_width + (icons_per_line - 1) * icon_spacing;
|
||||
|
||||
ImGui::Indent((usable_window_width - icon_line_width) / 2);
|
||||
|
||||
auto t0 = std::chrono::steady_clock::now();
|
||||
for (const auto [index, app]: utils::enumerate(*apps))
|
||||
{
|
||||
ImTextureID texture = [&]() -> ImTextureID {
|
||||
if (app.image.empty())
|
||||
return default_icon;
|
||||
else
|
||||
{
|
||||
auto it = app_icons.find(app.id);
|
||||
if (it == app_icons.end())
|
||||
{
|
||||
// Don't load too many textures at the same time to keep the GUI responsive
|
||||
if (std::chrono::steady_clock::now() - t0 > 10ms)
|
||||
return default_icon;
|
||||
|
||||
try
|
||||
{
|
||||
it = app_icons.emplace(app.id, imgui_ctx->load_texture(app.image)).first;
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Unable to load icon for \"{}\": {}", app.id, e.what());
|
||||
|
||||
app.image.clear();
|
||||
return default_icon;
|
||||
}
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
}();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
if (icon(app.name + "##" + app.id, texture, {256, 256}, ImGuiButtonFlags_PressedOnClickRelease, {icon_width, 0}))
|
||||
{
|
||||
timestamp_start_application = predicted_display_time;
|
||||
next_scene->start_application(app.id);
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
|
||||
if (index % 3 != 2)
|
||||
ImGui::SameLine();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
|
||||
std::vector<std::pair<std::string, ImTextureID>> to_be_removed;
|
||||
for (const auto & [app_id, app_icon]: app_icons)
|
||||
{
|
||||
if (not std::ranges::contains(*apps, app_id, &scenes::stream::app::id))
|
||||
to_be_removed.emplace_back(app_id, app_icon);
|
||||
}
|
||||
for (const auto & [app_id, app_icon]: to_be_removed)
|
||||
{
|
||||
imgui_ctx->free_texture(app_icon);
|
||||
app_icons.erase(app_id);
|
||||
}
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::EndDisabled();
|
||||
|
||||
if (app_starting)
|
||||
{
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||
ImSpinner::SpinnerAng("App starting spinner",
|
||||
200, // Radius
|
||||
40, // Thickness
|
||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||
6, // Velocity
|
||||
0.75f * 2 * M_PI // Angle
|
||||
);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_WindowPadding
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - disconnect_size - ImVec2{50, 50});
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(disconnect.c_str()))
|
||||
if (next_scene->apps.draw_gui(*imgui_ctx, _("Disconnect")) == app_launcher::Cancel)
|
||||
{
|
||||
next_scene.reset();
|
||||
current_tab = tab::server_list;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_new_server()
|
||||
@@ -534,43 +270,43 @@ void scenes::lobby::gui_new_server()
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::Dummy({1000, 1});
|
||||
|
||||
ImGui::BeginTable("table", 2);
|
||||
if (ImGui::BeginTable("table", 2))
|
||||
{
|
||||
ImGui::TableSetupColumn("Field name", ImGuiTableColumnFlags_WidthFixed);
|
||||
ImGui::TableSetupColumn("Field value", ImGuiTableColumnFlags_WidthStretch);
|
||||
|
||||
ImGui::TableSetupColumn("Field name", ImGuiTableColumnFlags_WidthFixed);
|
||||
ImGui::TableSetupColumn("Field value", ImGuiTableColumnFlags_WidthStretch);
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
// Make sure the label is vertically centered wrt the text input
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Name"));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
// Make sure the label is vertically centered wrt the text input
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Name"));
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::IsWindowAppearing())
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
InputText("##Name", add_server_window_prettyname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::IsWindowAppearing())
|
||||
ImGui::SetKeyboardFocusHere();
|
||||
InputText("##Name", add_server_window_prettyname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Address"));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Address"));
|
||||
ImGui::TableNextColumn();
|
||||
InputText("##Hostname", add_server_window_hostname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
InputText("##Hostname", add_server_window_hostname, {ImGui::GetContentRegionAvail().x, 0}, 0);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Port"));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + ImGui::GetStyle().FramePadding.y);
|
||||
ImGui::Text("%s", _S("Port"));
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::InputInt("##Port", &add_server_window_port, 1, 1, ImGuiInputTextFlags_CharsDecimal);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::EndTable();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::InputInt("##Port", &add_server_window_port, 1, 1, ImGuiInputTextFlags_CharsDecimal);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Checkbox(_S("TCP only"), &add_server_tcp_only);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
@@ -881,6 +617,31 @@ void scenes::lobby::gui_settings()
|
||||
}
|
||||
}
|
||||
|
||||
if (foveation)
|
||||
{
|
||||
std::array<const char *, 4> foveation_levels = {
|
||||
gettext_noop_context("Foveation level", "None"),
|
||||
gettext_noop_context("Foveation level", "Low"),
|
||||
gettext_noop_context("Foveation level", "Medium"),
|
||||
gettext_noop_context("Foveation level", "High"),
|
||||
};
|
||||
|
||||
if (ImGui::BeginCombo(_S("Foveation level"), _cS("Foveation level", foveation_levels[(int)foveation->level()])))
|
||||
{
|
||||
for (int level = 0; level < foveation_levels.size(); level++)
|
||||
{
|
||||
if (ImGui::Selectable(_cS("Foveation level", foveation_levels[level]), (int)foveation->level() == level))
|
||||
{
|
||||
foveation = xr::foveation_profile{instance, session, (XrFoveationLevelFB)level, -10, false};
|
||||
// TODO save in configuration
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
{
|
||||
const auto current = config.resolution_scale;
|
||||
const auto width = stream_view.recommendedImageRectWidth;
|
||||
@@ -1014,17 +775,6 @@ void scenes::lobby::gui_settings()
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
ImGui::BeginDisabled(system.passthrough_supported() == xr::passthrough_type::none);
|
||||
if (ImGui::Checkbox(_S("Enable video passthrough in lobby"), &config.passthrough_enabled))
|
||||
{
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
imgui_ctx->tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
|
||||
{
|
||||
ImGui::Checkbox(_S("Enable in-stream window"), &config.enable_stream_gui);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
@@ -1102,120 +852,229 @@ void scenes::lobby::gui_post_processing()
|
||||
}
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
void scenes::lobby::gui_debug_node_hierarchy(entt::entity root)
|
||||
{
|
||||
for (auto && [entity, node]: world.view<components::node>().each())
|
||||
{
|
||||
if (node.parent != root)
|
||||
continue;
|
||||
|
||||
std::string id = "entity-" + std::to_string((int)entity);
|
||||
const std::string & name = node.name == "" ? id : node.name;
|
||||
|
||||
// See ImGui::StyleColorsDark
|
||||
if (node.global_visible)
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.00f, 1.00f, 1.00f, 1.00f));
|
||||
else
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.50f, 0.50f, 0.50f, 1.00f));
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::TreeNodeEx(id.c_str(), ImGuiTreeNodeFlags_None, "%s", name.c_str()))
|
||||
{
|
||||
glm::vec3 scale{
|
||||
glm::length(glm::column(node.transform_to_root, 0)),
|
||||
glm::length(glm::column(node.transform_to_root, 1)),
|
||||
glm::length(glm::column(node.transform_to_root, 2)),
|
||||
};
|
||||
|
||||
gui_debug_node_hierarchy(entity);
|
||||
|
||||
if (node.mesh)
|
||||
for (auto [index, primitive]: utils::enumerate(node.mesh->primitives))
|
||||
{
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
std::string name = "Primitive " + std::to_string(index + 1);
|
||||
|
||||
ImGuiTreeNodeFlags flags = ImGuiTreeNodeFlags_Leaf;
|
||||
if (debug_primitive_to_highlight == std::pair{entity, index})
|
||||
flags |= ImGuiTreeNodeFlags_Selected;
|
||||
|
||||
if (ImGui::TreeNodeEx(name.c_str(), flags))
|
||||
{
|
||||
if (ImGui::IsItemClicked())
|
||||
debug_primitive_to_highlight = {entity, index};
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
std::string tooltip = fmt::format(
|
||||
"Name: {}\n"
|
||||
"Topology: {}\n"
|
||||
"Vertices: {}\n"
|
||||
"Material: {}\n"
|
||||
"vertex shader: {}\n"
|
||||
"Fragment shader: {}\n",
|
||||
name,
|
||||
vk::to_string(primitive.topology),
|
||||
primitive.vertex_count,
|
||||
primitive.material_->name,
|
||||
primitive.vertex_shader,
|
||||
primitive.material_->fragment_shader_name);
|
||||
|
||||
imgui_ctx->tooltip(tooltip);
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
glm::vec3 size = scale * (primitive.obb_max - primitive.obb_min);
|
||||
ImGui::Text("%s", fmt::format("{} vertices, {:.3f} x {:.3f} x {:.3f} m", primitive.vertex_count, size.x, size.y, size.z).c_str());
|
||||
}
|
||||
|
||||
ImGui::TreePop();
|
||||
}
|
||||
ImGui::TableNextRow();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Text
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_debug()
|
||||
{
|
||||
ImGui::GetIO().ConfigDragClickToInputText = true;
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(20, 20));
|
||||
|
||||
ImGui::Checkbox("Display debug axes", &display_debug_axes);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (display_debug_axes)
|
||||
if (ImGui::CollapsingHeader("Tune controller offset"))
|
||||
{
|
||||
ImGui::Checkbox("Display grip instead of aim", &display_grip_instead_of_aim);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::Checkbox("Display debug axes", &display_debug_axes);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (display_debug_axes)
|
||||
{
|
||||
ImGui::Checkbox("Display grip instead of aim", &display_grip_instead_of_aim);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset x", &offset_position.x, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset y", &offset_position.y, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Position", &offset_position.z, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##position"))
|
||||
offset_position = {0, 0, 0};
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset roll", &offset_orientation.x, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset pitch", &offset_orientation.y, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Rotation", &offset_orientation.z, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##orientation"))
|
||||
offset_orientation = {0, 0, 0};
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Ray offset", &ray_offset, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset x", &offset_position.x, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset y", &offset_position.y, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Position", &offset_position.z, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##position"))
|
||||
offset_position = {0, 0, 0};
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset roll", &offset_orientation.x, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("##offset pitch", &offset_orientation.y, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Rotation", &offset_orientation.z, 0.01);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button("Reset##orientation"))
|
||||
offset_orientation = {0, 0, 0};
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SetNextItemWidth(140);
|
||||
ImGui::DragFloat("Ray offset", &ray_offset, 0.0001);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
else
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
if (ImGui::Button("Delete configuration file"))
|
||||
std::filesystem::remove(application::get_config_path() / "client.json");
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
float win_width = ImGui::GetWindowSize().x;
|
||||
float win_height = ImGui::GetWindowSize().y;
|
||||
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
ImVec2 plot_size{
|
||||
win_width / 2 - style.ItemSpacing.x / 2,
|
||||
win_height / 2};
|
||||
|
||||
static std::array<float, 300> cpu_time;
|
||||
static std::array<float, 300> gpu_time;
|
||||
static int offset = 0;
|
||||
|
||||
float min_v = 0;
|
||||
float max_v = 20;
|
||||
|
||||
cpu_time[offset] = application::get_cpu_time().count() * 1.0e-6;
|
||||
gpu_time[offset] = renderer->get_gpu_time() * 1'000;
|
||||
offset = (offset + 1) % cpu_time.size();
|
||||
|
||||
ImPlot::PushStyleColor(ImPlotCol_PlotBg, IM_COL32(32, 32, 32, 64));
|
||||
ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBg, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgActive, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
|
||||
|
||||
if (ImPlot::BeginPlot(_S("CPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
if (ImGui::CollapsingHeader("CPU / GPU stats"))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(0);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
float win_width = ImGui::GetWindowSize().x;
|
||||
float win_height = ImGui::GetWindowSize().y;
|
||||
|
||||
ImPlot::SetupAxes(nullptr, _S("CPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
|
||||
ImPlot::SetupAxesLimits(0, cpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
|
||||
ImPlot::SetNextLineStyle(col);
|
||||
ImPlot::SetNextFillStyle(col, 0.25);
|
||||
ImPlot::PlotLine(_S("CPU time"), cpu_time.data(), cpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
|
||||
ImPlot::EndPlot();
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
ImVec2 plot_size{
|
||||
win_width / 2 - style.ItemSpacing.x / 2,
|
||||
win_height / 2};
|
||||
|
||||
static std::array<float, 300> cpu_time;
|
||||
static std::array<float, 300> gpu_time;
|
||||
static int offset = 0;
|
||||
|
||||
float min_v = 0;
|
||||
float max_v = 20;
|
||||
|
||||
cpu_time[offset] = application::get_cpu_time().count() * 1.0e-6;
|
||||
gpu_time[offset] = renderer->get_gpu_time() * 1'000;
|
||||
offset = (offset + 1) % cpu_time.size();
|
||||
|
||||
ImPlot::PushStyleColor(ImPlotCol_PlotBg, IM_COL32(32, 32, 32, 64));
|
||||
ImPlot::PushStyleColor(ImPlotCol_FrameBg, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBg, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgActive, IM_COL32(0, 0, 0, 0));
|
||||
ImPlot::PushStyleColor(ImPlotCol_AxisBgHovered, IM_COL32(0, 0, 0, 0));
|
||||
|
||||
if (ImPlot::BeginPlot(_S("CPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(0);
|
||||
|
||||
ImPlot::SetupAxes(nullptr, _S("CPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
|
||||
ImPlot::SetupAxesLimits(0, cpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
|
||||
ImPlot::SetNextLineStyle(col);
|
||||
ImPlot::SetNextFillStyle(col, 0.25);
|
||||
ImPlot::PlotLine(_S("CPU time"), cpu_time.data(), cpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImPlot::BeginPlot(_S("GPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(1);
|
||||
|
||||
ImPlot::SetupAxes(nullptr, _S("GPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
|
||||
ImPlot::SetupAxesLimits(0, gpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
|
||||
ImPlot::SetNextLineStyle(col);
|
||||
ImPlot::SetNextFillStyle(col, 0.25);
|
||||
ImPlot::PlotLine(_S("GPU time"), gpu_time.data(), gpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
ImPlot::PopStyleColor(5);
|
||||
}
|
||||
else
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
|
||||
if (ImPlot::BeginPlot(_S("GPU time"), plot_size, ImPlotFlags_CanvasOnly))
|
||||
if (ImGui::CollapsingHeader("Renderer stats"))
|
||||
{
|
||||
auto col = ImPlot::GetColormapColor(1);
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImPlot::SetupAxes(nullptr, _S("GPU time [ms]"), ImPlotAxisFlags_NoDecorations, 0);
|
||||
ImPlot::SetupAxesLimits(0, gpu_time.size() - 1, min_v, max_v, ImGuiCond_Always);
|
||||
ImPlot::SetNextLineStyle(col);
|
||||
ImPlot::SetNextFillStyle(col, 0.25);
|
||||
ImPlot::PlotLine(_S("GPU time"), gpu_time.data(), gpu_time.size(), 1, 0, ImPlotLineFlags_Shaded, offset);
|
||||
ImPlot::EndPlot();
|
||||
const auto & stats = renderer->last_frame_stats();
|
||||
|
||||
ImGui::Text("Primitives: %zd total, %zd culled", stats.count_primitives, stats.count_culled_primitives);
|
||||
ImGui::Text("Triangles: %zd total, %zd culled", stats.count_triangles, stats.count_culled_triangles);
|
||||
|
||||
if (ImGui::BeginTable("Node hierarchy", 2, ImGuiTableFlags_None))
|
||||
{
|
||||
gui_debug_node_hierarchy();
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
ImPlot::PopStyleColor(5);
|
||||
else
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_ItemSpacing
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1331,7 +1190,7 @@ void scenes::lobby::gui_licenses()
|
||||
selected_item = *components.begin();
|
||||
try
|
||||
{
|
||||
license = std::make_unique<asset>(std::filesystem::path("licenses") / selected_item);
|
||||
license = std::make_unique<utils::mapped_file>(std::filesystem::path("assets://licenses") / selected_item);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -1344,7 +1203,7 @@ void scenes::lobby::gui_licenses()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto current = std::make_unique<asset>(std::filesystem::path("licenses") / component);
|
||||
auto current = std::make_unique<utils::mapped_file>(std::filesystem::path("assets://licenses") / component);
|
||||
if (ImGui::Selectable(component, component == selected_item, ImGuiSelectableFlags_SelectOnRelease))
|
||||
{
|
||||
selected_item = component;
|
||||
@@ -1363,56 +1222,6 @@ void scenes::lobby::gui_licenses()
|
||||
ImGui::TextUnformatted((const char *)license->data(), (const char *)license->data() + license->size());
|
||||
}
|
||||
|
||||
static bool RadioButtonWithoutCheckBox(const std::string & label, bool active, ImVec2 size_arg)
|
||||
{
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext & g = *GImGui;
|
||||
const ImGuiStyle & style = g.Style;
|
||||
const ImGuiID id = window->GetID(label.c_str());
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(label.c_str(), NULL, true);
|
||||
|
||||
const ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ImGui::ItemSize(bb, style.FramePadding.y);
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
ImGuiCol_ col;
|
||||
if ((held && hovered) || active)
|
||||
col = ImGuiCol_ButtonActive;
|
||||
else if (hovered)
|
||||
col = ImGuiCol_ButtonHovered;
|
||||
else
|
||||
col = ImGuiCol_Button;
|
||||
|
||||
ImGui::RenderNavHighlight(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
|
||||
|
||||
ImVec2 TextAlign{0, 0.5f};
|
||||
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label.c_str(), NULL, &label_size, TextAlign, &bb);
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label.c_str(), g.LastItemData.StatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static bool RadioButtonWithoutCheckBox(const std::string & label, T * v, T v_button, ImVec2 size_arg)
|
||||
{
|
||||
const bool pressed = RadioButtonWithoutCheckBox(label, *v == v_button, size_arg);
|
||||
if (pressed)
|
||||
*v = v_button;
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static auto face_weights()
|
||||
{
|
||||
using weights = decltype(wivrn::from_headset::tracking::fb_face2{}.weights);
|
||||
@@ -1840,9 +1649,46 @@ static bool is_gui_visible(imgui_context & ctx, XrTime predicted_display_time)
|
||||
return true;
|
||||
}
|
||||
|
||||
void scenes::lobby::update_transfers()
|
||||
{
|
||||
for (auto & [name, transfer]: current_transfers)
|
||||
{
|
||||
transfer.first.sync();
|
||||
if (transfer.first.get_state() == libcurl::state::done and transfer.second)
|
||||
transfer.second(transfer.first);
|
||||
}
|
||||
|
||||
std::erase_if(current_transfers, [](auto & x) {
|
||||
auto state = x.second.first.get_state();
|
||||
return state == libcurl::state::done or state == libcurl::state::reset;
|
||||
});
|
||||
}
|
||||
|
||||
void scenes::lobby::download(const std::string & url, const std::filesystem::path & path, std::function<void(libcurl::curl_handle & handle)> callback)
|
||||
{
|
||||
current_transfers.emplace(url, std::make_pair(curl.download(url, path), std::move(callback)));
|
||||
}
|
||||
|
||||
void scenes::lobby::download(const std::string & url, std::function<void(libcurl::curl_handle & handle)> callback)
|
||||
{
|
||||
current_transfers.emplace(url, std::make_pair(curl.download(url), std::move(callback)));
|
||||
}
|
||||
|
||||
libcurl::curl_handle * scenes::lobby::try_get_download_handle(const std::string & url)
|
||||
{
|
||||
auto iter = current_transfers.find(url);
|
||||
if (iter == current_transfers.end())
|
||||
return nullptr;
|
||||
else
|
||||
return &iter->second.first;
|
||||
}
|
||||
|
||||
std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
{
|
||||
imgui_ctx->new_frame(predicted_display_time);
|
||||
update_transfers();
|
||||
update_file_picker();
|
||||
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
const float TabWidth = 300;
|
||||
@@ -1914,6 +1760,10 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
gui_post_processing();
|
||||
break;
|
||||
|
||||
case tab::customize:
|
||||
gui_customize(predicted_display_time);
|
||||
break;
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
case tab::debug:
|
||||
gui_debug();
|
||||
@@ -1951,28 +1801,31 @@ std::vector<std::pair<int, XrCompositionLayerQuad>> scenes::lobby::draw_gui(XrTi
|
||||
ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
|
||||
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), ¤t_tab, tab::server_list, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " " + _("Server list"), current_tab, tab::server_list, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), ¤t_tab, tab::settings, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), current_tab, tab::settings, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), ¤t_tab, tab::post_processing, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_WAND_MAGIC_SPARKLES " " + _("Post-processing"), current_tab, tab::post_processing, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_PANORAMA " " + _("Customize"), current_tab, tab::customize, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
#if WIVRN_CLIENT_DEBUG_MENU
|
||||
RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), ¤t_tab, tab::debug, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_BUG_SLASH " " + _("Debug"), current_tab, tab::debug, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
#endif
|
||||
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 3 * ImGui::GetCurrentContext()->FontSize - 6 * style.FramePadding.y - 2 * style.ItemSpacing.y - style.WindowPadding.y);
|
||||
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), ¤t_tab, tab::about, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " " + _("About"), current_tab, tab::about, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), ¤t_tab, tab::licenses, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_SCALE_BALANCED " " + _("Licenses"), current_tab, tab::licenses, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), ¤t_tab, tab::exit, {TabWidth, 0});
|
||||
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " " + _("Exit"), current_tab, tab::exit, {TabWidth, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
|
||||
|
||||
@@ -0,0 +1,857 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022-2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022-2024 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define IMGUI_DEFINE_MATH_OPERATORS
|
||||
|
||||
#include "lobby.h"
|
||||
|
||||
#include "application.h"
|
||||
#include "constants.h"
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "imspinner.h"
|
||||
#include "utils/files.h"
|
||||
#include "utils/i18n.h"
|
||||
#include "utils/json_string.h"
|
||||
#include <algorithm>
|
||||
#include <boost/url/url.hpp>
|
||||
#include <boost/url/url_view.hpp>
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
void scenes::lobby::save_environment_json()
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "[";
|
||||
bool empty = true;
|
||||
for (const auto & model: local_environments)
|
||||
{
|
||||
if (model.builtin)
|
||||
continue;
|
||||
|
||||
empty = false;
|
||||
ss << "{\"name\":" << json_string(model.name)
|
||||
<< ",\"author\":" << json_string(model.author)
|
||||
<< ",\"description\":" << json_string(model.description)
|
||||
<< ",\"screenshot\":" << json_string(model.screenshot_url)
|
||||
<< ",\"url\":" << json_string(model.gltf_url)
|
||||
<< ",\"size\":" << model.size
|
||||
<< "},";
|
||||
}
|
||||
if (not empty)
|
||||
ss.seekp(-1, ss.cur);
|
||||
ss << "]";
|
||||
|
||||
utils::write_whole_file(application::get_config_path() / "environments.json", ss.str());
|
||||
}
|
||||
|
||||
static std::string join_url(std::string_view base, std::string_view ref)
|
||||
{
|
||||
if (base == "")
|
||||
return (std::string)ref;
|
||||
|
||||
boost::urls::url base_url(base);
|
||||
boost::urls::url ref_url(ref);
|
||||
|
||||
if (auto res = base_url.resolve(boost::urls::url_view{ref}); res.has_error())
|
||||
{
|
||||
// The only possible error is if base is not a base url
|
||||
return (std::string)ref;
|
||||
}
|
||||
|
||||
return base_url.buffer();
|
||||
}
|
||||
|
||||
std::vector<scenes::lobby::environment_model> scenes::lobby::load_environment_json(const std::string & json, std::string_view base_url)
|
||||
{
|
||||
std::vector<scenes::lobby::environment_model> models;
|
||||
|
||||
simdjson::dom::parser parser;
|
||||
simdjson::dom::element root = parser.parse(json);
|
||||
|
||||
if (not root.is_array())
|
||||
return models;
|
||||
|
||||
for (simdjson::dom::object i: simdjson::dom::array(root))
|
||||
{
|
||||
environment_model model;
|
||||
if (auto val = i["name"]; val.is_string())
|
||||
model.name = val.get_string().value();
|
||||
|
||||
if (auto val = i["author"]; val.is_string())
|
||||
model.author = val.get_string().value();
|
||||
|
||||
if (auto val = i["description"]; val.is_string())
|
||||
model.description = val.get_string().value();
|
||||
|
||||
if (auto val = i["screenshot"]; val.is_string() and val.get_string().value() != "")
|
||||
model.screenshot_url = join_url(base_url, val.get_string().value());
|
||||
|
||||
if (auto val = i["url"]; val.is_string())
|
||||
model.gltf_url = join_url(base_url, val.get_string().value());
|
||||
|
||||
if (auto val = i["size"]; val.is_number())
|
||||
model.size = val.get_int64();
|
||||
|
||||
model.builtin = false;
|
||||
model.local_screenshot_path = application::get_config_path() / "environments" / (model.name + ".png");
|
||||
model.local_gltf_path = application::get_config_path() / "environments" / (model.name + ".glb");
|
||||
|
||||
models.push_back(std::move(model));
|
||||
}
|
||||
|
||||
std::ranges::sort(models, std::less{});
|
||||
|
||||
return models;
|
||||
}
|
||||
|
||||
void scenes::lobby::download_environment(const environment_model & model, bool use_after_downloading)
|
||||
{
|
||||
spdlog::info("Downloading {}", model.gltf_url);
|
||||
std::filesystem::create_directory(model.local_gltf_path.parent_path());
|
||||
|
||||
download(model.gltf_url, model.local_gltf_path, [this, m = model, use_after_downloading](libcurl::curl_handle & handle) {
|
||||
std::filesystem::create_directory(m.local_screenshot_path.parent_path());
|
||||
utils::write_whole_file(m.local_screenshot_path, m.screenshot_png);
|
||||
|
||||
local_environments.push_back(m);
|
||||
std::ranges::sort(local_environments, std::less{});
|
||||
save_environment_json();
|
||||
|
||||
if (use_after_downloading)
|
||||
use_environment(m);
|
||||
});
|
||||
}
|
||||
|
||||
void scenes::lobby::use_environment(const environment_model & model)
|
||||
{
|
||||
if (model.local_gltf_path == "")
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
config.passthrough_enabled = true;
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
else
|
||||
{
|
||||
load_environment_status = "";
|
||||
future_environment = utils::async<std::pair<std::string, std::shared_ptr<entt::registry>>, float>(
|
||||
[this](auto token, std::filesystem::path path) {
|
||||
return std::make_pair(
|
||||
path,
|
||||
load_gltf(path, [&](float progress) {
|
||||
token.set_progress(progress);
|
||||
}));
|
||||
},
|
||||
model.local_gltf_path);
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::lobby::update_file_picker()
|
||||
{
|
||||
if (not lobby_file_picker_future.valid())
|
||||
return;
|
||||
|
||||
lobby_file_picker.display();
|
||||
|
||||
if (lobby_file_picker_future.wait_for(0s) != std::future_status::ready)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
load_environment_status = "";
|
||||
future_environment = utils::async<std::pair<std::string, std::shared_ptr<entt::registry>>, float>(
|
||||
[this](auto token, file_picker_result environment) {
|
||||
auto local_path = application::get_cache_path() / "local.glb";
|
||||
|
||||
utils::write_whole_file(local_path, (std::span<const std::byte>)environment.file);
|
||||
|
||||
// TODO remove only local.glb from cache
|
||||
clear_gltf_cache();
|
||||
|
||||
return std::make_pair(
|
||||
local_path,
|
||||
load_gltf(local_path, [&](float progress) {
|
||||
token.set_progress(progress);
|
||||
}));
|
||||
},
|
||||
lobby_file_picker_future.get());
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Cannot load local environment: {}", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::lobby::delete_environment(const environment_model & to_be_deleted)
|
||||
{
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(to_be_deleted.local_gltf_path, ec); // Ignore errors
|
||||
std::filesystem::remove(to_be_deleted.local_screenshot_path, ec); // Ignore errors
|
||||
unload_gltf(to_be_deleted.local_gltf_path);
|
||||
clear_texture_cache();
|
||||
|
||||
if (std::erase_if(local_environments, [&](auto & model) { return model.local_gltf_path == to_be_deleted.local_gltf_path; }))
|
||||
save_environment_json();
|
||||
}
|
||||
|
||||
void scenes::lobby::download_environment_list()
|
||||
{
|
||||
downloadable_environment_list_status = "";
|
||||
downloadable_environments.clear();
|
||||
|
||||
if (not try_get_download_handle(WIVRN_ENVIRONMENTS_URL))
|
||||
{
|
||||
spdlog::info("Downloading {}", WIVRN_ENVIRONMENTS_URL);
|
||||
download(WIVRN_ENVIRONMENTS_URL, [this](libcurl::curl_handle & handle) {
|
||||
try
|
||||
{
|
||||
// TODO cache in filesystem?
|
||||
downloadable_environments = load_environment_json(handle.get_response(), WIVRN_ENVIRONMENTS_URL);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::error("Cannot load custom environments: {}", e.what());
|
||||
downloadable_environment_list_status = fmt::format("Cannot load custom environments: {}", e.what());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
scenes::lobby::environment_item_action scenes::lobby::environment_item(environment_model & model, bool download_screenshot)
|
||||
{
|
||||
environment_item_action action = environment_item_action::none;
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
bool local = std::ranges::contains(local_environments, model.name, &environment_model::name);
|
||||
|
||||
static std::unordered_map<std::string, float> expanded_height;
|
||||
|
||||
float width = ImGui::GetWindowSize().x - ImGui::GetCurrentWindow()->ScrollbarSizes.x - 2 * ImGui::GetCurrentWindow()->WindowPadding.x;
|
||||
ImVec2 screenshot_size{256, 256};
|
||||
ImVec2 default_selectable_size{
|
||||
width,
|
||||
screenshot_size.y + 2 * style.FramePadding.y // Screenshot size including padding
|
||||
// + style.ItemSpacing.y // Spacing
|
||||
// + ImGui::GetFontSize() + 2 * style.FramePadding.y // Progress bar height
|
||||
};
|
||||
ImVec2 selectable_size = default_selectable_size;
|
||||
|
||||
bool expanded = false;
|
||||
if (auto iter = expanded_height.find(model.gltf_url); iter != expanded_height.end())
|
||||
{
|
||||
selectable_size.y = std::max(selectable_size.y, iter->second);
|
||||
expanded = true;
|
||||
}
|
||||
|
||||
ImTextureID screenshot = model.screenshot;
|
||||
if (ImRect{window->DC.CursorPos, window->DC.CursorPos + selectable_size}.Overlaps(window->ClipRect))
|
||||
{
|
||||
if (screenshot == 0)
|
||||
{
|
||||
if (download_screenshot)
|
||||
{
|
||||
if (model.screenshot_url != "" and not try_get_download_handle(model.screenshot_url))
|
||||
{
|
||||
spdlog::info("Downloading {}", model.screenshot_url);
|
||||
|
||||
download(model.screenshot_url,
|
||||
[this, url = model.screenshot_url](libcurl::curl_handle & handle) {
|
||||
try
|
||||
{
|
||||
auto png = handle.get_response_bytes();
|
||||
auto screenshot = imgui_ctx->load_texture(png);
|
||||
|
||||
for (auto & model: downloadable_environments)
|
||||
{
|
||||
if (model.screenshot_url == url)
|
||||
{
|
||||
model.screenshot = screenshot;
|
||||
model.screenshot_png = std::vector<std::byte>{png.begin(), png.end()};
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Cannot load image from {}: {}", handle.get_url(), e.what());
|
||||
for (auto & model: downloadable_environments)
|
||||
{
|
||||
if (model.screenshot_url == url)
|
||||
{
|
||||
model.screenshot_url = "";
|
||||
model.screenshot = default_environment_screenshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (model.local_screenshot_path != "" and std::filesystem::exists(model.local_screenshot_path))
|
||||
{
|
||||
try
|
||||
{
|
||||
spdlog::info("Loading {}", model.local_screenshot_path.native());
|
||||
screenshot = model.screenshot = imgui_ctx->load_texture(utils::mapped_file{model.local_screenshot_path});
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
spdlog::warn("Cannot load screenshot {}: {}", model.local_screenshot_path.native(), e.what());
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(model.local_screenshot_path, ec); // Ignore errors
|
||||
model.local_screenshot_path = ""; // Avoid subsequent loading errors
|
||||
model.screenshot = default_environment_screenshot;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto backup_cursor = ImGui::GetCursorScreenPos();
|
||||
const auto & config = application::get_config();
|
||||
bool selected = (config.passthrough_enabled and model.local_gltf_path == "") or
|
||||
(not config.passthrough_enabled and config.environment_model == model.local_gltf_path);
|
||||
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
// Use ImGuiSelectableFlags_AllowDoubleClick to have ImGuiButtonFlags_PressedOnClickRelease in ImGui::Selectable
|
||||
if (ImGui::Selectable(("##" + model.gltf_url).c_str(), &selected, ImGuiSelectableFlags_AllowDoubleClick, selectable_size))
|
||||
{
|
||||
if (local)
|
||||
action = environment_item_action::use_model;
|
||||
else
|
||||
action = environment_item_action::download_model;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
auto end_cursor = ImGui::GetCursorScreenPos();
|
||||
|
||||
// Remove the height of the progress bar if a transfer is in progress
|
||||
float text_clip_height = selectable_size.y + style.FramePadding.y;
|
||||
if (auto handle = try_get_download_handle(model.gltf_url); handle and handle->get_state() == libcurl::state::transferring)
|
||||
text_clip_height -= ImGui::GetFontSize() + 2 * style.FramePadding.y + style.ItemSpacing.y;
|
||||
|
||||
// Display the screenshot
|
||||
ImGui::SetCursorScreenPos(backup_cursor + ImVec2(style.FramePadding.x, 0));
|
||||
ImGui::Image(screenshot ? screenshot : default_environment_screenshot, screenshot_size);
|
||||
|
||||
ImGui::PushClipRect(backup_cursor, backup_cursor + ImVec2(selectable_size.x, text_clip_height), true);
|
||||
float indent = screenshot_size.x + style.FramePadding.x + 2 * style.ImageBorderSize + style.ItemSpacing.x;
|
||||
|
||||
// Display the text
|
||||
std::pair<std::string, ImVec2> text_name;
|
||||
std::pair<std::string, ImVec2> text_author;
|
||||
std::pair<std::string, ImVec2> text_description;
|
||||
std::pair<std::string, ImVec2> text_filesize;
|
||||
|
||||
text_name.first = model.builtin ? _(model.name.c_str()) : model.name;
|
||||
if (model.author != "")
|
||||
text_author.first = fmt::format(_F("Author: {}"), model.author);
|
||||
if (model.description != "")
|
||||
text_description.first = model.description;
|
||||
if (not model.builtin)
|
||||
text_filesize.first = fmt::format(_F("Size: {:.1f} MB"), model.size * 1.0e-6);
|
||||
|
||||
const float wrap_width = selectable_size.x - indent - style.FramePadding.x;
|
||||
|
||||
// clang-format off
|
||||
text_name.second = ImGui::CalcTextSize(text_name.first.data(), text_name.first.data() + text_name.first.size(), false, wrap_width);
|
||||
text_author.second = ImGui::CalcTextSize(text_author.first.data(), text_author.first.data() + text_author.first.size(), false, wrap_width);
|
||||
text_description.second = ImGui::CalcTextSize(text_description.first.data(), text_description.first.data() + text_description.first.size(), false, wrap_width);
|
||||
text_filesize.second = ImGui::CalcTextSize(text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), false, wrap_width);
|
||||
// clang-format on
|
||||
|
||||
ImGui::SetCursorScreenPos(backup_cursor);
|
||||
|
||||
ImVec2 text_pos = backup_cursor + ImVec2(indent, 0);
|
||||
float text_height = 0;
|
||||
|
||||
ImGui::RenderTextWrapped(text_pos, text_name.first.data(), text_name.first.data() + text_name.first.size(), wrap_width);
|
||||
text_height += text_name.second.y + style.ItemSpacing.y;
|
||||
|
||||
if (text_author.first != "")
|
||||
{
|
||||
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_author.first.data(), text_author.first.data() + text_author.first.size(), wrap_width);
|
||||
text_height += text_author.second.y + style.ItemSpacing.y;
|
||||
}
|
||||
|
||||
if (text_description.first != "")
|
||||
{
|
||||
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_description.first.data(), text_description.first.data() + text_description.first.size(), wrap_width);
|
||||
text_height += text_description.second.y + style.ItemSpacing.y;
|
||||
}
|
||||
|
||||
if (text_filesize.first != "")
|
||||
{
|
||||
ImGui::RenderTextWrapped(text_pos + ImVec2(0, text_height), text_filesize.first.data(), text_filesize.first.data() + text_filesize.first.size(), wrap_width);
|
||||
text_height += text_filesize.second.y + style.ItemSpacing.y;
|
||||
}
|
||||
|
||||
ImGui::PopClipRect();
|
||||
|
||||
// Display the expand/collapse button
|
||||
if (text_height > default_selectable_size.y - 2 * style.FramePadding.y)
|
||||
{
|
||||
const char * button_text = expanded ? ICON_FA_CHEVRON_UP : ICON_FA_CHEVRON_DOWN;
|
||||
auto expand_size = ImGui::CalcTextSize(button_text) + style.FramePadding * 2.0f;
|
||||
float radius = std::max(expand_size.x, expand_size.y) / 2;
|
||||
|
||||
ImGui::SetCursorScreenPos(ImVec2(
|
||||
backup_cursor.x + selectable_size.x / 2 - radius,
|
||||
backup_cursor.y + selectable_size.y + style.FramePadding.y - radius));
|
||||
|
||||
// Triple hash so that the button text is not used to compute the button ID and
|
||||
// avoid vibrating the controller when the text changes
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, radius);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
if (ImGui::Button((button_text + ("###expand-" + model.gltf_url)).c_str(), ImVec2(radius * 2, radius * 2)))
|
||||
{
|
||||
if (expanded)
|
||||
expanded_height.erase(model.gltf_url);
|
||||
else
|
||||
expanded_height[model.gltf_url] = text_height + 2 * style.FramePadding.y;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FrameRounding
|
||||
}
|
||||
|
||||
// Display the delete button
|
||||
if (local and not model.builtin)
|
||||
{
|
||||
auto delete_size = ImGui::CalcTextSize(ICON_FA_TRASH) + style.FramePadding * 2;
|
||||
ImGui::SetCursorScreenPos(ImVec2(
|
||||
backup_cursor.x + width - style.FramePadding.x - delete_size.x,
|
||||
backup_cursor.y));
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button((ICON_FA_TRASH "##delete-" + model.name).c_str()))
|
||||
action = environment_item_action::delete_model;
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_("Delete this model"));
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
}
|
||||
// Display the download progress
|
||||
else if (auto handle = try_get_download_handle(model.gltf_url))
|
||||
{
|
||||
switch (handle->get_state())
|
||||
{
|
||||
case libcurl::state::transferring: {
|
||||
ImVec2 cancel_size = ImGui::CalcTextSize(ICON_FA_STOP) + style.FramePadding * 2;
|
||||
|
||||
ImGui::SetCursorScreenPos(ImVec2(
|
||||
backup_cursor.x + screenshot_size.x + style.FramePadding.x + style.ItemSpacing.x,
|
||||
backup_cursor.y + selectable_size.y - (ImGui::GetFontSize() + 2 * style.FramePadding.y)));
|
||||
|
||||
float progress_width = width - cancel_size.x - screenshot_size.x - 2 * style.FramePadding.x - 2 * style.ItemSpacing.x;
|
||||
|
||||
if (handle->get_content_length() > 0)
|
||||
ImGui::ProgressBar(handle->get_progress() / (float)handle->get_content_length(), {progress_width, 0});
|
||||
else
|
||||
ImGui::ProgressBar(-ImGui::GetTime(), {progress_width, 0}); // Indeterminate progress bar
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button((ICON_FA_STOP "##" + model.name).c_str()))
|
||||
handle->cancel();
|
||||
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
break;
|
||||
}
|
||||
|
||||
case libcurl::state::error:
|
||||
if (handle->get_curl_code() == CURLE_HTTP_RETURNED_ERROR)
|
||||
{
|
||||
spdlog::error("HTTP error {} when downloading {}", handle->get_response_code(), handle->get_url());
|
||||
load_environment_status = fmt::format(
|
||||
_F("HTTP error {} when downloading {}"),
|
||||
handle->get_response_code(),
|
||||
handle->get_url());
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("Curl error when downloading {}: {}", handle->get_url(), curl_easy_strerror(handle->get_curl_code()));
|
||||
load_environment_status = fmt::format(
|
||||
_F("Curl error when downloading {}\n{}: {}"),
|
||||
handle->get_url(),
|
||||
magic_enum::enum_name(handle->get_curl_code()),
|
||||
curl_easy_strerror(handle->get_curl_code()));
|
||||
}
|
||||
|
||||
handle->reset();
|
||||
break;
|
||||
|
||||
case libcurl::state::cancelled:
|
||||
handle->reset();
|
||||
break;
|
||||
|
||||
case libcurl::state::cancelling:
|
||||
case libcurl::state::reset:
|
||||
case libcurl::state::done:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::SetCursorScreenPos(end_cursor);
|
||||
ImGui::Dummy({});
|
||||
return action;
|
||||
}
|
||||
|
||||
void scenes::lobby::environment_list(std::vector<environment_model> & models, bool download_screenshot)
|
||||
{
|
||||
for (auto & model: models)
|
||||
{
|
||||
ImGui::BeginDisabled(model.local_gltf_path == "" and system.passthrough_supported() == xr::passthrough_type::none);
|
||||
switch (environment_item(model, download_screenshot))
|
||||
{
|
||||
case environment_item_action::none:
|
||||
break;
|
||||
|
||||
case environment_item_action::download_model:
|
||||
download_environment(model, true);
|
||||
break;
|
||||
|
||||
case environment_item_action::use_model:
|
||||
use_environment(model);
|
||||
break;
|
||||
|
||||
case environment_item_action::delete_model:
|
||||
ImGui::OpenPopup("confirm delete model");
|
||||
environment_to_be_deleted = &model;
|
||||
break;
|
||||
}
|
||||
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled) and (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled))
|
||||
imgui_ctx->tooltip(_("This feature is not supported by your headset"));
|
||||
ImGui::EndDisabled();
|
||||
}
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
if (ImGui::BeginPopupModal("confirm delete model", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
ImGui::Text(_S("Really delete %s?"), environment_to_be_deleted->name.c_str());
|
||||
|
||||
const auto & style = ImGui::GetStyle();
|
||||
auto cancel_text = _("Cancel");
|
||||
auto delete_text = _("Delete");
|
||||
auto cancel_size = ImGui::CalcTextSize(cancel_text.c_str()) + style.FramePadding * 2.0f;
|
||||
auto delete_size = ImGui::CalcTextSize(delete_text.c_str()) + style.FramePadding * 2.0f;
|
||||
|
||||
ImGui::SetCursorPosX(ImGui::GetWindowContentRegionMax().x - cancel_size.x - style.ItemSpacing.x - delete_size.x);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(delete_text.c_str()))
|
||||
{
|
||||
delete_environment(*environment_to_be_deleted);
|
||||
environment_to_be_deleted = nullptr;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(cancel_text.c_str()))
|
||||
{
|
||||
environment_to_be_deleted = nullptr;
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
|
||||
}
|
||||
|
||||
void scenes::lobby::popup_load_environment(XrTime predicted_display_time)
|
||||
{
|
||||
if (future_environment.valid() or load_environment_status != "")
|
||||
{
|
||||
if (not ImGui::IsPopupOpen("loading environment model"))
|
||||
{
|
||||
if (popup_load_environment_display_time == 0)
|
||||
popup_load_environment_display_time = predicted_display_time + 50'000'000;
|
||||
else if (predicted_display_time > popup_load_environment_display_time)
|
||||
ImGui::OpenPopup("loading environment model");
|
||||
}
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, constants::style::window_padding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
if (ImGui::BeginPopupModal("loading environment model", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
if (future_environment.valid())
|
||||
{
|
||||
if (future_environment.poll() == utils::future_status::ready)
|
||||
{
|
||||
try
|
||||
{
|
||||
load_environment_status = "";
|
||||
auto [gltf_path, env] = future_environment.get();
|
||||
ImGui::CloseCurrentPopup();
|
||||
popup_load_environment_display_time = 0;
|
||||
|
||||
// Keep the current lobby position / orientation
|
||||
auto & old_lobby_node = world.get<components::node>(lobby_entity);
|
||||
auto position = old_lobby_node.position;
|
||||
auto orientation = old_lobby_node.orientation;
|
||||
|
||||
remove(lobby_entity);
|
||||
auto [new_lobby_entity, new_lobby_node] = add_gltf(env, layer_lobby);
|
||||
new_lobby_node.position = position;
|
||||
new_lobby_node.orientation = orientation;
|
||||
lobby_entity = new_lobby_entity;
|
||||
|
||||
auto & config = application::get_config();
|
||||
|
||||
config.passthrough_enabled = false;
|
||||
config.environment_model = gltf_path;
|
||||
setup_passthrough();
|
||||
config.save();
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
load_environment_status = fmt::format(_F("Cannot load environment: {}"), e.what());
|
||||
spdlog::error("Cannot load environment: {}", e.what());
|
||||
}
|
||||
|
||||
future_environment.reset();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::Text("%s", _S("Loading environment"));
|
||||
ImGui::ProgressBar(future_environment.get_progress());
|
||||
}
|
||||
}
|
||||
|
||||
if (load_environment_status != "")
|
||||
{
|
||||
ImGui::Text("%s", load_environment_status.c_str());
|
||||
if (ImGui::Button(_S("Close")))
|
||||
{
|
||||
load_environment_status = "";
|
||||
ImGui::CloseCurrentPopup();
|
||||
popup_load_environment_display_time = 0;
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
ImGui::PopStyleVar(3); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
|
||||
}
|
||||
}
|
||||
|
||||
libcurl::curl_handle * scenes::lobby::parse_environment_list()
|
||||
{
|
||||
auto index_transfer = try_get_download_handle(WIVRN_ENVIRONMENTS_URL);
|
||||
if (index_transfer)
|
||||
switch (index_transfer->get_state())
|
||||
{
|
||||
case libcurl::state::cancelling:
|
||||
case libcurl::state::done:
|
||||
case libcurl::state::reset:
|
||||
case libcurl::state::transferring:
|
||||
break;
|
||||
|
||||
case libcurl::state::cancelled:
|
||||
index_transfer->reset();
|
||||
break;
|
||||
|
||||
case libcurl::state::error:
|
||||
if (index_transfer->get_curl_code() == CURLE_HTTP_RETURNED_ERROR)
|
||||
{
|
||||
spdlog::error("HTTP error {} when downloading index.json", index_transfer->get_response_code());
|
||||
downloadable_environment_list_status = fmt::format(
|
||||
_F("HTTP error {} when downloading {}"),
|
||||
index_transfer->get_response_code(),
|
||||
"index.json");
|
||||
}
|
||||
else
|
||||
{
|
||||
spdlog::error("Curl error when downloading index.json: {}", curl_easy_strerror(index_transfer->get_curl_code()));
|
||||
downloadable_environment_list_status = fmt::format(
|
||||
_F("Curl error when downloading {}\n{}: {}"),
|
||||
"index.json",
|
||||
magic_enum::enum_name(index_transfer->get_curl_code()),
|
||||
curl_easy_strerror(index_transfer->get_curl_code()));
|
||||
}
|
||||
|
||||
index_transfer->reset();
|
||||
break;
|
||||
}
|
||||
|
||||
return index_transfer;
|
||||
}
|
||||
|
||||
void scenes::lobby::gui_customize(XrTime predicted_display_time)
|
||||
{
|
||||
auto & config = application::get_config();
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, {20, 20});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
|
||||
ImGui::BeginChild("environment list", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, ImGui::GetFontSize() + 80));
|
||||
environment_list(local_environments, false);
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
if (ImGui::Button(_S("Download more environments")))
|
||||
{
|
||||
download_environment_list();
|
||||
ImGui::OpenPopup("download environment model");
|
||||
}
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::SameLine();
|
||||
if (ImGui::Button(_S("Open local glTF model")))
|
||||
lobby_file_picker_future = lobby_file_picker.open();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
const auto & popup_layer = imgui_ctx->layers()[1];
|
||||
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
|
||||
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
|
||||
ImGui::SetNextWindowSize({1200, 900});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, constants::style::window_rounding);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, constants::style::window_border_size);
|
||||
if (ImGui::BeginPopupModal("download environment model", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
auto close = _("Close");
|
||||
auto close_size = ImGui::CalcTextSize(close.c_str());
|
||||
|
||||
ImGui::BeginChild("Main", ImGui::GetWindowSize() - ImGui::GetCursorPos() - ImVec2(0, close_size.y + 80) /*, ImGuiChildFlags_AlwaysUseWindowPadding*/);
|
||||
|
||||
auto index_transfer = parse_environment_list();
|
||||
switch (index_transfer ? index_transfer->get_state() : libcurl::state::reset)
|
||||
{
|
||||
case libcurl::state::cancelling:
|
||||
case libcurl::state::transferring:
|
||||
case libcurl::state::cancelled:
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() / 2 - ImVec2{200, 200} - ImGui::GetStyle().FramePadding);
|
||||
ImSpinner::SpinnerAng("index download spinner",
|
||||
200, // Radius
|
||||
40, // Thickness
|
||||
ImColor{1.f, 1.f, 1.f, 1.f}, // Colour
|
||||
ImColor{1.f, 1.f, 1.f, 0.f}, // Background
|
||||
6, // Velocity
|
||||
0.75f * 2 * M_PI // Angle
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case libcurl::state::error: // Should not happen, parse_environment_list resets the status in case of error
|
||||
case libcurl::state::done: // Should not happen, parse_environment_list resets the status when done
|
||||
assert(false);
|
||||
break;
|
||||
|
||||
case libcurl::state::reset:
|
||||
if (downloadable_environment_list_status == "")
|
||||
{
|
||||
environment_list(downloadable_environments, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
CenterTextHV(downloadable_environment_list_status);
|
||||
|
||||
ImGui::Dummy({0, constants::gui::font_size_large});
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, 0);
|
||||
ImGui::SetCursorPosX((ImGui::GetWindowSize().x - ImGui::CalcTextSize(ICON_FA_ROTATE).x) / 2 - ImGui::GetStyle().FramePadding.x);
|
||||
if (ImGui::Button(ICON_FA_ROTATE))
|
||||
download_environment_list();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_Button
|
||||
ImGui::PopFont();
|
||||
}
|
||||
}
|
||||
|
||||
ScrollWhenDragging();
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - close_size - ImVec2{50, 50});
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(_S("Close")))
|
||||
ImGui::CloseCurrentPopup();
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3); // ImGuiCol_Button, ImGuiCol_ButtonHovered, ImGuiCol_ButtonActive
|
||||
|
||||
popup_load_environment(predicted_display_time);
|
||||
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
popup_load_environment(predicted_display_time);
|
||||
}
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowRounding, ImGuiStyleVar_WindowBorderSize
|
||||
|
||||
// if (ImGui::RadioButton(_S("Custom environment"), not config.passthrough_enabled and config.environment_model_uri != ""))
|
||||
// lobby_file_picker_future = lobby_file_picker.open();
|
||||
// imgui_ctx->vibrate_on_hover();
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// lobby_file_picker.display();
|
||||
//
|
||||
// if (lobby_file_picker_future.valid() and lobby_file_picker_future.wait_for(0s) == std::future_status::ready)
|
||||
// {
|
||||
// auto environment = lobby_file_picker_future.get();
|
||||
//
|
||||
// // TODO load asynchronously
|
||||
// // TODO allow caching
|
||||
// spdlog::info("Loading new environment from {}", environment.path.native());
|
||||
// auto t0 = std::chrono::steady_clock::now();
|
||||
// auto new_lobby = load_gltf(environment.file);
|
||||
// auto dt = std::chrono::steady_clock::now() - t0;
|
||||
// spdlog::info("Loaded successfully in {}", dt);
|
||||
//
|
||||
// remove(lobby_entity);
|
||||
// lobby_entity = add_gltf(new_lobby, layer_lobby).first;
|
||||
//
|
||||
// config.passthrough_enabled = false;
|
||||
// setup_passthrough();
|
||||
// }
|
||||
// }
|
||||
// catch (std::exception & e)
|
||||
// {
|
||||
// spdlog::warn("Cannot load environment: {}", e.what());
|
||||
// }
|
||||
|
||||
// auto & lobby_node = world.get<components::node>(lobby_entity);
|
||||
// float scale = lobby_node.scale.x;
|
||||
// if (ImGui::SliderFloat("Environment scale", &scale, 0.1, 10, "%.3f", ImGuiSliderFlags_Logarithmic))
|
||||
// lobby_node.scale = glm::vec3{scale, scale, scale};
|
||||
// imgui_ctx->vibrate_on_hover();
|
||||
//
|
||||
// ImGui::SliderFloat("Environment elevation", &lobby_node.position.y, -3, 3, "%.3f");
|
||||
// imgui_ctx->vibrate_on_hover();
|
||||
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_ItemSpacing, ImGuiStyleVar_FramePadding
|
||||
}
|
||||
@@ -151,8 +151,9 @@ static const std::array supported_depth_formats{
|
||||
vk::Format::eX8D24UnormPack32,
|
||||
};
|
||||
|
||||
scenes::stream::stream() :
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats),
|
||||
scenes::stream::stream(std::string server_name, scene & parent_scene) :
|
||||
scene_impl<stream>(supported_color_formats, supported_depth_formats, parent_scene),
|
||||
apps{*this, std::move(server_name)},
|
||||
blitters{blitter(device, 0), blitter(device, 1)}
|
||||
{
|
||||
}
|
||||
@@ -185,9 +186,9 @@ static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::inst
|
||||
return res;
|
||||
}
|
||||
|
||||
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps)
|
||||
std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_session> network_session, float guessed_fps, std::string server_name, scene & parent_scene)
|
||||
{
|
||||
std::shared_ptr<stream> self{new stream};
|
||||
std::shared_ptr<stream> self{new stream{std::move(server_name), parent_scene}};
|
||||
self->network_session = std::move(network_session);
|
||||
|
||||
self->network_session->send_control([&]() {
|
||||
@@ -389,6 +390,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
|
||||
});
|
||||
|
||||
self->wifi = application::get_wifi_lock().get_wifi_lock();
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -401,13 +403,10 @@ void scenes::stream::on_focused()
|
||||
width = views[0].recommendedImageRectWidth;
|
||||
height = views[0].recommendedImageRectHeight;
|
||||
|
||||
renderer.emplace(device, physical_device, queue, commandpool);
|
||||
loader.emplace(device, physical_device, queue, queue_family_index, renderer->get_default_material());
|
||||
|
||||
std::string profile = controller_name();
|
||||
input.emplace(
|
||||
*this,
|
||||
"controllers/" + profile + "/profile.json",
|
||||
"assets://controllers/" + profile + "/profile.json",
|
||||
layer_controllers,
|
||||
layer_rays);
|
||||
|
||||
@@ -447,7 +446,8 @@ void scenes::stream::on_focused()
|
||||
},
|
||||
};
|
||||
|
||||
swapchain_imgui = xr::swapchain(
|
||||
xr::swapchain swapchain_imgui(
|
||||
instance,
|
||||
session,
|
||||
device,
|
||||
swapchain_format,
|
||||
@@ -467,8 +467,9 @@ void scenes::stream::on_focused()
|
||||
queue_family_index,
|
||||
queue,
|
||||
imgui_inputs,
|
||||
swapchain_imgui,
|
||||
std::vector{vp});
|
||||
std::move(swapchain_imgui),
|
||||
std::vector{vp},
|
||||
image_cache);
|
||||
|
||||
if (application::get_config().enable_stream_gui)
|
||||
{
|
||||
@@ -491,17 +492,14 @@ void scenes::stream::on_focused()
|
||||
|
||||
void scenes::stream::on_unfocused()
|
||||
{
|
||||
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets
|
||||
world.clear(); // Must be cleared before the renderer so that the descriptor sets are freed before their pools
|
||||
renderer->wait_idle(); // Must be before the scene data because the renderer uses its descriptor sets;
|
||||
world.clear();
|
||||
input.reset();
|
||||
loader.reset();
|
||||
renderer.reset();
|
||||
clear_swapchains();
|
||||
left_hand.reset();
|
||||
right_hand.reset();
|
||||
|
||||
imgui_ctx.reset();
|
||||
swapchain_imgui = xr::swapchain();
|
||||
}
|
||||
|
||||
scenes::stream::~stream()
|
||||
@@ -730,6 +728,8 @@ bool scenes::stream::is_gui_interactable() const
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::foveation_settings:
|
||||
case gui_status::applications:
|
||||
case gui_status::application_launcher:
|
||||
return true;
|
||||
|
||||
case gui_status::hidden:
|
||||
@@ -777,6 +777,7 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
.variant = application::get_messages_info().variant,
|
||||
});
|
||||
|
||||
gui_status = stream::gui_status::hidden;
|
||||
application::pop_scene();
|
||||
}
|
||||
|
||||
@@ -927,6 +928,28 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
command_buffer.end();
|
||||
vk::SubmitInfo submit_info;
|
||||
submit_info.setCommandBuffers(*command_buffer);
|
||||
|
||||
std::vector<vk::Semaphore> semaphores;
|
||||
std::vector<uint64_t> semaphore_vals;
|
||||
std::vector<vk::PipelineStageFlags> wait_stages;
|
||||
for (auto b: current_blit_handles)
|
||||
{
|
||||
if (b and b->semaphore)
|
||||
{
|
||||
assert(b->semaphore_val);
|
||||
semaphores.push_back(b->semaphore);
|
||||
semaphore_vals.push_back(*b->semaphore_val);
|
||||
wait_stages.push_back(vk::PipelineStageFlagBits::eFragmentShader);
|
||||
}
|
||||
}
|
||||
submit_info.setWaitDstStageMask(wait_stages);
|
||||
submit_info.setWaitSemaphores(semaphores);
|
||||
vk::TimelineSemaphoreSubmitInfo sem_info{
|
||||
.waitSemaphoreValueCount = uint32_t(semaphore_vals.size()),
|
||||
.pWaitSemaphoreValues = semaphore_vals.data(),
|
||||
};
|
||||
submit_info.pNext = &sem_info;
|
||||
|
||||
queue.lock()->submit(submit_info, *fence);
|
||||
#if WIVRN_FEATURE_RENDERDOC
|
||||
renderdoc_end(*vk_instance);
|
||||
@@ -978,6 +1001,8 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
break;
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::applications:
|
||||
case gui_status::application_launcher:
|
||||
dimming = dimming + frame_state.predictedDisplayPeriod / (1e9 * constants::stream::fade_duration);
|
||||
break;
|
||||
}
|
||||
@@ -1063,12 +1088,14 @@ void scenes::stream::render(const XrFrameState & frame_state)
|
||||
case gui_status::hidden:
|
||||
case gui_status::compact:
|
||||
case gui_status::overlay_only:
|
||||
gui_status = gui_status::stats;
|
||||
gui_status = next_gui_status;
|
||||
break;
|
||||
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::foveation_settings:
|
||||
case gui_status::applications:
|
||||
case gui_status::application_launcher:
|
||||
gui_status = gui_status::hidden;
|
||||
break;
|
||||
}
|
||||
@@ -1105,7 +1132,7 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
|
||||
spdlog::info("Creating decoder size {}x{} offset {},{}", item.width, item.height, item.offset_x, item.offset_y);
|
||||
|
||||
decoders.push_back(accumulator_images{
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, item, description.fps, shared_from_this(), stream_index),
|
||||
.decoder = std::make_unique<shard_accumulator>(device, physical_device, instance, queue_family_index, item, description.fps, shared_from_this(), stream_index),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1120,7 +1147,7 @@ void scenes::stream::setup_reprojection_swapchain(uint32_t swapchain_width, uint
|
||||
|
||||
auto views = system.view_configuration_views(viewconfig);
|
||||
|
||||
swapchain = xr::swapchain(session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
swapchain = xr::swapchain(instance, session, device, swapchain_format, swapchain_width, swapchain_height, 1, views.size());
|
||||
spdlog::info("Created stream swapchain: {}x{}", swapchain.width(), swapchain.height());
|
||||
for (auto view: views)
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "app_launcher.h"
|
||||
#include "audio/audio.h"
|
||||
#include "decoder/shard_accumulator.h"
|
||||
#include "render/imgui_impl.h"
|
||||
@@ -49,12 +50,7 @@ public:
|
||||
};
|
||||
static const size_t image_buffer_size = 3;
|
||||
|
||||
struct app
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image;
|
||||
};
|
||||
app_launcher apps;
|
||||
|
||||
private:
|
||||
static const size_t view_count = 2;
|
||||
@@ -114,7 +110,6 @@ private:
|
||||
state state_ = state::initializing;
|
||||
|
||||
xr::swapchain swapchain;
|
||||
xr::swapchain swapchain_imgui;
|
||||
|
||||
std::optional<audio> audio_handle;
|
||||
|
||||
@@ -136,13 +131,16 @@ private:
|
||||
compact,
|
||||
stats,
|
||||
settings,
|
||||
foveation_settings
|
||||
foveation_settings,
|
||||
applications,
|
||||
application_launcher,
|
||||
};
|
||||
|
||||
bool is_gui_interactable() const;
|
||||
|
||||
std::atomic<gui_status> gui_status = gui_status::hidden;
|
||||
enum gui_status last_gui_status = gui_status::hidden;
|
||||
enum gui_status next_gui_status = gui_status::stats;
|
||||
XrTime gui_status_last_change;
|
||||
float dimming = 0;
|
||||
|
||||
@@ -170,15 +168,19 @@ private:
|
||||
// Keep a reference to the resources needed to blit the images until vkWaitForFences
|
||||
std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> current_blit_handles;
|
||||
|
||||
// Last application list received from server
|
||||
thread_safe<std::vector<app>> applications;
|
||||
XrTime running_application_req = 0;
|
||||
thread_safe<to_headset::running_applications> running_applications;
|
||||
|
||||
stream();
|
||||
stream(std::string server_name, scene & parent_scene);
|
||||
|
||||
public:
|
||||
~stream();
|
||||
|
||||
static std::shared_ptr<stream> create(std::unique_ptr<wivrn_session> session, float guessed_fps);
|
||||
static std::shared_ptr<stream> create(
|
||||
std::unique_ptr<wivrn_session> session,
|
||||
float guessed_fps,
|
||||
std::string server_name,
|
||||
scene & parent_scene);
|
||||
|
||||
void render(const XrFrameState &) override;
|
||||
void on_focused() override;
|
||||
@@ -198,6 +200,7 @@ public:
|
||||
void operator()(to_headset::refresh_rate_change &&);
|
||||
void operator()(to_headset::application_list &&);
|
||||
void operator()(to_headset::application_icon &&);
|
||||
void operator()(to_headset::running_applications &&);
|
||||
void operator()(audio_data &&);
|
||||
|
||||
void push_blit_handle(wivrn::shard_accumulator * decoder, std::shared_ptr<wivrn::shard_accumulator::blit_handle> handle);
|
||||
@@ -214,11 +217,6 @@ public:
|
||||
return !exiting;
|
||||
}
|
||||
|
||||
auto get_applications()
|
||||
{
|
||||
return applications.lock();
|
||||
}
|
||||
|
||||
void start_application(std::string appid);
|
||||
|
||||
static meta & get_meta_scene();
|
||||
@@ -305,6 +303,7 @@ private:
|
||||
void gui_compact_view();
|
||||
void gui_settings();
|
||||
void gui_foveation_settings(float predicted_display_period);
|
||||
void gui_applications();
|
||||
void draw_gui(XrTime predicted_display_time, XrDuration predicted_display_period);
|
||||
};
|
||||
} // namespace scenes
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "stream_defoveator.h"
|
||||
#include "application.h"
|
||||
#include "utils/contains.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vk/allocation.h"
|
||||
#include "vk/pipeline.h"
|
||||
@@ -36,7 +35,7 @@ struct stream_defoveator::vertex
|
||||
{
|
||||
// output image position
|
||||
alignas(8) glm::vec2 position;
|
||||
// input texture coordinates + shading rate in the first 4 bits of x
|
||||
// input texture coordinates
|
||||
alignas(8) glm::uvec2 uv;
|
||||
};
|
||||
|
||||
@@ -119,27 +118,17 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
|
||||
target.layout = vk::raii::PipelineLayout(device, pipeline_layout_info);
|
||||
|
||||
const auto & vk_device_extensions = application::get_vk_device_extensions();
|
||||
bool fragment_shading_rate = false;
|
||||
if (utils::contains(vk_device_extensions, VK_KHR_CREATE_RENDERPASS_2_EXTENSION_NAME) and
|
||||
utils::contains(vk_device_extensions, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME))
|
||||
{
|
||||
const auto & [prop, rate_prop] = physical_device.getProperties2<vk::PhysicalDeviceProperties2, vk::PhysicalDeviceFragmentShadingRatePropertiesKHR>();
|
||||
const auto & [feat, fragment_feat] = physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceFragmentShadingRateFeaturesKHR>();
|
||||
fragment_shading_rate = rate_prop.fragmentShadingRateNonTrivialCombinerOps and
|
||||
fragment_feat.primitiveFragmentShadingRate and
|
||||
fragment_feat.attachmentFragmentShadingRate;
|
||||
}
|
||||
|
||||
// Vertex shader
|
||||
vk::raii::ShaderModule vertex_shader = load_shader(device, fragment_shading_rate ? "reprojection_vsr.vert" : "reprojection.vert");
|
||||
auto vertex_shader = load_shader(device, "reprojection.vert");
|
||||
|
||||
// Fragment shader
|
||||
auto specialization = make_specialization_constants(
|
||||
int32_t(alpha),
|
||||
VkBool32(need_srgb_conversion(guess_model())));
|
||||
vk::raii::ShaderModule fragment_shader = load_shader(device, "reprojection.frag");
|
||||
auto fragment_shader = load_shader(device, "reprojection.frag");
|
||||
|
||||
vk::pipeline_builder pipeline_info_builder{
|
||||
vk::pipeline_builder pipeline_info{
|
||||
.flags = {},
|
||||
.Stages = {
|
||||
{
|
||||
@@ -197,48 +186,6 @@ stream_defoveator::pipeline_t & stream_defoveator::ensure_pipeline(size_t view,
|
||||
.subpass = 0,
|
||||
};
|
||||
|
||||
vk::GraphicsPipelineCreateInfo pipeline_info(pipeline_info_builder);
|
||||
|
||||
// Variable fragment shading
|
||||
std::array combiner{
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
vk::FragmentShadingRateCombinerOpKHR::eMax,
|
||||
};
|
||||
vk::PipelineFragmentShadingRateStateCreateInfoKHR shading{
|
||||
.fragmentSize = vk::Extent2D{1, 1},
|
||||
.combinerOps = combiner,
|
||||
};
|
||||
if (fragment_shading_rate)
|
||||
{
|
||||
pipeline_info.pNext = &shading;
|
||||
|
||||
spdlog::info("Available fragment shading rates:");
|
||||
for (const auto rate: physical_device.getFragmentShadingRatesKHR())
|
||||
{
|
||||
if (rate.sampleCounts & vk::SampleCountFlagBits::e1)
|
||||
{
|
||||
spdlog::info("\tfragment size: {}x{}", rate.fragmentSize.width, rate.fragmentSize.height);
|
||||
int flags = 0;
|
||||
if (rate.fragmentSize.width == 4)
|
||||
flags |= 8;
|
||||
else if (rate.fragmentSize.width == 2)
|
||||
flags |= 4;
|
||||
if (rate.fragmentSize.height == 4)
|
||||
flags |= 2;
|
||||
else if (rate.fragmentSize.height == 2)
|
||||
flags |= 1;
|
||||
for (int y = std::bit_width(rate.fragmentSize.height) - 1; y < 3; ++y)
|
||||
{
|
||||
for (int x = std::bit_width(rate.fragmentSize.width) - 1; x < 3; ++x)
|
||||
{
|
||||
if (fragment_sizes[x][y] == 0)
|
||||
fragment_sizes[x][y] = flags << 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
target.pipeline = device.createGraphicsPipeline(application::get_pipeline_cache(), pipeline_info);
|
||||
return target;
|
||||
}
|
||||
@@ -346,21 +293,6 @@ static size_t required_vertices(const wivrn::to_headset::foveation_parameter & p
|
||||
return (2 * (p.x.size() + 1) + 1) * p.y.size();
|
||||
}
|
||||
|
||||
uint32_t stream_defoveator::shading_rate(int pixels_x, int pixels_y)
|
||||
{
|
||||
int x = 0;
|
||||
if (pixels_x >= 2)
|
||||
x = 1;
|
||||
if (pixels_x >= 4)
|
||||
x = 2;
|
||||
int y = 0;
|
||||
if (pixels_y >= 2)
|
||||
y = 1;
|
||||
if (pixels_y >= 4)
|
||||
y = 2;
|
||||
return fragment_sizes[x][y];
|
||||
}
|
||||
|
||||
void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
const std::array<wivrn::to_headset::foveation_parameter, 2> & foveation,
|
||||
std::span<wivrn::blitter::output> inputs,
|
||||
@@ -410,14 +342,13 @@ void stream_defoveator::defoveate(vk::raii::CommandBuffer & command_buffer,
|
||||
for (auto [ix, n_out_x]: utils::enumerate_range(px))
|
||||
{
|
||||
const int ratio_x = std::abs(n_ratio_x - int(ix)) + 1;
|
||||
glm::uvec2 rate = glm::uvec2(shading_rate(ratio_x, ratio_y), 0);
|
||||
*vertices++ = {
|
||||
.position = out * out_pixel_size,
|
||||
.uv = in | rate,
|
||||
.uv = in,
|
||||
};
|
||||
*vertices++ = {
|
||||
.position = (out + glm::vec2(0, n_out_y * ratio_y)) * out_pixel_size,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)) | rate,
|
||||
.uv = (in + glm::uvec2(0, n_out_y)),
|
||||
};
|
||||
in.x += n_out_x;
|
||||
out.x += n_out_x * ratio_x;
|
||||
|
||||
@@ -49,13 +49,6 @@ class stream_defoveator
|
||||
pipeline_t pipeline_rgb[view_count];
|
||||
pipeline_t pipeline_a[view_count];
|
||||
|
||||
// Allowed sizes for variable shading rate
|
||||
// indices are for x, y
|
||||
// 0 is 1 pixel
|
||||
// 1 is 2 or 3 pixels
|
||||
// 2 is 4 pixels or more
|
||||
uint32_t fragment_sizes[3][3] = {};
|
||||
|
||||
// Destination images
|
||||
std::vector<vk::Image> output_images;
|
||||
std::vector<vk::raii::ImageView> output_image_views;
|
||||
@@ -65,7 +58,6 @@ class stream_defoveator
|
||||
void ensure_vertices(size_t num_vertices);
|
||||
vertex * get_vertices(size_t view);
|
||||
|
||||
uint32_t shading_rate(int pixels_x, int pixels_y);
|
||||
pipeline_t & ensure_pipeline(size_t view, vk::Sampler rgb, vk::Sampler a);
|
||||
|
||||
public:
|
||||
|
||||
@@ -160,57 +160,6 @@ void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std
|
||||
metrics_offset = (metrics_offset + 1) % global_metrics.size();
|
||||
}
|
||||
|
||||
// TODO move in separate file, factorize with lobby_gui.cpp
|
||||
static bool RadioButtonWithoutCheckBox(const std::string & label, bool active, ImVec2 size_arg)
|
||||
{
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext & g = *GImGui;
|
||||
const ImGuiStyle & style = g.Style;
|
||||
const ImGuiID id = window->GetID(label.c_str());
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(label.c_str(), NULL, true);
|
||||
|
||||
const ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ImGui::ItemSize(bb, style.FramePadding.y);
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
ImGuiCol_ col;
|
||||
if ((held && hovered) || active)
|
||||
col = ImGuiCol_ButtonActive;
|
||||
else if (hovered)
|
||||
col = ImGuiCol_ButtonHovered;
|
||||
else
|
||||
col = ImGuiCol_Button;
|
||||
|
||||
ImGui::RenderNavHighlight(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
|
||||
|
||||
ImVec2 TextAlign{0, 0.5f};
|
||||
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label.c_str(), NULL, &label_size, TextAlign, &bb);
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label.c_str(), g.LastItemData.StatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
static bool RadioButtonWithoutCheckBox(const std::string & label, T & v, U v_button, ImVec2 size_arg)
|
||||
{
|
||||
const bool pressed = RadioButtonWithoutCheckBox(label, v == v_button, size_arg);
|
||||
if (pressed)
|
||||
v = v_button;
|
||||
return pressed;
|
||||
}
|
||||
|
||||
void scenes::stream::gui_performance_metrics()
|
||||
{
|
||||
const ImGuiStyle & style = ImGui::GetStyle();
|
||||
@@ -603,6 +552,85 @@ void scenes::stream::gui_foveation_settings(float predicted_display_period)
|
||||
});
|
||||
}
|
||||
|
||||
void scenes::stream::gui_applications()
|
||||
{
|
||||
auto now = instance.now();
|
||||
if (now - running_application_req > 1'000'000'000)
|
||||
{
|
||||
running_application_req = now;
|
||||
network_session->send_control(from_headset::get_running_applications{});
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, {10, 10});
|
||||
ImGui::PushFont(nullptr, constants::gui::font_size_large);
|
||||
CenterTextH(_("Running XR applications:"));
|
||||
ImGui::PopFont();
|
||||
auto apps = running_applications.lock();
|
||||
ImVec2 button_size(ImGui::GetWindowSize().x - ImGui::GetCursorPosX() - 20, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(ImGui::GetStyle().ItemSpacing.x, 20));
|
||||
ImGui::Spacing();
|
||||
std::ranges::sort(apps->applications, [](auto & l, auto & r) {
|
||||
if (l.overlay == r.overlay)
|
||||
return false;
|
||||
return r.overlay;
|
||||
});
|
||||
bool overlay = false;
|
||||
for (const auto & app: apps->applications)
|
||||
{
|
||||
if (app.overlay and not overlay)
|
||||
{
|
||||
ImGui::Separator();
|
||||
CenterTextH(_S("Overlays"));
|
||||
overlay = true;
|
||||
}
|
||||
int colors = 1;
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32_BLACK_TRANS);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 20));
|
||||
if (app.active or app.overlay)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32_BLACK_TRANS);
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32_BLACK_TRANS);
|
||||
colors += 2;
|
||||
}
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
const bool clicked = RadioButtonWithoutCheckBox(
|
||||
std::format("{}{}##{}", app.active ? ICON_FA_CHEVRON_RIGHT " " : " ", app.name, app.id).c_str(),
|
||||
app.active,
|
||||
button_size);
|
||||
if (clicked and not(app.active or app.overlay))
|
||||
{
|
||||
network_session->send_control(from_headset::set_active_application{.id = app.id});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
}
|
||||
ImGui::PopStyleColor(colors);
|
||||
ImGui::PopStyleVar(2);
|
||||
|
||||
ImGui::SameLine();
|
||||
auto right = ImGui::GetWindowSize().x;
|
||||
ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 10);
|
||||
ImGui::SetCursorPosX(right - ImGui::CalcTextSize(ICON_FA_XMARK).x - ImGui::GetStyle().FramePadding.x - 40);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
if (ImGui::Button(std::format(ICON_FA_XMARK "##{}", app.id).c_str()))
|
||||
network_session->send_control(from_headset::stop_application{.id = app.id});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
imgui_ctx->tooltip(_S("Request to quit, may be ignored by the application"));
|
||||
}
|
||||
|
||||
auto btn = _("Start");
|
||||
ImGui::SetCursorPos(ImGui::GetWindowSize() - ImGui::CalcTextSize(btn.c_str()) - ImVec2(50, 50));
|
||||
if (ImGui::Button(btn.c_str()))
|
||||
gui_status = gui_status::application_launcher;
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
ImGui::PopStyleVar(3);
|
||||
}
|
||||
|
||||
// Return the vector v such that dot(v, x) > 0 iff x is on the side where the composition layer is visible
|
||||
static glm::vec4 compute_ray_limits(const XrPosef & pose, float margin = 0)
|
||||
{
|
||||
@@ -642,6 +670,8 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
break;
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::applications:
|
||||
case gui_status::application_launcher:
|
||||
break;
|
||||
}
|
||||
imgui_ctx->set_controllers_enabled(interactable);
|
||||
@@ -662,6 +692,8 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
if (gui_status != last_gui_status)
|
||||
{
|
||||
last_gui_status = gui_status;
|
||||
if (is_gui_interactable())
|
||||
next_gui_status = gui_status;
|
||||
gui_status_last_change = predicted_display_time;
|
||||
|
||||
// Override session state if the GUI is interactable
|
||||
@@ -708,6 +740,8 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
case gui_status::compact:
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::applications:
|
||||
case gui_status::application_launcher:
|
||||
imgui_ctx->layers()[0].orientation = head_position->second * head_gui_orientation;
|
||||
imgui_ctx->layers()[0].position = head_position->first + M * head_gui_position;
|
||||
break;
|
||||
@@ -748,11 +782,18 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
|
||||
case gui_status::stats:
|
||||
case gui_status::settings:
|
||||
case gui_status::applications:
|
||||
ImGui::SetNextWindowPos(margin_around_window);
|
||||
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size - margin_around_window * 2);
|
||||
always_auto_resize = false;
|
||||
display_tabs = true;
|
||||
break;
|
||||
case gui_status::application_launcher:
|
||||
ImGui::SetNextWindowPos(margin_around_window);
|
||||
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size - margin_around_window * 2);
|
||||
always_auto_resize = false;
|
||||
display_tabs = false;
|
||||
break;
|
||||
}
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 0);
|
||||
@@ -804,6 +845,17 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
case gui_status::foveation_settings:
|
||||
gui_foveation_settings(predicted_display_period * 1.e-9f);
|
||||
break;
|
||||
|
||||
case gui_status::applications:
|
||||
ImGui::SetCursorPos({tab_width + 20, 20});
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
gui_applications();
|
||||
ImGui::EndChild();
|
||||
break;
|
||||
|
||||
case gui_status::application_launcher:
|
||||
if (apps.draw_gui(*imgui_ctx, _("Cancel")) != app_launcher::None)
|
||||
gui_status = gui_status::applications;
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_FrameRounding
|
||||
@@ -822,6 +874,9 @@ void scenes::stream::draw_gui(XrTime predicted_display_time, XrDuration predicte
|
||||
RadioButtonWithoutCheckBox(ICON_FA_GEARS " " + _("Settings"), gui_status, gui_status::settings, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
RadioButtonWithoutCheckBox(ICON_FA_LIST " " + _("Applications"), gui_status, gui_status::applications, {tab_width, 0});
|
||||
imgui_ctx->vibrate_on_hover();
|
||||
|
||||
int n_items_at_end = 4;
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - n_items_at_end * ImGui::GetCurrentContext()->FontSize - (n_items_at_end * 2) * style.FramePadding.y - (n_items_at_end - 1) * style.ItemSpacing.y - style.WindowPadding.y);
|
||||
|
||||
|
||||
@@ -106,31 +106,19 @@ void scenes::stream::send_feedback(const wivrn::from_headset::feedback & feedbac
|
||||
}
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::application_list && apps)
|
||||
void scenes::stream::operator()(to_headset::application_list && l)
|
||||
{
|
||||
std::ranges::sort(apps.applications, [](auto & l, auto & r) {
|
||||
return una::casesens::collate_utf8(l.name, r.name) < 0;
|
||||
});
|
||||
|
||||
auto locked = applications.lock();
|
||||
|
||||
locked->clear();
|
||||
locked->reserve(apps.applications.size());
|
||||
for (const auto & i: apps.applications)
|
||||
{
|
||||
locked->push_back(app{
|
||||
.id = std::move(i.id),
|
||||
.name = std::move(i.name),
|
||||
});
|
||||
}
|
||||
apps(std::move(l));
|
||||
}
|
||||
|
||||
void scenes::stream::operator()(to_headset::application_icon && icon)
|
||||
{
|
||||
auto locked = applications.lock();
|
||||
apps(std::move(icon));
|
||||
}
|
||||
|
||||
if (auto it = std::ranges::find(*locked, icon.id, &app::id); it != locked->end())
|
||||
it->image = std::move(icon.image);
|
||||
void scenes::stream::operator()(to_headset::running_applications && apps)
|
||||
{
|
||||
*running_applications.lock() = std::move(apps);
|
||||
}
|
||||
|
||||
void scenes::stream::start_application(std::string appid)
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
// kate: hl glsl
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_clipping = 4;
|
||||
const int nb_texcoords = 2;
|
||||
|
||||
const bool use_pbr = false;
|
||||
const bool use_normal_maps = false;
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
mat4 view[nb_views];
|
||||
vec4 light_position;
|
||||
vec4 ambient_color;
|
||||
vec4 light_color;
|
||||
} scene;
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
{
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
vec4 clipping_plane[nb_clipping];
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 2) uniform joints_ubo
|
||||
{
|
||||
mat4 joint_matrices[32];
|
||||
} joints;
|
||||
|
||||
layout(set = 0, binding = 3) uniform sampler2D base_color_texture;
|
||||
layout(set = 0, binding = 4) uniform sampler2D metallic_roughness_texture;
|
||||
layout(set = 0, binding = 5) uniform sampler2D occlusion_texture;
|
||||
layout(set = 0, binding = 6) uniform sampler2D emissive_texture;
|
||||
layout(set = 0, binding = 7) uniform sampler2D normal_map_texture;
|
||||
layout(set = 0, binding = 8) uniform material_ubo
|
||||
{
|
||||
vec4 base_color_factor;
|
||||
vec4 base_emissive_factor;
|
||||
float metallic_factor;
|
||||
float roughness_factor;
|
||||
float occlusion_strength;
|
||||
float normal_scale;
|
||||
float alpha_cutoff;
|
||||
|
||||
int base_color_texcoord;
|
||||
int metallic_roughness_texcoord;
|
||||
int occlusion_texcoord;
|
||||
int emissive_texcoord;
|
||||
int normal_texcoord;
|
||||
} material;
|
||||
|
||||
const float dither_pattern[4][4] = {
|
||||
{ 0.0f, 0.5f, 0.125f, 0.625f},
|
||||
{ 0.75f, 0.25f, 0.875f, 0.375f},
|
||||
{ 0.1875f, 0.6875f, 0.0625f, 0.5625},
|
||||
{ 0.9375f, 0.4375f, 0.8125f, 0.3125}
|
||||
};
|
||||
vec4 one_over_d_linear_to_srgb(vec4 color)
|
||||
{
|
||||
/* Linear to sRGB is:
|
||||
*
|
||||
* if (x <= 0.0031308)
|
||||
* return 12.92 * x;
|
||||
* else
|
||||
* return 1.055*pow(x, 1.0 / 2.4) - 0.055;
|
||||
*
|
||||
* Its derivative is:
|
||||
* if (x <= 0.0031308)
|
||||
* return 12.92;
|
||||
* else
|
||||
* return (1.055 / 2.4) * pow(x, -1.4 / 2.4);
|
||||
*
|
||||
*/
|
||||
|
||||
// vec3 tmp1 = vec3(1.0 / 12.92);
|
||||
// vec3 tmp2 = (2.4 / 1.055) * pow(color.rgb, vec3(1.4 / 2.4));
|
||||
|
||||
vec3 tmp1 = vec3(0.0773993808049);
|
||||
vec3 tmp2 = 2.27488151659 * pow(color.rgb, vec3(0.583333333333));
|
||||
|
||||
// Alpha is not converted to sRGB
|
||||
return vec4(mix(tmp1, tmp2, vec3(greaterThan(color.rgb, vec3(0.0031308, 0.0031308, 0.0031308)))), 1.0);
|
||||
}
|
||||
|
||||
vec4 dither(ivec2 frag_coord, vec4 colour)
|
||||
{
|
||||
ivec2 tmp = frag_coord % 4;
|
||||
float dither_thd = 1.0f - dither_pattern[tmp.x][tmp.y];
|
||||
|
||||
return colour + one_over_d_linear_to_srgb(colour) * vec4(dither_thd, dither_thd, dither_thd, 0) / 255.0f;
|
||||
}
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
#define VS_TO_FS in
|
||||
#else
|
||||
#define VS_TO_FS out
|
||||
#endif
|
||||
|
||||
// Vertex-to-fragment
|
||||
layout(location = 0) VS_TO_FS vec3 normal;
|
||||
layout(location = 1) VS_TO_FS vec4 tangent;
|
||||
layout(location = 2) VS_TO_FS vec4 frag_pos;
|
||||
layout(location = 3) VS_TO_FS vec4 light_pos;
|
||||
layout(location = 4) VS_TO_FS vec2 texcoord[nb_texcoords];
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 450
|
||||
|
||||
#extension GL_EXT_multiview : enable
|
||||
|
||||
layout (constant_id = 0) const int nb_texcoords = 2;
|
||||
layout (constant_id = 1) const bool dithering = true;
|
||||
layout (constant_id = 2) const bool alpha_cutout = false;
|
||||
layout (constant_id = 3) const bool skinning = false;
|
||||
|
||||
const int nb_views = 2;
|
||||
const int nb_clipping = 4;
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
mat4 view[nb_views];
|
||||
vec4 light_position;
|
||||
vec4 ambient_color;
|
||||
vec4 light_color;
|
||||
} scene;
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
{
|
||||
mat4 model;
|
||||
mat4 modelview[nb_views];
|
||||
mat4 modelviewproj[nb_views];
|
||||
vec4 clipping_plane[nb_clipping];
|
||||
} mesh;
|
||||
|
||||
layout(set = 0, binding = 2) uniform joints_ubo
|
||||
{
|
||||
mat4 joint_matrices[32];
|
||||
} joints;
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
layout(set = 0, binding = 3) uniform sampler2D base_color;
|
||||
layout(set = 0, binding = 4) uniform sampler2D metallic_roughness;
|
||||
layout(set = 0, binding = 5) uniform sampler2D occlusion;
|
||||
layout(set = 0, binding = 6) uniform sampler2D emissive;
|
||||
layout(set = 0, binding = 7) uniform sampler2D normal_map;
|
||||
layout(set = 0, binding = 8) uniform material_ubo
|
||||
{
|
||||
vec4 base_color_factor;
|
||||
vec4 base_emissive_factor;
|
||||
float metallic_factor;
|
||||
float roughness_factor;
|
||||
float occlusion_strength;
|
||||
float normal_scale;
|
||||
float alpha_cutoff;
|
||||
|
||||
int base_color_texcoord;
|
||||
int metallic_roughness_texcoord;
|
||||
int occlusion_texcoord;
|
||||
int emissive_texcoord;
|
||||
int normal_texcoord;
|
||||
} material;
|
||||
#endif
|
||||
|
||||
// Vertex input
|
||||
#ifdef VERT_SHADER
|
||||
layout(location = 0) in vec4 in_position;
|
||||
layout(location = 1) in vec4 in_color;
|
||||
#endif
|
||||
|
||||
// Vertex-to-fragment
|
||||
#ifdef VERT_SHADER
|
||||
#define VERT_TO_FRAG out
|
||||
#else
|
||||
#define VERT_TO_FRAG in
|
||||
#endif
|
||||
|
||||
layout(location = 0) VERT_TO_FRAG vec4 color;
|
||||
|
||||
// Shader code
|
||||
#ifdef VERT_SHADER
|
||||
out gl_PerVertex
|
||||
{
|
||||
vec4 gl_Position;
|
||||
};
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mesh.modelviewproj[gl_ViewIndex] * in_position;
|
||||
color = in_color;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
layout(location = 0) out vec4 out_color;
|
||||
layout(early_fragment_tests) in;
|
||||
void main()
|
||||
{
|
||||
out_color = color;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2022 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2022 Patrick Nicolas <patricknicolas@laposte.net>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#version 450
|
||||
|
||||
#extension GL_GOOGLE_include_directive : require
|
||||
|
||||
#include "common.glsl.inc"
|
||||
#include "pbr.glsl.inc"
|
||||
|
||||
// Fragment output
|
||||
layout(location = 0) out vec4 out_color;
|
||||
layout(early_fragment_tests) in;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 albedo = material.base_color_factor * texture(base_color_texture, texcoord[0]);
|
||||
vec3 emissive_color = (material.base_emissive_factor * texture(emissive_texture, texcoord[0])).rgb;
|
||||
|
||||
vec3 normal_unit;
|
||||
|
||||
if (use_normal_maps)
|
||||
{
|
||||
vec3 sampled_normal = normalize(vec3(material.normal_scale, material.normal_scale, 1) * (texture(normal_map_texture, texcoord[0]).xyz * 2 - 1));
|
||||
|
||||
// glTF spec §3.7.2.1
|
||||
vec3 bitangent = cross(normal, tangent.xyz) * tangent.w;
|
||||
mat3 TBN = mat3(tangent.xyz, bitangent, normal); // View space to tangent space?
|
||||
|
||||
// Normal in view space
|
||||
normal_unit = TBN * sampled_normal;
|
||||
}
|
||||
else
|
||||
normal_unit = normalize(normal);
|
||||
|
||||
vec3 light_dir = normalize(light_pos.xyz - frag_pos.xyz * light_pos.w);
|
||||
vec3 view_dir = normalize(-frag_pos.xyz);
|
||||
|
||||
if (use_pbr)
|
||||
{
|
||||
float ao = 1 + material.occlusion_strength * (texture(occlusion_texture, texcoord[0]).r - 1);
|
||||
vec4 mr = texture(metallic_roughness_texture, texcoord[0]);
|
||||
|
||||
vec3 half_vec = normalize(light_dir + view_dir);
|
||||
|
||||
float metallic = material.metallic_factor * mr.b;
|
||||
float roughness = material.roughness_factor * mr.g;
|
||||
|
||||
vec3 light_colour = scene.light_color.rgb;
|
||||
float attenuation = 1;
|
||||
vec3 radiance =
|
||||
per_light_radiance(albedo.rgb, metallic, roughness, light_colour, light_dir, normal_unit, view_dir, half_vec, attenuation) +
|
||||
vec3(scene.ambient_color) * albedo.rgb * ao;
|
||||
|
||||
vec3 tmp = radiance + emissive_color;
|
||||
|
||||
out_color = vec4(tmp / (tmp + 1), albedo.a);
|
||||
}
|
||||
else
|
||||
{
|
||||
out_color = vec4(emissive_color + albedo.rgb * (max(0, dot(normal_unit, light_dir)) * scene.light_color.rgb + scene.ambient_color.rgb), albedo.a);
|
||||
}
|
||||
}
|
||||