Allow user-provided ovrSession via PlatformData

This commit is contained in:
Colby Klein
2016-10-13 12:35:55 -07:00
parent f67b9d9892
commit e382bc4b64
4 changed files with 34 additions and 9 deletions

View File

@@ -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.

View File

@@ -39,6 +39,7 @@ typedef struct bgfx_platform_data
void* context;
void* backBuffer;
void* backBufferDS;
void* session;
} bgfx_platform_data_t;

View File

@@ -26,7 +26,6 @@ namespace bgfx
struct VRDesc
{
uint64_t m_adapterLuid;
uint32_t m_deviceType;
float m_refreshRate;
VRSize m_deviceSize;

View File

@@ -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);