libgoatvr
changeset 24:d659cbedde1d
works on linux with 0.4.4
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 14 Jan 2015 08:03:27 +0200 |
parents | 0fea7c2b25d7 |
children | bb85be761b50 |
files | src/vr.c src/vr_libovr.c |
diffstat | 2 files changed, 54 insertions(+), 11 deletions(-) [+] |
line diff
1.1 --- a/src/vr.c Mon Jan 12 08:59:32 2015 +0200 1.2 +++ b/src/vr.c Wed Jan 14 08:03:27 2015 +0200 1.3 @@ -33,7 +33,7 @@ 1.4 int vr_init(void) 1.5 { 1.6 int i, nmodules; 1.7 - char *vrmod_env; 1.8 + char *env; 1.9 1.10 /* create the default options database */ 1.11 if(!defopt && (defopt = create_options())) { 1.12 @@ -42,7 +42,12 @@ 1.13 set_option_float(defopt, VR_IPD, DEF_IPD); 1.14 set_option_vec3f(defopt, VR_LEYE_OFFSET, -DEF_IPD * 0.5f, 0.0f, 0.0f); 1.15 set_option_vec3f(defopt, VR_REYE_OFFSET, DEF_IPD * 0.5f, 0.0f, 0.0f); 1.16 - set_option_int(defopt, VR_NULL_STEREO, 0); 1.17 + 1.18 + if((env = getenv("VR_NULL_STEREO")) && atoi(env)) { 1.19 + set_option_int(defopt, VR_NULL_STEREO, 1); 1.20 + } else { 1.21 + set_option_int(defopt, VR_NULL_STEREO, 0); 1.22 + } 1.23 } 1.24 1.25 if(vrm) { 1.26 @@ -64,8 +69,8 @@ 1.27 return -1; 1.28 } 1.29 1.30 - if((vrmod_env = getenv("VR_MODULE"))) { 1.31 - vr_use_module_named(vrmod_env); 1.32 + if((env = getenv("VR_MODULE"))) { 1.33 + vr_use_module_named(env); 1.34 } else { 1.35 vr_use_module(0); 1.36 }
2.1 --- a/src/vr_libovr.c Mon Jan 12 08:59:32 2015 +0200 2.2 +++ b/src/vr_libovr.c Wed Jan 14 08:03:27 2015 +0200 2.3 @@ -1,8 +1,9 @@ 2.4 #ifdef WIN32 2.5 #define OVR_OS_WIN32 2.6 -#endif 2.7 -#ifdef __APPLE__ 2.8 +#elif defined(__APPLE__) 2.9 #define OVR_OS_MAC 2.10 +#else 2.11 +#define OVR_OS_LINUX 2.12 #endif 2.13 2.14 #include "vr_impl.h" 2.15 @@ -17,6 +18,10 @@ 2.16 #include <OVR_CAPI.h> 2.17 #include <OVR_CAPI_GL.h> 2.18 2.19 +#ifdef OVR_OS_LINUX 2.20 +#include <GL/glx.h> 2.21 +#endif 2.22 + 2.23 /* undef this if you want the retarded health and safety warning screen */ 2.24 #define DISABLE_RETARDED_HEALTH_WARNING 2.25 2.26 @@ -123,10 +128,17 @@ 2.27 glcfg.OGL.Header.Multisample = 1; 2.28 #ifdef WIN32 2.29 win = GetActiveWindow(); 2.30 - /*glcfg.OGL.Window = win; 2.31 + glcfg.OGL.Window = win; 2.32 glcfg.OGL.DC = wglGetCurrentDC(); 2.33 - assert(glcfg.OGL.Window); 2.34 - assert(glcfg.OGL.DC);*/ 2.35 +#else 2.36 + glcfg.OGL.Disp = glXGetCurrentDisplay(); 2.37 + win = (void*)glXGetCurrentDrawable(); 2.38 + 2.39 + /* on linux the Oculus SDK docs are instructing users to leave the DK2 screen in 2.40 + * portrait mode. So we'll have to flip width and height 2.41 + */ 2.42 + glcfg.OGL.Header.BackBufferSize.w = hmd->Resolution.h; 2.43 + glcfg.OGL.Header.BackBufferSize.h = hmd->Resolution.w; 2.44 #endif 2.45 2.46 if(!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop)) { 2.47 @@ -139,6 +151,9 @@ 2.48 2.49 dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp | 2.50 ovrDistortionCap_Overdrive | ovrDistortionCap_NoRestore; 2.51 +#ifdef OVR_OS_LINUX 2.52 + dcaps |= ovrDistortionCap_LinuxDevFullscreen; 2.53 +#endif 2.54 2.55 if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) { 2.56 fprintf(stderr, "failed to configure LibOVR distortion renderer\n"); 2.57 @@ -148,11 +163,20 @@ 2.58 leye_offs[0] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.x; 2.59 leye_offs[1] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.y; 2.60 leye_offs[2] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.z; 2.61 - set_option_vec(optdb, VR_LEYE_OFFSET, leye_offs); 2.62 reye_offs[0] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.x; 2.63 reye_offs[1] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.y; 2.64 reye_offs[2] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.z; 2.65 - set_option_vec(optdb, VR_REYE_OFFSET, reye_offs); 2.66 + 2.67 + /* sanity check ... on linux it seems I'm getting the eye offsets reversed for some reason */ 2.68 + if(leye_offs[0] > reye_offs[0]) { 2.69 + fprintf(stderr, "BUG %s:%d: eye offset reversed?! fixing but wtf...\n", __FILE__, __LINE__); 2.70 + set_option_vec(optdb, VR_LEYE_OFFSET, reye_offs); 2.71 + set_option_vec(optdb, VR_REYE_OFFSET, leye_offs); 2.72 + } else { 2.73 + set_option_vec(optdb, VR_LEYE_OFFSET, leye_offs); 2.74 + set_option_vec(optdb, VR_REYE_OFFSET, reye_offs); 2.75 + } 2.76 + 2.77 2.78 #ifdef DISABLE_RETARDED_HEALTH_WARNING 2.79 ovrhmd_EnableHSWDisplaySDKRender(hmd, 0); 2.80 @@ -182,6 +206,10 @@ 2.81 fval = *(float*)valp; 2.82 set_option_float(optdb, opt, fval); 2.83 break; 2.84 + 2.85 + case OTYPE_VEC: 2.86 + set_option_vec(optdb, opt, valp); 2.87 + break; 2.88 } 2.89 2.90 if(hmd && strcmp(opt, VR_RENDER_RES_SCALE) == 0) { 2.91 @@ -204,6 +232,8 @@ 2.92 return get_option_int(optdb, opt, valp); 2.93 case OTYPE_FLOAT: 2.94 return get_option_float(optdb, opt, valp); 2.95 + case OTYPE_VEC: 2.96 + return get_option_vec(optdb, opt, valp); 2.97 } 2.98 return -1; 2.99 } 2.100 @@ -283,11 +313,19 @@ 2.101 2.102 static int present(void) 2.103 { 2.104 + int cur_prog; 2.105 + 2.106 if(!hmd) return 0; 2.107 2.108 + glGetIntegerv(GL_CURRENT_PROGRAM, &cur_prog); 2.109 + 2.110 ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture); 2.111 inside_begin_end = 0; 2.112 2.113 + if(cur_prog) { 2.114 + glUseProgram(0); 2.115 + } 2.116 + 2.117 return 1; 2.118 } 2.119