From e382bc4b64032a18f8d2cacfaa2a4d1665a49a0c Mon Sep 17 00:00:00 2001 From: Colby Klein Date: Thu, 13 Oct 2016 12:35:55 -0700 Subject: [PATCH] Allow user-provided ovrSession via PlatformData --- include/bgfx/bgfxplatform.h | 1 + include/bgfx/c99/bgfxplatform.h | 1 + src/hmd.h | 1 - src/hmd_ovr.cpp | 40 ++++++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 9 deletions(-) diff --git a/include/bgfx/bgfxplatform.h b/include/bgfx/bgfxplatform.h index f44bb82f8..09962b6d1 100644 --- a/include/bgfx/bgfxplatform.h +++ b/include/bgfx/bgfxplatform.h @@ -51,6 +51,7 @@ namespace bgfx void* context; //!< GL context, or D3D device. void* backBuffer; //!< GL backbuffer, or D3D render target view. void* backBufferDS; //!< Backbuffer depth/stencil. + void* session; //!< ovrSession, for Oculus SDK }; /// Set platform data. diff --git a/include/bgfx/c99/bgfxplatform.h b/include/bgfx/c99/bgfxplatform.h index e1bc71538..f1b0642c3 100644 --- a/include/bgfx/c99/bgfxplatform.h +++ b/include/bgfx/c99/bgfxplatform.h @@ -39,6 +39,7 @@ typedef struct bgfx_platform_data void* context; void* backBuffer; void* backBufferDS; + void* session; } bgfx_platform_data_t; diff --git a/src/hmd.h b/src/hmd.h index f6263ca98..5832909ea 100644 --- a/src/hmd.h +++ b/src/hmd.h @@ -26,7 +26,6 @@ namespace bgfx struct VRDesc { - uint64_t m_adapterLuid; uint32_t m_deviceType; float m_refreshRate; VRSize m_deviceSize; diff --git a/src/hmd_ovr.cpp b/src/hmd_ovr.cpp index 960db032c..648f56381 100644 --- a/src/hmd_ovr.cpp +++ b/src/hmd_ovr.cpp @@ -30,11 +30,21 @@ namespace bgfx VRImplOVR::~VRImplOVR() { + if (NULL != g_platformData.session) + { + return; + } + BX_CHECK(NULL == m_session, "OVR not shutdown properly."); } bool VRImplOVR::init() { + if (NULL != g_platformData.session) + { + return true; + } + ovrResult initialized = ovr_Initialize(NULL); if (!OVR_SUCCESS(initialized)) { @@ -47,21 +57,30 @@ namespace bgfx void VRImplOVR::shutdown() { + if (NULL != g_platformData.session) + { + return; + } + ovr_Shutdown(); } void VRImplOVR::connect(VRDesc* _desc) { - ovrGraphicsLuid luid; - ovrResult result = ovr_Create(&m_session, &luid); - if (!OVR_SUCCESS(result)) + if (NULL == g_platformData.session) { - BX_TRACE("Failed to create OVR device."); - return; + ovrGraphicsLuid luid; + ovrResult result = ovr_Create(&m_session, &luid); + if (!OVR_SUCCESS(result)) + { + BX_TRACE("Failed to create OVR device."); + return; + } + } + else + { + m_session = (ovrSession)g_platformData.session; } - - BX_STATIC_ASSERT(sizeof(_desc->m_adapterLuid) >= sizeof(luid)); - memcpy(&_desc->m_adapterLuid, &luid, sizeof(luid)); ovrHmdDesc hmdDesc = ovr_GetHmdDesc(m_session); _desc->m_deviceType = hmdDesc.Type; @@ -118,6 +137,11 @@ namespace bgfx void VRImplOVR::disconnect() { + if (NULL != g_platformData.session) + { + return; + } + if (NULL != m_session) { ovr_Destroy(m_session);