[Bf-blender-cvs] [b90f3b1] HMD_viewport: Updated OpenHMD to latest git version Now uses threading for updating the hmd, better polling rates for performance on heavy scenes/low framerates
Joey Ferwerda
noreply at git.blender.org
Wed Jun 8 16:59:26 CEST 2016
Commit: b90f3b1982dacb91abe16708742a85b0ab796b5b
Author: Joey Ferwerda
Date: Thu May 19 00:46:44 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rBb90f3b1982dacb91abe16708742a85b0ab796b5b
Updated OpenHMD to latest git version
Now uses threading for updating the hmd, better polling rates for performance on heavy scenes/low framerates
===================================================================
M extern/openhmd/include/openhmd.h
M extern/openhmd/src/drv_dummy/dummy.c
M extern/openhmd/src/drv_external/external.c
M extern/openhmd/src/drv_oculus_rift/rift.c
M extern/openhmd/src/log.h
M extern/openhmd/src/omath.c
M extern/openhmd/src/openhmd.c
M extern/openhmd/src/openhmdi.h
M extern/openhmd/src/platform-posix.c
M extern/openhmd/src/platform-win32.c
M extern/openhmd/src/platform.h
M intern/ghost/intern/GHOST_OpenHMDManager.cpp
===================================================================
diff --git a/extern/openhmd/include/openhmd.h b/extern/openhmd/include/openhmd.h
index 11c5d36..dafb806 100644
--- a/extern/openhmd/include/openhmd.h
+++ b/extern/openhmd/include/openhmd.h
@@ -140,18 +140,27 @@ typedef enum {
OHMD_DRIVER_PROPERTIES = 1,
} ohmd_data_value;
+typedef enum {
+ /** int[1] (set, default: 1): Set this to 0 to prevent OpenHMD from creating background threads to do automatic device ticking.
+ Call ohmd_update(); must be called frequently, at least 10 times per second, if the background threads are disabled. */
+ OHMD_IDS_AUTOMATIC_UPDATE = 0,
+} ohmd_int_settings;
+
/** An opaque pointer to a context structure. */
typedef struct ohmd_context ohmd_context;
/** An opaque pointer to a structure representing a device, such as an HMD. */
typedef struct ohmd_device ohmd_device;
+/** An opaque pointer to a structure representing arguments for a device. */
+typedef struct ohmd_device_settings ohmd_device_settings;
+
/**
* Create an OpenHMD context.
*
* @return a pointer to an allocated ohmd_context on success or NULL if it fails.
**/
-OHMD_APIENTRYDLL ohmd_context* OHMD_APIENTRY ohmd_ctx_create();
+OHMD_APIENTRYDLL ohmd_context* OHMD_APIENTRY ohmd_ctx_create(void);
/**
* Destroy an OpenHMD context.
@@ -177,10 +186,12 @@ OHMD_APIENTRYDLL const char* OHMD_APIENTRY ohmd_ctx_get_error(ohmd_context* ctx)
/**
* Update a context.
*
- * Performs tasks like pumping events from the device. The exact details are up to the driver
- * but try to call it quite frequently.
+ * Update the values for the devices handled by a context.
+ *
+ * If background threads are disabled, this performs tasks like pumping events from the device. The exact details
+ * are up to the driver but try to call it quite frequently.
* Once per frame in a "game loop" should be sufficient.
- * If OpenHMD is handled in a background thread, calling ohmd_ctx_update and then sleeping for 10-20 ms
+ * If OpenHMD is handled in a background thread in your program, calling ohmd_ctx_update and then sleeping for 10-20 ms
* is recommended.
*
* @param ctx The context that needs updating.
@@ -231,6 +242,46 @@ OHMD_APIENTRYDLL const char* OHMD_APIENTRY ohmd_list_gets(ohmd_context* ctx, int
OHMD_APIENTRYDLL ohmd_device* OHMD_APIENTRY ohmd_list_open_device(ohmd_context* ctx, int index);
/**
+ * Open a device with additional settings provided.
+ *
+ * Opens a device from a zero indexed enumeration index between 0 and (max - 1)
+ * where max is the number ohmd_ctx_probe returned (i.e. if ohmd_ctx_probe returns 3,
+ * valid indices are 0, 1 and 2).
+ *
+ * ohmd_ctx_probe must be called before calling ohmd_list_open_device.
+ *
+ * @param ctx A (probed) context.
+ * @param index An index, between 0 and the value returned from ohmd_ctx_probe.
+ * @param settings A pointer to a device settings struct.
+ * @return a pointer to an ohmd_device, which represents a hardware device, such as an HMD.
+ **/
+OHMD_APIENTRYDLL ohmd_device* OHMD_APIENTRY ohmd_list_open_device_s(ohmd_context* ctx, int index, ohmd_device_settings* settings);
+
+/**
+ * Specify int settings in a device settings struct.
+ *
+ * @param settings The device settings struct to set values to.
+ * @param key The specefic setting you wish to set.
+ * @param value A pointer to an int or int array (containing the expected number of elements) with the value(s) you wish to set.
+ **/
+OHMD_APIENTRYDLL ohmd_status OHMD_APIENTRY ohmd_device_settings_seti(ohmd_device_settings* settings, ohmd_int_settings key, const int* val);
+
+/**
+ * Create a device settings instance.
+ *
+ * @param ctx A pointer to a valid ohmd_context.
+ * @return a pointer to an allocated ohmd_context on success or NULL if it fails.
+ **/
+OHMD_APIENTRYDLL ohmd_device_settings* OHMD_APIENTRY ohmd_device_settings_create(ohmd_context* ctx);
+
+/**
+ * Destroy a device settings instance.
+ *
+ * @param ctx The device settings instance to destroy.
+ **/
+OHMD_APIENTRYDLL void OHMD_APIENTRY ohmd_device_settings_destroy(ohmd_device_settings* settings);
+
+/**
* Close a device.
*
* Closes a device opened by ohmd_list_open_device. Note that ohmd_ctx_destroy automatically closes any open devices
@@ -260,7 +311,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_getf(ohmd_device* device, ohmd_fl
* @param in A pointer to a float, or float array where the new value is stored.
* @return 0 on success, <0 on failure.
**/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, float* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_setf(ohmd_device* device, ohmd_float_value type, const float* in);
/**
* Get an integer value from a device.
@@ -280,7 +331,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_geti(ohmd_device* device, ohmd_in
* @param in A pointer to a int, or int array where the new value is stored.
* @return 0 on success, <0 on failure.
**/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, int* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_int_value type, const int* in);
/**
* Set an void* data value for a device.
@@ -290,7 +341,7 @@ OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_seti(ohmd_device* device, ohmd_in
* @param in A pointer to the void* casted object.
* @return 0 on success, <0 on failure.
**/
-OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, void* in);
+OHMD_APIENTRYDLL int OHMD_APIENTRY ohmd_device_set_data(ohmd_device* device, ohmd_data_value type, const void* in);
#ifdef __cplusplus
}
diff --git a/extern/openhmd/src/drv_dummy/dummy.c b/extern/openhmd/src/drv_dummy/dummy.c
index 1f81a17..2b5436e 100644
--- a/extern/openhmd/src/drv_dummy/dummy.c
+++ b/extern/openhmd/src/drv_dummy/dummy.c
@@ -38,7 +38,7 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
break;
default:
- ohmd_set_error(priv->base.ctx, "invalid type given to getf (%d)", type);
+ ohmd_set_error(priv->base.ctx, "invalid type given to getf (%ud)", type);
return -1;
break;
}
diff --git a/extern/openhmd/src/drv_external/external.c b/extern/openhmd/src/drv_external/external.c
index e0c4cad..a675e33 100644
--- a/extern/openhmd/src/drv_external/external.c
+++ b/extern/openhmd/src/drv_external/external.c
@@ -43,7 +43,7 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
return 0;
}
-static int setf(ohmd_device* device, ohmd_float_value type, float* in)
+static int setf(ohmd_device* device, ohmd_float_value type, const float* in)
{
external_priv* priv = (external_priv*)device;
@@ -138,9 +138,9 @@ ohmd_driver* ohmd_create_external_drv(ohmd_context* ctx)
}
/* external specific functions */
-static void set_external_properties(ohmd_device* device, ohmd_device_properties* props)
+/*static void set_external_properties(ohmd_device* device, ohmd_device_properties* props)
{
- external_priv* priv = (external_priv*)device;
+ external_priv* priv = (external_priv*)device;
priv->base.properties.hsize = props->hsize;
priv->base.properties.vsize = props->vsize;
@@ -150,4 +150,4 @@ static void set_external_properties(ohmd_device* device, ohmd_device_properties*
priv->base.properties.lens_vpos = props->lens_vpos;
priv->base.properties.fov = DEG_TO_RAD(props->fov);
priv->base.properties.ratio = props->ratio;
-}
+}*/
diff --git a/extern/openhmd/src/drv_oculus_rift/rift.c b/extern/openhmd/src/drv_oculus_rift/rift.c
index 4b0be16..aa98def 100644
--- a/extern/openhmd/src/drv_oculus_rift/rift.c
+++ b/extern/openhmd/src/drv_oculus_rift/rift.c
@@ -169,7 +169,7 @@ static int getf(ohmd_device* device, ohmd_float_value type, float* out)
break;
default:
- ohmd_set_error(priv->base.ctx, "invalid type given to getf (%d)", type);
+ ohmd_set_error(priv->base.ctx, "invalid type given to getf (%ud)", type);
return -1;
break;
}
diff --git a/extern/openhmd/src/log.h b/extern/openhmd/src/log.h
index 9e43fd2..87b1a37 100644
--- a/extern/openhmd/src/log.h
+++ b/extern/openhmd/src/log.h
@@ -10,7 +10,7 @@
#ifndef LOG_H
#define LOG_H
-void* ohmd_allocfn(ohmd_context* ctx, char* e_msg, size_t size);
+void* ohmd_allocfn(ohmd_context* ctx, const char* e_msg, size_t size);
#define ohmd_alloc(_ctx, _size) ohmd_allocfn(_ctx, "could not allocate " #_size " bytes of RAM @ " __FILE__ ":" OHMD_STRINGIFY(__LINE__), _size)
#ifndef LOGLEVEL
diff --git a/extern/openhmd/src/omath.c b/extern/openhmd/src/omath.c
index 6dd8339..2928e45 100644
--- a/extern/openhmd/src/omath.c
+++ b/extern/openhmd/src/omath.c
@@ -19,7 +19,7 @@ float ovec3f_get_length(const vec3f* me)
void ovec3f_normalize_me(vec3f* me)
{
- if(me->x == 0 && me->x == 0 && me->z == 0)
+ if(me->x == 0 && me->y == 0 && me->z == 0)
return;
float len = ovec3f_get_length(me);
diff --git a/extern/openhmd/src/openhmd.c b/extern/openhmd/src/openhmd.c
index ff12a1e..bca97fa 100644
--- a/extern/openhmd/src/openhmd.c
+++ b/extern/openhmd/src/openhmd.c
@@ -12,7 +12,10 @@
#include <string.h>
#include <stdio.h>
-ohmd_context* OHMD_APIENTRY ohmd_ctx_create()
+// Running automatic updates at 144 Hz
+#define AUTOMATIC_UPDATE_SLEEP (1.0 / 1000.0)
+
+ohmd_context* OHMD_APIENTRY ohmd_ctx_create(void)
{
ohmd_context* ctx = calloc(1, sizeof(ohmd_context));
if(!ctx){
@@ -34,11 +37,15 @@ ohmd_context* OHMD_APIENTRY ohmd_ctx_create()
// add dummy driver last to make it the lowest priority
ctx->drivers[ctx->num_drivers++] = ohmd_create_dummy_drv(ctx);
+ ctx->update_request_quit = false;
+
return ctx;
}
void OHMD_APIENTRY ohmd_ctx_destroy(ohmd_context* ctx)
{
+ ctx->update_request_quit = true;
+
for(int i = 0; i < ctx->num_active_devices; i++){
ctx->active_devices[i]->close(ctx->active_devices[i]);
}
@@ -47,13 +54,26 @@ void OHMD_APIENTRY ohmd_ctx_destroy(ohmd_context* ctx)
ctx->drivers[i]->destroy(ctx->drivers[i]);
}
+ if(ctx->update_thread){
+ ohmd_destroy_thread(ctx->update_thread);
+ ohmd_destroy_mutex(ctx->update_mutex);
+ }
+
free(ctx);
}
void OHMD_APIENTRY ohmd_ctx_update(ohmd_context* ctx)
{
- for(int i = 0; i < ctx->num_active_devices; i++)
- ctx->active_devices[i]->update(ctx->ac
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list