[Bf-blender-cvs] [d823930] HMD_viewport: Open/close HMD device based on session status

TheOnlyJoey noreply at git.blender.org
Fri Mar 18 03:07:41 CET 2016


Commit: d8239304deabd331c718afa55f78ebc9a6701ad8
Author: TheOnlyJoey
Date:   Fri Mar 18 03:06:06 2016 +0100
Branches: HMD_viewport
https://developer.blender.org/rBd8239304deabd331c718afa55f78ebc9a6701ad8

Open/close HMD device based on session status

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_ISystem.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.cpp
M	intern/ghost/intern/GHOST_OpenHMDManager.h
M	intern/ghost/intern/GHOST_System.h
M	intern/ghost/intern/GHOST_SystemX11.cpp
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index f1484a2..adeea2b 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -930,6 +930,9 @@ extern void GHOST_BeginIME(GHOST_WindowHandle windowhandle,
  */
 extern void GHOST_EndIME(GHOST_WindowHandle windowhandle);
 
+extern void GHOST_HMDopenDevice(int index);
+extern void GHOST_HMDcloseDevice(void);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/intern/ghost/GHOST_ISystem.h b/intern/ghost/GHOST_ISystem.h
index 4c48473..a6a3c86 100644
--- a/intern/ghost/GHOST_ISystem.h
+++ b/intern/ghost/GHOST_ISystem.h
@@ -40,6 +40,7 @@
 #include "GHOST_IWindow.h"
 
 class GHOST_IEventConsumer;
+class GHOST_OpenHMDManager;
 
 /**
  * \page GHOSTPage GHOST
@@ -384,6 +385,11 @@ public:
 	virtual void setNDOFDeadZone(float deadzone) = 0;
 
 	/**
+	 * \return A pointer to our OpenHMD manager.
+	 */
+	virtual GHOST_OpenHMDManager *getOpenHMDManager() const = 0;
+
+	/**
 	 * Toggles console
 	 * \param action
 	 * - 0: Hides
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index ccd7f57..1e725d7 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -38,6 +38,7 @@
 #include "GHOST_ISystem.h"
 #include "GHOST_IEvent.h"
 #include "GHOST_IEventConsumer.h"
+#include "GHOST_OpenHMDManager.h"
 #include "intern/GHOST_CallbackEventConsumer.h"
 
 GHOST_SystemHandle GHOST_CreateSystem(void)
@@ -931,3 +932,21 @@ void GHOST_EndIME(GHOST_WindowHandle windowhandle)
 }
 
 #endif  /* WITH_INPUT_IME */
+
+#ifdef WITH_OPENHMD
+
+void GHOST_HMDopenDevice(int index)
+{
+	GHOST_ISystem *system = GHOST_ISystem::getSystem();
+	GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+	ohmd->openDevice(index);
+}
+
+void GHOST_HMDcloseDevice()
+{
+	GHOST_ISystem *system = GHOST_ISystem::getSystem();
+	GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+	ohmd->closeDevice();
+}
+
+#endif
\ No newline at end of file
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.cpp b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
index e3956cd..b539c55 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.cpp
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.cpp
@@ -31,37 +31,13 @@ GHOST_OpenHMDManager::GHOST_OpenHMDManager(GHOST_System& sys)
 	  m_device(NULL),
 	  m_deviceIndex(-1)
 {
-	m_context = ohmd_ctx_create();
-	if (m_context != NULL) {
-
-		int num_devices = ohmd_ctx_probe(m_context);
-		if (num_devices > 0) {
-			m_available = true;
-
-			//can't fail?
-			m_deviceIndex = 0;
-			m_device = ohmd_list_open_device(m_context, m_deviceIndex);
-		}
-		else {
-			printf("No available devices in OpenHMD Context\n");
-
-			ohmd_ctx_destroy(m_context);
-			m_context = NULL;
-		}
-	}
-	else {
-		printf("Failed to create OpenHMD Context\n");
-	}
+	//context can be pre-created. the device can be opened later at will
+	createContext(); 
 }
 
 GHOST_OpenHMDManager::~GHOST_OpenHMDManager()
 {
-	if (m_available) {
-		ohmd_ctx_destroy(m_context);
-		m_context = NULL;
-		m_device = NULL;
-		m_available = false;
-	}
+	closeDevice();
 }
 
 bool GHOST_OpenHMDManager::processEvents()
@@ -94,9 +70,20 @@ bool GHOST_OpenHMDManager::available() const
 	return m_available;
 }
 
