# HG changeset patch # User John Tsiombikas # Date 1408727475 -10800 # Node ID e3f0ca1d008a0cf7843566c6fc598e99abb84372 # Parent c2eecf764daa76b28a4e19b469acb2f3bde22622 added preliminary OpenHMD module diff -r c2eecf764daa -r e3f0ca1d008a Makefile --- a/Makefile Fri Aug 22 18:48:25 2014 +0300 +++ b/Makefile Fri Aug 22 20:11:15 2014 +0300 @@ -7,6 +7,9 @@ # comment out to disable LibOVR (oculus sdk) #ovr_cflags = -DUSE_LIBOVR #ovr_libs = -lovr +# comment out to disable OpenHMD +ohmd_cflags = -DUSE_OPENHMD +ohmd_libs = -lopenhmd CFLAGS = -pedantic -Wall -g $(ovr_cflags) CXXFLAGS = -std=c++11 $(CFLAGS) diff -r c2eecf764daa -r e3f0ca1d008a src/vr/opt.c --- a/src/vr/opt.c Fri Aug 22 18:48:25 2014 +0300 +++ b/src/vr/opt.c Fri Aug 22 20:11:15 2014 +0300 @@ -5,7 +5,7 @@ #include "opt.h" #include "rbtree.h" -static void opt_del_func(void *opt, void *cls) +static void opt_del_func(struct rbnode *opt, void *cls) { free(opt); } diff -r c2eecf764daa -r e3f0ca1d008a src/vr/vr.c --- a/src/vr/vr.c Fri Aug 22 18:48:25 2014 +0300 +++ b/src/vr/vr.c Fri Aug 22 20:11:15 2014 +0300 @@ -152,7 +152,17 @@ int vr_view_matrix(int eye, float *mat) { - /* TODO combine vr_view_translation and vr_view_rotation */ + float offs[3], quat[4]; + + if(vrm && vrm->view_matrix) { + vrm->view_matrix(eye, mat); + return 1; + } + + if(!vr_view_translation(eye, offs) && !vr_view_rotation(eye, quat)) { + return 0; + } + /* TODO construct matrix */ return 0; } diff -r c2eecf764daa -r e3f0ca1d008a src/vr/vr_impl.h --- a/src/vr/vr_impl.h Fri Aug 22 18:48:25 2014 +0300 +++ b/src/vr/vr_impl.h Fri Aug 22 20:11:15 2014 +0300 @@ -16,6 +16,7 @@ void (*translation)(int eye, float *vec); void (*rotation)(int eye, float *quat); + void (*view_matrix)(int eye, float *mat); void (*proj_matrix)(int eye, float znear, float zfar, float *mat); void (*begin)(int eye); diff -r c2eecf764daa -r e3f0ca1d008a src/vr/vr_libovr.c --- a/src/vr/vr_libovr.c Fri Aug 22 18:48:25 2014 +0300 +++ b/src/vr/vr_libovr.c Fri Aug 22 20:11:15 2014 +0300 @@ -104,16 +104,16 @@ #endif ovrHmd_AttachToWindow(hmd, win, 0, 0); - //ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); + /*ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);*/ - dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette;// | ovrDistortionCap_TimeWarp;// | - //ovrDistortionCap_Overdrive; + dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette;/* | ovrDistortionCap_TimeWarp;// | + ovrDistortionCap_Overdrive; */ if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) { fprintf(stderr, "failed to configure LibOVR distortion renderer\n"); } - //ovrhmd_EnableHSWDisplaySDKRender(hmd, 0); + /* ovrhmd_EnableHSWDisplaySDKRender(hmd, 0); */ } static void cleanup(void) diff -r c2eecf764daa -r e3f0ca1d008a src/vr/vr_modules.c --- a/src/vr/vr_modules.c Fri Aug 22 18:48:25 2014 +0300 +++ b/src/vr/vr_modules.c Fri Aug 22 20:11:15 2014 +0300 @@ -4,6 +4,7 @@ #include "vr_impl.h" struct vr_module *vr_module_libovr(void); +struct vr_module *vr_module_openhmd(void); struct vr_module *vr_module_null(void); static struct vr_module *modules; @@ -23,11 +24,13 @@ vr_register_module(m); } + if((m = vr_module_openhmd())) { + vr_register_module(m); + } + if((m = vr_module_null())) { vr_register_module(m); } - - /* more ... */ } void vr_clear_modules(void) diff -r c2eecf764daa -r e3f0ca1d008a src/vr/vr_openhmd.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/vr/vr_openhmd.c Fri Aug 22 20:11:15 2014 +0300 @@ -0,0 +1,210 @@ +#include "vr_impl.h" + +#ifdef USE_OPENHMD +#include +#include +#include +#include "opt.h" + +/* a noble spirit embiggens the framebuffer to avoid aliasing in the middle */ +#define EMBIGGEN 1.5 + +static ohmd_context *ctx; +static ohmd_device *dev; +static void *optdb; +static int new_frame = 1; + +static int disp_width, disp_height; +static float ipd; + +static struct { + unsigned int id; + float umin, umax; + float vmin, vmax; +} eye_tex[2]; + + +static int init(void) +{ + int i, num_hmds; + + if(!(ctx = ohmd_ctx_create())) { + fprintf(stderr, "failed to create OpenHMD context\n"); + ohmd_ctx_destroy(ctx); + return -1; + } + if(!(num_hmds = ohmd_ctx_probe(ctx))) { + fprintf(stderr, "no HMDs detected\n"); + return -1; + } + + for(i=0; i