Просмотр исходного кода

Allow user-provided ovrSession via PlatformData

Colby Klein 9 лет назад
Родитель
Сommit
e382bc4b64
4 измененных файлов с 34 добавлено и 9 удалено
  1. 1 0
      include/bgfx/bgfxplatform.h
  2. 1 0
      include/bgfx/c99/bgfxplatform.h
  3. 0 1
      src/hmd.h
  4. 32 8
      src/hmd_ovr.cpp

+ 1 - 0
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.

+ 1 - 0
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;
 

+ 0 - 1
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;

+ 32 - 8
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);