-bool GHOST_OpenHMDManager::setDevice(const char *requested_vendor_name, const char *requested_device_name)
+bool GHOST_OpenHMDManager::createContext()
 {
-	if (!m_available) {
+	if (m_context != NULL)
+		return true;
+
+	m_context = ohmd_ctx_create();
+	return (m_context != NULL);
+}
+
+bool GHOST_OpenHMDManager::openDevice(const char *requested_vendor_name, const char *requested_device_name)
+{
+	//create the context if it hasn't been created yet.
+	//do not check for m_available as that indicates both the context and device are valid, which isn't the case if the context isn't available
+	if (!createContext()) {
 		return false;
 	}
 
@@ -107,7 +94,7 @@ bool GHOST_OpenHMDManager::setDevice(const char *requested_vendor_name, const ch
 		const char* vendor_name = ohmd_list_gets(m_context, i, OHMD_VENDOR);
 
 		if (strcmp(device_name, requested_device_name) == 0 && strcmp(vendor_name, requested_vendor_name) == 0) {
-			success = setDevice(i);
+			success = openDevice(i);
 			break;
 		}
 	}
@@ -115,9 +102,11 @@ bool GHOST_OpenHMDManager::setDevice(const char *requested_vendor_name, const ch
 	return success;
 }
 
-bool GHOST_OpenHMDManager::setDevice(int index)
+bool GHOST_OpenHMDManager::openDevice(int index)
 {
-	if (!m_available) {
+	//create the context if it hasn't been created yet
+	//do not check for m_available as that indicates both the context and device are valid, which isn't the case if the context isn't available
+	if (!createContext()) {
 		return false;
 	}
 
@@ -126,11 +115,26 @@ bool GHOST_OpenHMDManager::setDevice(int index)
 		return false;
 	}
 
+	//can't fail to open the device
 	m_deviceIndex = index;
 	m_device = ohmd_list_open_device(m_context, index);
+	m_available = true;
 	return true;
 }
 
+void GHOST_OpenHMDManager::closeDevice()
+{
+	if (!m_available) {
+		return;
+	}
+
+	ohmd_ctx_destroy(m_context);
+	m_context = NULL;
+	m_device = NULL;
+	m_deviceIndex = -1;
+	m_available = false;
+}
+
 int GHOST_OpenHMDManager::getNumDevices() const
 {
 	if (!m_available)
diff --git a/intern/ghost/intern/GHOST_OpenHMDManager.h b/intern/ghost/intern/GHOST_OpenHMDManager.h
index 20f0537..c188938 100644
--- a/intern/ghost/intern/GHOST_OpenHMDManager.h
+++ b/intern/ghost/intern/GHOST_OpenHMDManager.h
@@ -55,14 +55,21 @@ public:
 	 *  \param requested_device_name    The exact name of the requested device.
 	 *  \return A boolean indicating success.
 	 */
-	bool setDevice(const char *requested_vendor_name, const char *requested_device_name);
+	bool openDevice(const char *requested_vendor_name, const char *requested_device_name);
 
 	/**
 	 *  Select a device by index
 	 *  \param index    The index of the requested device
-	 *  See setDevice(const char*, const char*) for more information.
+	 *  See openDevice(const char*, const char*) for more information.
 	 */
-	bool setDevice(int index);
+	bool openDevice(int index);
+
+	/** 
+	 *	Close the currently opened device (if available)
+	 *  This means no more events will be generated until another device is opened using openDevice.
+	 * 	Has no effect is available() is false.
+	 */
+	void closeDevice();
 
 	/**
 	 *  \return The number of connected devices.
@@ -70,11 +77,14 @@ public:
 	 */
 	int getNumDevices() const;
 
+	///TODO add a function to retrieve a list of connected devices, or the data of a single device by index.
+	//the data should contain at least the device name and vendor name.
+
 	/**
 	 *  \return A c-style string containing the last error as a human-readable message
 	 *  NULL is returned if available() is false.
 	 */
-	 const char *getError() const;
+	const char *getError() const;
 
 	/**
 	 *  \return A c-style string with the human-readable name of the current device.
@@ -98,121 +108,121 @@ public:
 	 * \param orientation   The absolute orientation of the device, as quaternion, in blender format (w,x,y,z)
 	 *  Nothing is written if available() is false.
 	 */
-	bool    getRotationQuat(float orientation[4]) const;
+	bool getRotationQuat(float orientation[4]) const;
 
 	/**
 	 * \param mat   A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the left eye of the HMD.
 	 *  Nothing is written if available() is false.
 	 */
-	void    getLeftEyeGLModelviewMatrix(float mat[16]) const;
+	void getLeftEyeGLModelviewMatrix(float mat[16]) const;
 
 	/**
 	 * \param mat   A "ready to use" OpenGL style 4x4 matrix with a modelview matrix for the right eye of the HMD.
 	 *  Nothing is written if available() is false.
 	 */
-	void    getRightEyeGLModelviewMatrix(float mat[16]) const;
+	void getRightEyeGLModelviewMatrix(float mat[16]) const;
 
 	/**
 	 * \param mat   A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the left eye of the HMD.
 	 *  Nothing is written if available() is false.
 	 */
-	void    getLeftEyeGLProjectionMatrix(float mat[16]) const;
+	void getLeftEyeGLProjectionMatrix(float mat[16]) const;
 
 	/**
 	 * \param mat   A "ready to use" OpenGL style 4x4 matrix with a projection matrix for the right eye of the HMD.
 	 *  Nothing is written if available() is false.
 	 */
-	void    getRightEyeGLProjectionMatrix(float mat[16]) const;
+	void getRightEyeGLProjectionMatrix(float mat[16]) const;
 
 	 /**
 	 * \param position  A 3-D vector representing the absolute position of the device, in space.
 	 *  Nothing is written if available() is false.
 	 */
-	void    getPositionVector(float position[3]) const;
+	void getPositionVector(float position[3]) const;
 
 	/**
 	 * \return  Physical width of the device screen in metres.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getScreenHorizontalSize() const;
+	float getScreenHorizontalSize() const;
 
 	/**
 	 * \return  Physical height of the device screen in metres.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getScreenVerticalSize() const;
+	float getScreenVerticalSize() const;
 
 	/**
 	 * \return  Physical separation of the device lenses in metres.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getLensHorizontalSeparation() const;
+	float getLensHorizontalSeparation() const;
 
 	/**
 	 * \return  Physical vertical position of the lenses in metres.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getLensVerticalPosition() const;
+	float getLensVerticalPosition() const;
 
 	/**
 	 * \return  Physical field of view for the left eye in degrees.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getLeftEyeFOV() const;
+	float getLeftEyeFOV() const;
 
 	/**
 	 * \return  Physical display aspect ratio for the left eye screen.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getLeftEyeAspectRatio() const;
+	float getLeftEyeAspectRatio() const;
 
 	/**
 	 * \return  Physical display aspect ratio for the left eye screen.
 	 *  -1 is returned if available() is false.
 	 */
-	float   getRightEyeFOV() const;
+	float getRightEyeFOV() const;
 
 	/**
 	 * \return  Physical display aspect ratio for the right eye screen.
 	 *  -1 is returned if avail

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list