libgoatvr

diff src/vr_libovr.c @ 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 7f9cc8a4d3a5
children 5136dfcea7b1
line diff
     1.1 --- a/src/vr_libovr.c	Mon Jan 12 08:59:32 2015 +0200
     1.2 +++ b/src/vr_libovr.c	Wed Jan 14 08:03:27 2015 +0200
     1.3 @@ -1,8 +1,9 @@
     1.4  #ifdef WIN32
     1.5  #define OVR_OS_WIN32
     1.6 -#endif
     1.7 -#ifdef __APPLE__
     1.8 +#elif defined(__APPLE__)
     1.9  #define OVR_OS_MAC
    1.10 +#else
    1.11 +#define OVR_OS_LINUX
    1.12  #endif
    1.13  
    1.14  #include "vr_impl.h"
    1.15 @@ -17,6 +18,10 @@
    1.16  #include <OVR_CAPI.h>
    1.17  #include <OVR_CAPI_GL.h>
    1.18  
    1.19 +#ifdef OVR_OS_LINUX
    1.20 +#include <GL/glx.h>
    1.21 +#endif
    1.22 +
    1.23  /* undef this if you want the retarded health and safety warning screen */
    1.24  #define DISABLE_RETARDED_HEALTH_WARNING
    1.25  
    1.26 @@ -123,10 +128,17 @@
    1.27  	glcfg.OGL.Header.Multisample = 1;
    1.28  #ifdef WIN32
    1.29  	win = GetActiveWindow();
    1.30 -	/*glcfg.OGL.Window = win;
    1.31 +	glcfg.OGL.Window = win;
    1.32  	glcfg.OGL.DC = wglGetCurrentDC();
    1.33 -	assert(glcfg.OGL.Window);
    1.34 -	assert(glcfg.OGL.DC);*/
    1.35 +#else
    1.36 +	glcfg.OGL.Disp = glXGetCurrentDisplay();
    1.37 +	win = (void*)glXGetCurrentDrawable();
    1.38 +
    1.39 +	/* on linux the Oculus SDK docs are instructing users to leave the DK2 screen in
    1.40 +	 * portrait mode. So we'll have to flip width and height
    1.41 +	 */
    1.42 +	glcfg.OGL.Header.BackBufferSize.w = hmd->Resolution.h;
    1.43 +	glcfg.OGL.Header.BackBufferSize.h = hmd->Resolution.w;
    1.44  #endif
    1.45  
    1.46  	if(!(hmd->HmdCaps & ovrHmdCap_ExtendDesktop)) {
    1.47 @@ -139,6 +151,9 @@
    1.48  
    1.49  	dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_TimeWarp |
    1.50  		ovrDistortionCap_Overdrive | ovrDistortionCap_NoRestore;
    1.51 +#ifdef OVR_OS_LINUX
    1.52 +	dcaps |= ovrDistortionCap_LinuxDevFullscreen;
    1.53 +#endif
    1.54  
    1.55  	if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, eye_fov, eye_render_desc)) {
    1.56  		fprintf(stderr, "failed to configure LibOVR distortion renderer\n");
    1.57 @@ -148,11 +163,20 @@
    1.58  	leye_offs[0] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.x;
    1.59  	leye_offs[1] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.y;
    1.60  	leye_offs[2] = eye_render_desc[ovrEye_Left].HmdToEyeViewOffset.z;
    1.61 -	set_option_vec(optdb, VR_LEYE_OFFSET, leye_offs);
    1.62  	reye_offs[0] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.x;
    1.63  	reye_offs[1] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.y;
    1.64  	reye_offs[2] = eye_render_desc[ovrEye_Right].HmdToEyeViewOffset.z;
    1.65 -	set_option_vec(optdb, VR_REYE_OFFSET, reye_offs);
    1.66 +
    1.67 +	/* sanity check ... on linux it seems I'm getting the eye offsets reversed for some reason */
    1.68 +	if(leye_offs[0] > reye_offs[0]) {
    1.69 +		fprintf(stderr, "BUG %s:%d: eye offset reversed?! fixing but wtf...\n", __FILE__, __LINE__);
    1.70 +		set_option_vec(optdb, VR_LEYE_OFFSET, reye_offs);
    1.71 +		set_option_vec(optdb, VR_REYE_OFFSET, leye_offs);
    1.72 +	} else {
    1.73 +		set_option_vec(optdb, VR_LEYE_OFFSET, leye_offs);
    1.74 +		set_option_vec(optdb, VR_REYE_OFFSET, reye_offs);
    1.75 +	}
    1.76 +
    1.77  
    1.78  #ifdef DISABLE_RETARDED_HEALTH_WARNING
    1.79  	ovrhmd_EnableHSWDisplaySDKRender(hmd, 0);
    1.80 @@ -182,6 +206,10 @@
    1.81  		fval = *(float*)valp;
    1.82  		set_option_float(optdb, opt, fval);
    1.83  		break;
    1.84 +
    1.85 +	case OTYPE_VEC:
    1.86 +		set_option_vec(optdb, opt, valp);
    1.87 +		break;
    1.88  	}
    1.89  
    1.90  	if(hmd && strcmp(opt, VR_RENDER_RES_SCALE) == 0) {
    1.91 @@ -204,6 +232,8 @@
    1.92  		return get_option_int(optdb, opt, valp);
    1.93  	case OTYPE_FLOAT:
    1.94  		return get_option_float(optdb, opt, valp);
    1.95 +	case OTYPE_VEC:
    1.96 +		return get_option_vec(optdb, opt, valp);
    1.97  	}
    1.98  	return -1;
    1.99  }
   1.100 @@ -283,11 +313,19 @@
   1.101  
   1.102  static int present(void)
   1.103  {
   1.104 +	int cur_prog;
   1.105 +
   1.106  	if(!hmd) return 0;
   1.107  
   1.108 +	glGetIntegerv(GL_CURRENT_PROGRAM, &cur_prog);
   1.109 +
   1.110  	ovrHmd_EndFrame(hmd, pose, &eye_tex[0].Texture);
   1.111  	inside_begin_end = 0;
   1.112  
   1.113 +	if(cur_prog) {
   1.114 +		glUseProgram(0);
   1.115 +	}
   1.116 +
   1.117  	return 1;
   1.118  }
   1.119