Skip to content

Commit f13340a

Browse files
committed
More project restructuring
1 parent 573ce05 commit f13340a

19 files changed

+112
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/build
1+
/build
2+
/CMakeFiles

CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION "3.7.1")
22

33
# Solution
4-
project("driver_example")
4+
project("Simple_SteamVR_Driver_Tutorial")
55
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
66

77
# Deps
@@ -25,33 +25,34 @@ endif()
2525
find_library(OPENVR_LIB openvr_api HINTS "${CMAKE_CURRENT_SOURCE_DIR}/libraries/openvr/lib/${PLATFORM_NAME}${PROCESSOR_ARCH}/" NO_DEFAULT_PATH )
2626

2727
# Example Driver
28-
set(EXAMPLE_PROJECT "driver_example")
29-
file(GLOB_RECURSE HEADERS "${EXAMPLE_PROJECT}/src/*.hpp")
30-
file(GLOB_RECURSE SOURCES "${EXAMPLE_PROJECT}/src/*.cpp")
28+
set(DRIVER_NAME "example")
29+
set(EXAMPLE_PROJECT "driver_${DRIVER_NAME}")
30+
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/driver_files/src/*.hpp")
31+
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/driver_files/src/*.cpp")
3132
add_library("${EXAMPLE_PROJECT}" SHARED "${HEADERS}" "${SOURCES}")
3233

3334
target_include_directories("${EXAMPLE_PROJECT}" PUBLIC "${OPENVR_INCLUDE_DIR}")
3435
target_include_directories("${EXAMPLE_PROJECT}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/libraries/linalg")
35-
target_include_directories("${EXAMPLE_PROJECT}" PUBLIC "${EXAMPLE_PROJECT}/src/")
36+
target_include_directories("${EXAMPLE_PROJECT}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/driver_files/src/")
3637
target_link_libraries("${EXAMPLE_PROJECT}" PUBLIC "${OPENVR_LIB}")
37-
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_PROJECT}/src" PREFIX "Header Files" FILES ${HEADERS})
38-
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE_PROJECT}/src" PREFIX "Source Files" FILES ${SOURCES})
38+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/driver_files/src" PREFIX "Header Files" FILES ${HEADERS})
39+
source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}/driver_files/src" PREFIX "Source Files" FILES ${SOURCES})
3940
set_property(TARGET "${EXAMPLE_PROJECT}" PROPERTY CXX_STANDARD 17)
4041

4142
# Copy driver assets to output folder
4243
add_custom_command(
4344
TARGET ${EXAMPLE_PROJECT}
4445
PRE_BUILD
4546
COMMAND ${CMAKE_COMMAND} -E copy_directory
46-
${CMAKE_SOURCE_DIR}/${EXAMPLE_PROJECT}/driver/
47+
${CMAKE_SOURCE_DIR}/driver_files/driver/
4748
$<TARGET_FILE_DIR:${EXAMPLE_PROJECT}>
4849
)
4950

5051
# Copy dll to output folder
5152
add_custom_command(
5253
TARGET ${EXAMPLE_PROJECT}
53-
POST_BUILD
54+
POST_BUILD
5455
COMMAND ${CMAKE_COMMAND} -E copy
5556
$<TARGET_FILE:${EXAMPLE_PROJECT}>
56-
$<TARGET_FILE_DIR:${EXAMPLE_PROJECT}>/${EXAMPLE_PROJECT}/bin/${PLATFORM_NAME}${PROCESSOR_ARCH}/$<TARGET_FILE_NAME:${EXAMPLE_PROJECT}>
57+
$<TARGET_FILE_DIR:${EXAMPLE_PROJECT}>/${DRIVER_NAME}/bin/${PLATFORM_NAME}${PROCESSOR_ARCH}/$<TARGET_FILE_NAME:${EXAMPLE_PROJECT}>
5758
)

README.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Simple OpenVR Driver Tutorial
2+
I created this driver as a demonstration for how to write some of the most common things a SteamVR/OpenVR driver would want to do. You will need to understand C++11 and some C++17 features at least to make the most use of this repo. It features:
3+
4+
- [Reading and writing configuration files]()
5+
- [Tracked HMD]()
6+
- [Tracked Controllers]() (todo)
7+
- [Tracked Trackers]() (todo)
8+
- [Tracking References (base stations)]() (todo)
9+
10+
## Building
11+
- Clone the project and submodules
12+
- `git clone --recursive https://github.com/terminal29/Simple-OpenVR-Driver-Tutorial.git`
13+
- Build project with CMake
14+
- `cd Simple-OpenVR-Driver-Tutorial && cmake .`
15+
- Open project with Visual Studio and hit build
16+
- Driver folder structure and files will be copied to the output folder as `example`.
17+
18+
## Installation
19+
20+
There are two ways to "install" this plugin:
21+
22+
- Find your SteamVR driver directory, which should be at:
23+
`C:\Program Files (x86)\Steam\steamapps\common\SteamVR\drivers`
24+
and copy the `example` directory from the project's build directory into the SteamVR drivers directory. Your folder structure should look something like this:
25+
26+
![Drivers folder structure](https://i.imgur.com/hOsDk1H.png)
27+
or
28+
29+
- Navigate to `C:\Users\<Username>\AppData\Local\openvr` and find the `openvrpaths.vrpath` file. Open this file with your text editor of choice, and under `"external_drivers"`, add another entry with the location of the `example` folder. For example mine looks like this after adding the entry:
30+
31+
```json
32+
{
33+
"config" :
34+
[
35+
"C:\\Program Files (x86)\\Steam\\config",
36+
"c:\\program files (x86)\\steam\\config"
37+
],
38+
"external_drivers" :
39+
[
40+
"C:\\Users\\<Username>\\Documents\\Programming\\c++\\Simple-OpenVR-Driver-Tutorial\\build\\Debug\\example"
41+
],
42+
"jsonid" : "vrpathreg",
43+
"log" :
44+
[
45+
"C:\\Program Files (x86)\\Steam\\logs",
46+
"c:\\program files (x86)\\steam\\logs"
47+
],
48+
"runtime" :
49+
[
50+
"C:\\Program Files (x86)\\Steam\\steamapps\\common\\SteamVR"
51+
],
52+
"version" : 1
53+
}
54+
```
55+
56+
## Debugging
57+
Debugging SteamVR is not as simple as it seems because of the startup procedure it uses. The SteamVR ecosystem consists of a couple programs:
58+
59+
- **vrserver**: the driver host
60+
- **vrcompositor**: the render engine
61+
- **vrmonitor**: the popup that displays status information
62+
- **vrdashboard**: the VR menu/overlay
63+
- **vrstartup**: a program to start everything up
64+
65+
To debug effectively in Visual Studio, you can use an extension called [Microsoft Child Process Debugging Power Tool](https://marketplace.visualstudio.com/items?itemName=vsdbgplat.MicrosoftChildProcessDebuggingPowerTool) and enable debugging child processes, disable debugging for all other child processes, and add `vrserver.exe` as a child process to debug as below:
66+
![Child process debugging settings](https://i.imgur.com/yDNvLMm.png)
67+
68+
Set the program the project should run in debug mode to **vrstartup** (Usually located `C:\Program Files (x86)\Steam\steamapps\common\SteamVR\bin\win64\vrstartup.exe`). Now we can start up SteamVR without needing to go through Steam, and can properly startup all the other programs vrserver needs.
69+
70+
71+
## License
72+
MIT License
73+
74+
Copyright (c) 2020 Jacob Hilton (Terminal29)
75+
76+
Permission is hereby granted, free of charge, to any person obtaining a copy
77+
of this software and associated documentation files (the "Software"), to deal
78+
in the Software without restriction, including without limitation the rights
79+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
80+
copies of the Software, and to permit persons to whom the Software is
81+
furnished to do so, subject to the following conditions:
82+
83+
The above copyright notice and this permission notice shall be included in all
84+
copies or substantial portions of the Software.
85+
86+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
87+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
88+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
89+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
90+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
91+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
92+
SOFTWARE.

driver_example/src/Native/DriverFactory.cpp renamed to driver_files/src/Native/DriverFactory.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "DriverFactory.hpp"
2+
#include <thread>
23
#include <Driver/VRDriver.hpp>
4+
#include <Windows.h>
5+
#include <sstream>
36

47
static std::shared_ptr<ExampleDriver::IVRDriver> driver;
58

@@ -21,4 +24,4 @@ void* HmdDriverFactory(const char* interface_name, int* return_code) {
2124

2225
std::shared_ptr<ExampleDriver::IVRDriver> ExampleDriver::getDriver() {
2326
return driver;
24-
}
27+
}

driver_example/src/Native/DriverFactory.hpp renamed to driver_files/src/Native/DriverFactory.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@
1010
extern "C" __declspec(dllexport) void* HmdDriverFactory(const char* interface_name, int* return_code);
1111

1212
namespace ExampleDriver {
13-
extern std::shared_ptr<ExampleDriver::IVRDriver> getDriver();
13+
std::shared_ptr<ExampleDriver::IVRDriver> getDriver();
14+
15+
void launchDebugger(bool blocking = true);
1416
}

0 commit comments

Comments
 (0)