-
Notifications
You must be signed in to change notification settings - Fork 1
/
openvr_api_public.cpp
217 lines (177 loc) · 5.81 KB
/
openvr_api_public.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
//========= Copyright Valve Corporation ============//
#define VR_API_EXPORT 1
#include "openvr.h"
#include "hmderrors_public.h"
#include <mutex>
#include <string.h>
#include <iostream>
#include <vector>
//for the compositor
#include <SDL.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/string_cast.hpp>
#include <glm/gtc/matrix_inverse.hpp>
//TODO what is this
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
bool fulldbg = false;
#ifdef BUILD_OSVR
#include "openvr_osvr.h"
#endif
#ifdef BUILD_OPENHMD
#include "openvr_openhmd.h"
#endif
using vr::EVRInitError;
using vr::IVRSystem;
using vr::VRInitError_None;
namespace vr
{
static void *g_pVRModule = NULL;
static std::recursive_mutex g_mutexSystem;
typedef void* (*VRClientCoreFactoryFn)(const char *pInterfaceName, int *pReturnCode);
static uint32_t g_nVRToken = 0;
uint32_t VR_GetInitToken()
{
if (fulldbg) printf("inittoken requested\n");
return g_nVRToken;
}
EVRInitError VR_LoadHmdSystemInternal();
void CleanupInternalInterfaces();
uint32_t VR_InitInternal2( EVRInitError *peError, vr::EVRApplicationType eApplicationType, const char *pStartupInfo )
{
printf("initinternal2\n");
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if ( peError )
*peError = VRInitError_None;
return ++g_nVRToken;
}
VR_INTERFACE uint32_t VR_CALLTYPE VR_InitInternal( EVRInitError *peError, EVRApplicationType eApplicationType );
uint32_t VR_InitInternal( EVRInitError *peError, vr::EVRApplicationType eApplicationType )
{
printf("initinternal\n");
return VR_InitInternal2( peError, eApplicationType, nullptr );
}
void VR_ShutdownInternal()
{
printf("shutdowninternal\n");
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
//context->free();
++g_nVRToken;
}
EVRInitError VR_LoadHmdSystemInternal()
{
printf("pretending to load hmdsysteminternal...\n");
return VRInitError_None;
}
bool startsWith(const char *pre, const char *str)
{
size_t lenpre = strlen(pre),
lenstr = strlen(str);
return lenstr < lenpre ? false : strncmp(pre, str, lenpre) == 0;
}
IVRSystem *ivrsystem;
IVRCompositor *ivrcompositor;
IVRRenderModels *ivrrendermodels;
IVROverlay *ivroverlay;
char* backend;
void *VR_GetGenericInterface(const char *pchInterfaceVersion, EVRInitError *peError)
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
if (!ivrsystem) {
backend = getenv ("OPENVR_BACKEND");
if (backend==NULL) {
printf ("Choose backend OSVR or OPENHMD with OPENVR_BACKEND=[OSVR|OPENHMD]\n");
#if defined(BUILD_OSVR)
backend = strdup("OSVR"); // default
#elif defined(BUILD_OPENHMD)
backend = strdup("OPENHMD");
#else
#error "No backend built!"
#endif
}
printf ("Using backend: %s\n", backend);
if (strcmp(backend, "OSVR") == 0) {
#if !(defined(BUILD_OSVR))
printf("Error: OSVR backend chosen but not built!\n");
return nullptr;
#else
ivrsystem = new OSVRHMDIVRSystem(); //make sure ivrsystem is always going to be initialized first so implementations can do their base init here
ivrcompositor = new OSVRHMDCompositor();
ivrrendermodels = new OSVRHMDRenderModels();
ivroverlay = new OSVRHMDOverlay();
#endif
} else if (strcmp(backend, "OPENHMD") == 0) {
#if !(defined(BUILD_OPENHMD))
printf("Error: OpenHMD backend chosen but not built!\n");
return nullptr;
#else
ivrsystem = new OpenHMDIVRSystem();
ivrcompositor = new OpenHMDCompositor();
ivrrendermodels = new OpenHMDRenderModels();
ivroverlay = new OpenHMDOverlay();
#endif
}
}
printf("Creating %s impl of interface: %s\n", backend, pchInterfaceVersion);
*peError = VRInitError_None;
if (startsWith("IVRSystem_", pchInterfaceVersion)) {
return ivrsystem;
} else if (startsWith("IVRRenderModels_", pchInterfaceVersion)) {
return ivrrendermodels;
} else if (startsWith("IVRCompositor_", pchInterfaceVersion)) {
return ivrcompositor;
} else if (startsWith("IVROverlay_", pchInterfaceVersion)) {
return ivroverlay;
} else {
printf("interface %s failed\n", pchInterfaceVersion);
//ohmd_ctx_destroy(ctx);
*peError = VRInitError_Unknown;
return nullptr;
}
}
bool VR_IsInterfaceVersionValid(const char *pchInterfaceVersion)
{
if (fulldbg) printf("interfaceversion %s is valid requested, confirming..\n", pchInterfaceVersion);
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
return true;
}
bool VR_IsHmdPresent()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
printf("IsHmdPresent requested, confirming..\n");
return true;
}
/** Returns true if the OpenVR runtime is installed. */
bool VR_IsRuntimeInstalled()
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
printf("Runtime installed requested, confirming..\n");
return true;
}
/** Returns where OpenVR runtime is installed. */
const char *VR_RuntimePath()
{
printf("Runtime path requested, pretending \"\"\n");
return "";
}
/** Returns the symbol version of an HMD error. */
const char *VR_GetVRInitErrorAsSymbol( EVRInitError error )
{
std::lock_guard<std::recursive_mutex> lock( g_mutexSystem );
return GetIDForVRInitError( error );
}
/** Returns the english string version of an HMD error. */
const char *VR_GetVRInitErrorAsEnglishDescription( EVRInitError error )
{
return GetEnglishStringForHmdError( error );
}
VR_INTERFACE const char *VR_CALLTYPE VR_GetStringForHmdError( vr::EVRInitError error );
/** Returns the english string version of an HMD error. */
const char *VR_GetStringForHmdError( EVRInitError error )
{
return VR_GetVRInitErrorAsEnglishDescription( error );
}
}