Skip to content

Commit

Permalink
Merge branch 'feature/linux'
Browse files Browse the repository at this point in the history
  • Loading branch information
maluoi committed Jun 25, 2021
2 parents d444924 + 2b78665 commit 5db56dc
Show file tree
Hide file tree
Showing 29 changed files with 2,738 additions and 158 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ install_manifest.txt
compile_commands.json
CTestTestfile.cmake
_deps
build
build
build_win
build_linux
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ set(OPENXR_loader_LIBRARY "${CMAKE_BINARY_DIR}/src/loader/Release/openxr_loader.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_subdirectory(src)

install(TARGETS openxr-explorer xrsetruntime
DESTINATION bin)

# Command to install via cmake:
# sudo cmake --install . --prefix /usr
#
# Command to uninstall afterwards:
# sudo xargs rm < install_manifest.txt
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
OpenXR Explorer is a handy debug tool for OpenXR developers. It allows for easy switching between OpenXR runtimes, shows lists of the runtime's supported extensions, and allows for inspection of common properties and enumerations, with direct links to relevant parts of the OpenXR specification!

## Download
Get the latest pre-compiled binaries over in [the releases tab](https://github.com/maluoi/openxr-explorer/releases)!
Get the latest pre-compiled Windows and Linux binaries over in [the releases tab](https://github.com/maluoi/openxr-explorer/releases)!

## Features
### Runtime Switching
Expand Down Expand Up @@ -32,16 +32,35 @@ From the root directory:
mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --build . --config Release --parallel 8
cd Release
openxr-explorer.exe
```
#### Linux
Coming soon... OpenXR Explorer was built with Linux support in mind, but it still needs a bit of work yet.
Pre-requisites
```
sudo apt-get install libxcb-keysyms1-dev libxcb1-dev libxcb-xfixes0-dev libxcb-cursor-dev libxcb-xkb-dev
```

From the root directory:
```
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --parallel 8
./openxr-explorer
# Optionally to install as a system utility
sudo cmake --install . --prefix /usr
# And to uninstall (still in build dir)
sudo xargs rm < install_manifest.txt
```

### Contributing
OpenXR is a living API, and there's new extensions coming out all the time! If you think there's something OpenXR Explorer should be displaying, then heck yeah I'll take a pull request! The application is architected to easily allow for additional information. All you need to do is add a new `display_table_t` to the `xr_tables` list, and you're good to go! See `openxr_info.cpp` for reference.

Found a new runtime manifest you think should be included by default? Add it to [xr_runtime_default.h](https://github.com/maluoi/openxr-explorer/blob/main/src/common/xr_runtime_default.h), or raise it as an Issue :)

### Relevant Stuff
If you're learning OpenXR, check out this [introductory tutorial](https://playdeck.net/blog/introduction-to-openxr) I also wrote!

Expand Down
13 changes: 13 additions & 0 deletions buildrelease.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
mkdir build_win
cd build_win
cmake ..
cmake --build . --config Release --parallel 8
cd ..
powershell "Compress-Archive -Force -Path build_win\Release\openxr-explorer.exe, build_win\Release\xrsetruntime.exe -DestinationPath openxr-explorer-win-x64.zip"

mkdir build_linux
cd build_linux
wsl cmake .. -DCMAKE_BUILD_TYPE=Release
wsl cmake --build . --parallel 8
cd ..
powershell "Compress-Archive -Force -Path build_linux\openxr-explorer, build_linux\xrsetruntime -DestinationPath openxr-explorer-linux-x64.zip"
15 changes: 15 additions & 0 deletions src/common/xr_runtime_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const char *runtime_default_list = R"_(
# If two runtimes are given the same name , the first
# valid one will be used. Items in this file are listed
# before the default items stored in the code. ~ will
# be replaced with the HOME path on Linux.
#
# Format is:
# [OS id: windows|linux] [name, no space] [path to runtime manifest, spaces are ok]
windows WMR C:\WINDOWS\system32\MixedRealityRuntime.json
windows Oculus C:\Program Files\Oculus\Support\oculus-runtime\oculus_openxr_64.json
windows SteamVR C:\Program Files (x86)\Steam\steamapps\common\SteamVR\steamxr_win64.json
windows Varjo C:\Program Files\Varjo\varjo-openxr\VarjoOpenXR.json
windows ViveOpenXR C:\Program Files (x86)\VIVE\Updater\App\ViveVRRuntime\ViveVR_openxr\ViveOpenXR.json
linux Monado /usr/share/openxr/1/openxr_monado.json
linux SteamVR ~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json)_";
19 changes: 19 additions & 0 deletions src/common/xr_runtime_template.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const char *runtime_default_template = R"_(
# If two runtimes are given the same name , the first
# valid one will be used. Items in this file are listed
# before the default items stored in the code. '~' will
# be replaced with the HOME path on Linux.
#
# You can find the default configuration list on Github
# over here: https://github.com/maluoi/openxr-explorer/blob/main/src/common/xr_runtime_default.h
# Please feel free to make a PR, or raise an issue if you
# think a path should be added as a default!
#
# Format is:
# [OS id: windows|linux] [name, no space] [path to runtime manifest, spaces are ok]
#
# Here are some examples that are listed in the defaults:
# windows SteamVR C:\Program Files (x86)\Steam\steamapps\common\SteamVR\steamxr_win64.json
# linux SteamVR ~/.steam/steam/steamapps/common/SteamVR/steamxr_linux64.json

)_";
5 changes: 0 additions & 5 deletions src/common/xr_runtimes.txt

This file was deleted.

121 changes: 108 additions & 13 deletions src/common/xrruntime.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include "xrruntime.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <sys/stat.h>
#include <windows.h>

/*** Default Runtime File ****************/

#include "xr_runtime_default.h"
#include "xr_runtime_template.h"

/*** Signatures **************************/

Expand All @@ -11,24 +18,42 @@ bool file_exists(const char *file);
/*** Code ********************************/

bool load_runtimes(const char *file, runtime_t **out_runtime_list, int32_t *out_runtime_count) {
FILE *fp = nullptr;
const char *files[3] = {};
FILE *fp = nullptr;
char *file_data = nullptr;
fp = fopen(file, "r");
if (fp == nullptr) {
printf("Couldn't load %s!\n", file);
return false;
if (fp != nullptr) {
// Get length of file
fseek(fp, 0, SEEK_END);
size_t size = ftell(fp);
fseek(fp, 0, SEEK_SET);

// Read the data
file_data = (char*)malloc(size+1);
fread (file_data, 1, size, fp);
fclose(fp);

// Stick an end string 0 character at the end in case the caller wants
// to treat it like a string
file_data[size] = 0;

files[0] = file_data;
files[1] = runtime_default_list;
} else {
files[0] = runtime_default_list;
}


runtime_t *result_list = nullptr;
int32_t result_count = 0;

char line[1024];
while (fgets(line, sizeof(line), fp)) {
int32_t file_id = 0;
const char*line = files[0];
while (files[file_id] != nullptr) {
runtime_t runtime = {};
int32_t spaces = 0;
int32_t curr = 0;
char plat_name[32] = {};
size_t len = strlen(line);
for (int32_t i=0; i<len; i+=1) {
for (int32_t i=0; ; i+=1) {
if (line[i] == ' ') {
if (spaces == 0) {
plat_name[curr] = '\0';
Expand All @@ -39,6 +64,11 @@ bool load_runtimes(const char *file, runtime_t **out_runtime_list, int32_t *out_
} else runtime.file[curr] = line[i];
spaces += 1;
} else if (line[i] == '\n') {
line = &line[i+1];
break;
} else if (line[i] == '\0') {
file_id++;
line = files[file_id];
break;
} else {
if (spaces == 0) plat_name [curr] = line[i];
Expand All @@ -51,20 +81,45 @@ bool load_runtimes(const char *file, runtime_t **out_runtime_list, int32_t *out_

if (strcmp(plat_name,"windows") == 0) runtime.platform = platform_windows;
else if (strcmp(plat_name,"linux" ) == 0) runtime.platform = platform_linux;
else continue;

result_count += 1;
result_list = (runtime_t*)realloc(result_list, sizeof(runtime_t) * result_count);
result_list[result_count-1] = runtime;
}
fclose(fp);
free(file_data);

#ifdef _WIN32
#if defined(_WIN32)
platform_ curr_platform = platform_windows;
#else
#elif defined(__linux)
platform_ curr_platform = platform_linux;

// On linux, we want to support the '~' path feature, esp. for SteamVR
const char *user = getenv("USER");
if (strcmp(user, "root") == 0)
user = getenv("SUDO_USER");

char path_tmp[1024];
for (int32_t i=0; i<result_count; i+=1) {
if (result_list[i].file[0] == '~') {
snprintf(path_tmp, sizeof(path_tmp), "/home/%s%s", user, &result_list[i].file[1]);
strcpy(result_list[i].file, path_tmp);
}
}
#endif

for (int32_t i=0; i<result_count; i+=1) {
// See if there's an earlier one
bool exists = false;
for (size_t e = 0; e < i; e++) {
if (result_list[e].present && strcmp(result_list[e].name, result_list[i].name) == 0) {
exists = true;
break;
}
}

result_list[i].present =
!exists &&
result_list[i].platform == curr_platform &&
file_exists(result_list[i].file);
}
Expand All @@ -76,6 +131,46 @@ bool load_runtimes(const char *file, runtime_t **out_runtime_list, int32_t *out_

///////////////////////////////////////////

void ensure_runtime_config_exists(const char *at_file) {
if (file_exists(at_file))
return;

FILE *fp = fopen(at_file, "w");
if (fp != nullptr) {
fputs(runtime_default_template, fp);
fclose(fp);
} else {
printf("Error creating default config file at %s!\n", at_file);
}
}

///////////////////////////////////////////

#if defined(_WIN32)

const char *runtime_config_path() {
return "runtimes.txt";
}

#elif defined(__linux__)

char runtime_config_path_str[1024];
const char *runtime_config_path() {
const char *config_root = getenv("XDG_CONFIG_HOME");
if (config_root == nullptr) {
config_root = getenv("HOME");
snprintf(runtime_config_path_str, sizeof(runtime_config_path_str), "%s/.config/openxr-explorer/runtimes.txt", config_root);
} else {
snprintf(runtime_config_path_str, sizeof(runtime_config_path_str), "%s/openxr-explorer/runtimes.txt", config_root);
}

return runtime_config_path_str;
}

#endif

///////////////////////////////////////////

bool file_exists(const char *file) {
struct stat buffer;
return (stat (file, &buffer) == 0);
Expand Down
2 changes: 2 additions & 0 deletions src/common/xrruntime.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ typedef struct runtime_t {

/*** Signatures **************************/

const char *runtime_config_path();
void ensure_runtime_config_exists(const char *at_file);
bool load_runtimes(const char *file, runtime_t **out_runtime_list, int32_t *out_runtime_count);
46 changes: 42 additions & 4 deletions src/openxrexplorer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,18 @@ project(openxr-explorer VERSION 1.0
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})

find_package(OpenXR REQUIRED)
if (UNIX)
find_package(X11 REQUIRED)
find_package(GLEW REQUIRED)
endif(UNIX)

include_directories(../common)
include_directories(${OPENXR_OPENXR_INCLUDE_DIR})
if (WIN32)
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /subsystem:windows /ENTRY:mainCRTStartup")
set(PLATFORM_FILES
resource.h
resource.rc
)
endif(WIN32)

add_executable(openxr-explorer
main.cpp
Expand All @@ -25,6 +34,8 @@ add_executable(openxr-explorer
imgui/imgui_impl_skg.cpp
imgui/imgui_impl_win32.h
imgui/imgui_impl_win32.cpp
imgui/imgui_impl_x11.h
imgui/imgui_impl_x11.cpp
imgui/imgui_internal.h
imgui/imgui_shader.hlsl.h
imgui/imgui_skg.h
Expand All @@ -35,5 +46,32 @@ add_executable(openxr-explorer
imgui/imstb_textedit.h
imgui/imstb_truetype.h
imgui/sk_gpu.h
imgui/sokol_time.h)
target_link_libraries(openxr-explorer xrruntime openxr_loader)
imgui/sokol_time.h
${PLATFORM_FILES})

target_include_directories(openxr-explorer PRIVATE
../common
${OPENXR_OPENXR_INCLUDE_DIR})

if (UNIX)
set(LINUX_LIBS
X11
X11-xcb
${X11_LIBRARIES}
xcb
xcb-xkb
xcb-randr
xcb-xfixes
xcb-cursor
xcb-keysyms
GL
GLEW
GLX )
endif(UNIX)

target_link_libraries(openxr-explorer
PUBLIC
xrruntime
PRIVATE
openxr_loader
${LINUX_LIBS})
2 changes: 1 addition & 1 deletion src/openxrexplorer/app_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void cli_print_table(const display_table_t *table) {
for (size_t i = table->header_row ? 1 : 0; i < table->cols[0].count; i++) {
printf("| ");
for (size_t c = 0; c < table->column_count; c++) {
printf("%-*s", max[c], table->cols[c][i].text ? table->cols[c][i].text : "");
printf("%-*s", (int32_t)max[c], table->cols[c][i].text ? table->cols[c][i].text : "");
if (c != table->column_count-1)
printf(" | ");
}
Expand Down
Loading

0 comments on commit 5db56dc

Please sign in to comment.