mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-19 05:23:00 +01:00
Allow user-provided ovrSession via PlatformData
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef struct bgfx_platform_data
|
||||
void* context;
|
||||
void* backBuffer;
|
||||
void* backBufferDS;
|
||||
void* session;
|
||||
|
||||
} bgfx_platform_data_t;
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace bgfx
|
||||
|
||||
struct VRDesc
|
||||
{
|
||||
uint64_t m_adapterLuid;
|
||||
uint32_t m_deviceType;
|
||||
float m_refreshRate;
|
||||
VRSize m_deviceSize;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user