Added OpenVR stub.

This commit is contained in:
Branimir Karadžić
2016-04-09 00:03:39 -07:00
parent 641d294b9d
commit 4bf0bfaf2c
5 changed files with 1530 additions and 0 deletions

1417
3rdparty/openvr/openvr_capi.h vendored Normal file

File diff suppressed because it is too large Load Diff

93
src/hmd_openvr.cpp Normal file
View File

@@ -0,0 +1,93 @@
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#include "hmd_openvr.h"
#include <openvr/openvr_capi.h>
namespace bgfx
{
#if BX_PLATFORM_WINDOWS
# define VR_CALLTYPE __cdecl
#else
# define VR_CALLTYPE
#endif
typedef uint32_t (VR_CALLTYPE *PFN_VR_INITINTERNAL)(EVRInitError* peError, EVRApplicationType eType);
typedef void (VR_CALLTYPE *PFN_VR_SHUTDOWNINTERNAL)();
typedef bool (VR_CALLTYPE *PFN_VR_ISHMDPRESENT)();
typedef void* (VR_CALLTYPE *PFN_VR_GETGENERICINTERFACE)(const char* pchInterfaceVersion, EVRInitError* peError);
typedef bool (VR_CALLTYPE *PFN_VR_ISRUNTIMEINSTALLED)();
typedef bool (VR_CALLTYPE *PFN_VR_ISINTERFACEVERSIONVALID)(const char *pchInterfaceVersion);
typedef uint32_t (VR_CALLTYPE *PFN_VR_GETINITTOKEN)();
typedef const char* (VR_CALLTYPE *PFN_VR_GETVRINITERRORASSYMBOL)(EVRInitError error);
typedef const char* (VR_CALLTYPE *PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION)(EVRInitError error);
PFN_VR_INITINTERNAL VR_InitInternal;
PFN_VR_SHUTDOWNINTERNAL VR_ShutdownInternal;
PFN_VR_ISHMDPRESENT VR_IsHmdPresent;
PFN_VR_GETGENERICINTERFACE VR_GetGenericInterface;
PFN_VR_ISRUNTIMEINSTALLED VR_IsRuntimeInstalled;
PFN_VR_ISINTERFACEVERSIONVALID VR_IsInterfaceVersionValid;
PFN_VR_GETINITTOKEN VR_GetInitToken;
PFN_VR_GETVRINITERRORASSYMBOL VR_GetVRInitErrorAsSymbol;
PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION VR_GetVRInitErrorAsEnglishDescription;
void* loadOpenVR()
{
void* openvrdll = bx::dlopen(
#if BX_PLATFORM_LINUX
"libopenvr_api.so"
#elif BX_PLATFORM_OSX
"libopenvr_api.dylib"
#else
"openvr_api.dll"
#endif // BX_PLATFORM_*
);
if (NULL != openvrdll)
{
VR_InitInternal = (PFN_VR_INITINTERNAL )bx::dlsym(openvrdll, "VR_InitInternal");
VR_ShutdownInternal = (PFN_VR_SHUTDOWNINTERNAL )bx::dlsym(openvrdll, "VR_ShutdownInternal");
VR_IsHmdPresent = (PFN_VR_ISHMDPRESENT )bx::dlsym(openvrdll, "VR_IsHmdPresent");
VR_GetGenericInterface = (PFN_VR_GETGENERICINTERFACE )bx::dlsym(openvrdll, "VR_GetGenericInterface");
VR_IsRuntimeInstalled = (PFN_VR_ISRUNTIMEINSTALLED )bx::dlsym(openvrdll, "VR_IsRuntimeInstalled");
VR_IsInterfaceVersionValid = (PFN_VR_ISINTERFACEVERSIONVALID)bx::dlsym(openvrdll, "VR_IsInterfaceVersionValid");
VR_GetInitToken = (PFN_VR_GETINITTOKEN )bx::dlsym(openvrdll, "VR_GetInitToken");
VR_GetVRInitErrorAsSymbol = (PFN_VR_GETVRINITERRORASSYMBOL )bx::dlsym(openvrdll, "VR_GetVRInitErrorAsSymbol");
VR_GetVRInitErrorAsEnglishDescription = (PFN_VR_GETVRINITERRORASENGLISHDESCRIPTION)bx::dlsym(openvrdll, "VR_GetVRInitErrorAsEnglishDescription");
if (NULL == VR_InitInternal
&& NULL == VR_ShutdownInternal
&& NULL == VR_IsHmdPresent
&& NULL == VR_GetGenericInterface
&& NULL == VR_IsRuntimeInstalled
&& NULL == VR_IsInterfaceVersionValid
&& NULL == VR_GetInitToken
&& NULL == VR_GetVRInitErrorAsSymbol
&& NULL == VR_GetVRInitErrorAsEnglishDescription)
{
bx::dlclose(openvrdll);
return NULL;
}
EVRInitError err;
uint32_t token = VR_InitInternal(&err, EVRApplicationType_VRApplication_Scene);
BX_UNUSED(token);
BX_TRACE("OpenVR: HMD is %spresent, Runtime is %sinstalled."
, VR_IsHmdPresent() ? "" : "not "
, VR_IsRuntimeInstalled() ? "" : "not "
);
}
return openvrdll;
}
void unloadOpenVR(void* _openvrdll)
{
VR_ShutdownInternal();
bx::dlclose(_openvrdll);
}
} // namespace bgfx

18
src/hmd_openvr.h Normal file
View File

@@ -0,0 +1,18 @@
/*
* Copyright 2011-2016 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
*/
#ifndef BGFX_OPENVR_H_HEADER_GUARD
#define BGFX_OPENVR_H_HEADER_GUARD
#include "bgfx_p.h"
namespace bgfx
{
void* loadOpenVR();
void unloadOpenVR(void*);
} // namespace bgfx
#endif // BGFX_OPENVR_H_HEADER_GUARD

View File

@@ -33,6 +33,7 @@ BX_PRAGMA_DIAGNOSTIC_POP()
#include "renderer_d3d.h"
#include "shader_dxbc.h"
#include "hmd_ovr.h"
#include "hmd_openvr.h"
#include "debug_renderdoc.h"
#ifndef D3DCOLOR_ARGB

View File

@@ -108,6 +108,7 @@ typedef uint64_t GLuint64;
#include "renderer.h"
#include "hmd_ovr.h"
#include "hmd_openvr.h"
#include "debug_renderdoc.h"
#ifndef GL_LUMINANCE