vrchess
diff src/vr/vr_libovr.c @ 11:5dc4e2b8f6f5
LibOVR is broken
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 23 Aug 2014 00:24:20 +0300 |
parents | e3f0ca1d008a |
children |
line diff
1.1 --- a/src/vr/vr_libovr.c Fri Aug 22 20:11:15 2014 +0300 1.2 +++ b/src/vr/vr_libovr.c Sat Aug 23 00:24:20 2014 +0300 1.3 @@ -13,6 +13,8 @@ 1.4 #include <OVR_CAPI.h> 1.5 #include <OVR_CAPI_GL.h> 1.6 1.7 +#define DISABLE_RETARDED_HEALTH_WARNING 1.8 + 1.9 /* just dropping the prototype here to avoid including CAPI_HSWDisplay.h */ 1.10 OVR_EXPORT void ovrhmd_EnableHSWDisplaySDKRender(ovrHmd hmd, ovrBool enabled); 1.11 1.12 @@ -46,7 +48,7 @@ 1.13 if(!(h = ovrHmd_Create(i))) { 1.14 break; 1.15 } 1.16 - printf(" [%d]: %s - %s\n", h->Manufacturer, h->ProductName); 1.17 + printf(" [%d]: %s - %s\n", i, h->Manufacturer, h->ProductName); 1.18 1.19 if(!hmd) { 1.20 hmd = h; 1.21 @@ -60,6 +62,8 @@ 1.22 return -1; 1.23 } 1.24 1.25 + ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0); 1.26 + 1.27 eye_fov[0] = hmd->DefaultEyeFov[0]; 1.28 eye_fov[1] = hmd->DefaultEyeFov[1]; 1.29 1.30 @@ -76,6 +80,8 @@ 1.31 set_option_int(optdb, VR_OPT_REYE_YRES, eye_res[1].h); 1.32 set_option_float(optdb, VR_OPT_EYE_HEIGHT, ovrHmd_GetFloat(hmd, OVR_KEY_EYE_HEIGHT, OVR_DEFAULT_EYE_HEIGHT)); 1.33 set_option_float(optdb, VR_OPT_IPD, ovrHmd_GetFloat(hmd, OVR_KEY_IPD, OVR_DEFAULT_IPD)); 1.34 + set_option_int(optdb, VR_OPT_WIN_XOFFS, hmd->WindowsPos.x); 1.35 + set_option_int(optdb, VR_OPT_WIN_YOFFS, hmd->WindowsPos.y); 1.36 } 1.37 1.38 deferred_init_done = 0; 1.39 @@ -90,30 +96,33 @@ 1.40 1.41 deferred_init_done = 1; 1.42 1.43 - ovrHmd_ConfigureTracking(hmd, 0xffffffff, 0); 1.44 - 1.45 + memset(&glcfg, 0, sizeof glcfg); 1.46 glcfg.OGL.Header.API = ovrRenderAPI_OpenGL; 1.47 glcfg.OGL.Header.RTSize = hmd->Resolution; 1.48 glcfg.OGL.Header.Multisample = 1; 1.49 #ifdef WIN32 1.50 win = GetActiveWindow(); 1.51 - glcfg.OGL.Window = win; 1.52 + /*glcfg.OGL.Window = win; 1.53 glcfg.OGL.DC = wglGetCurrentDC(); 1.54 assert(glcfg.OGL.Window); 1.55 - assert(glcfg.OGL.DC); 1.56 + assert(glcfg.OGL.DC);*/ 1.57 #endif 1.58 1.59 - ovrHmd_AttachToWindow(hmd, win, 0, 0); 1.60 - /*ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction);*/ 1.61 + if(!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop)) { 1.62 + ovrHmd_AttachToWindow(hmd, win, 0, 0); 1.63 + } 1.64 + ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); 1.65 1.66 - dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette;/* | ovrDistortionCap_TimeWarp;// | 1.67 - ovrDistortionCap_Overdrive; */ 1.68 + dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | 1.69 + ovrDistortionCap_Overdrive | ovrDistortionCap_NoRestore; 1.70 1.71 if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) { 1.72 fprintf(stderr, "failed to configure LibOVR distortion renderer\n"); 1.73 } 1.74 1.75 - /* ovrhmd_EnableHSWDisplaySDKRender(hmd, 0); */ 1.76 +#ifdef DISABLE_RETARDED_HEALTH_WARNING 1.77 + ovrhmd_EnableHSWDisplaySDKRender(hmd, 0); 1.78 +#endif 1.79 } 1.80 1.81 static void cleanup(void) 1.82 @@ -153,14 +162,14 @@ 1.83 { 1.84 if(!hmd) { 1.85 vec[0] = vec[1] = vec[2] = 0; 1.86 - return -1; 1.87 + return 0; 1.88 } 1.89 1.90 pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right); 1.91 vec[0] = pose[eye].Position.x; 1.92 vec[1] = pose[eye].Position.y; 1.93 vec[2] = pose[eye].Position.z; 1.94 - return 0; 1.95 + return 1; 1.96 } 1.97 1.98 static int rotation(int eye, float *quat) 1.99 @@ -168,7 +177,7 @@ 1.100 if(!hmd) { 1.101 quat[0] = quat[1] = quat[2] = 0.0f; 1.102 quat[3] = 1.0f; 1.103 - return -1; 1.104 + return 0; 1.105 } 1.106 1.107 pose[eye] = ovrHmd_GetEyePose(hmd, eye == VR_EYE_LEFT ? ovrEye_Left : ovrEye_Right); 1.108 @@ -176,13 +185,14 @@ 1.109 quat[1] = pose[eye].Orientation.y; 1.110 quat[2] = pose[eye].Orientation.z; 1.111 quat[3] = pose[eye].Orientation.w; 1.112 - return 0; 1.113 + return 1; 1.114 } 1.115 1.116 static const float idmat[] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; 1.117 1.118 static void proj_matrix(int eye, float znear, float zfar, float *mat) 1.119 { 1.120 + int i, j; 1.121 ovrMatrix4f vmat; 1.122 1.123 if(!hmd) { 1.124 @@ -191,7 +201,12 @@ 1.125 } 1.126 1.127 vmat = ovrMatrix4f_Projection(eye_render_desc[eye].Fov, znear, zfar, 1); 1.128 - memcpy(mat, vmat.M[0], 16 * sizeof(float)); 1.129 + 1.130 + for(i=0; i<4; i++) { 1.131 + for(j=0; j<4; j++) { 1.132 + *mat++ = vmat.M[j][i]; 1.133 + } 1.134 + } 1.135 } 1.136 1.137 static int new_frame = 1; 1.138 @@ -227,6 +242,9 @@ 1.139 ovrSizei texsz; 1.140 ovrRecti rect; 1.141 1.142 + vmin = 1.0 - vmax; 1.143 + vmax = 1.0 - vmin; 1.144 + 1.145 glBindTexture(GL_TEXTURE_2D, tex); 1.146 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texsz.w); 1.147 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texsz.h); 1.148 @@ -236,9 +254,6 @@ 1.149 rect.Size.w = (int)((umax - umin) * texsz.w); 1.150 rect.Size.h = (int)((vmax - vmin) * texsz.h); 1.151 1.152 - printf("eye %d texture: %u [%g, %g] -> [%g, %g]\n", eye, tex, umin, vmin, umax, vmax); 1.153 - printf(" pixels [%d, %d] -> [%d, %d]\n", rect.Pos.x, rect.Pos.y, rect.Pos.x + rect.Size.w, rect.Pos.y + rect.Size.h); 1.154 - 1.155 eye_tex[eye].OGL.Header.API = ovrRenderAPI_OpenGL; 1.156 eye_tex[eye].OGL.Header.TextureSize = texsz; 1.157 eye_tex[eye].OGL.Header.RenderViewport = rect;