oculus2
changeset 15:62a37bd5bc74
ok oculus2 test now works on linux with SDK 0.4.3 experimental.
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 29 Oct 2014 01:08:38 +0200 |
parents | 256d8fcf02f1 |
children | 0888d4e24e21 |
files | src/main.c |
diffstat | 1 files changed, 66 insertions(+), 7 deletions(-) [+] |
line diff
1.1 --- a/src/main.c Mon Oct 27 04:20:07 2014 +0200 1.2 +++ b/src/main.c Wed Oct 29 01:08:38 2014 +0200 1.3 @@ -54,6 +54,9 @@ 1.4 static ovrSizei eyeres[2]; 1.5 static ovrEyeRenderDesc eye_rdesc[2]; 1.6 static ovrGLTexture fb_ovr_tex[2]; 1.7 +static union ovrGLConfig glcfg; 1.8 +static unsigned int distort_caps; 1.9 +static unsigned int hmd_caps; 1.10 1.11 static unsigned int chess_tex; 1.12 1.13 @@ -83,8 +86,7 @@ 1.14 int init(void) 1.15 { 1.16 int i, x, y; 1.17 - unsigned int flags, dcaps; 1.18 - union ovrGLConfig glcfg; 1.19 + unsigned int flags; 1.20 1.21 /* libovr must be initialized before we create the OpenGL context */ 1.22 ovr_Initialize(); 1.23 @@ -137,7 +139,7 @@ 1.24 fb_ovr_tex[i].OGL.Header.TextureSize.h = fb_tex_height; 1.25 /* this next field is the only one that differs between the two eyes */ 1.26 fb_ovr_tex[i].OGL.Header.RenderViewport.Pos.x = i == 0 ? 0 : fb_width / 2.0; 1.27 - fb_ovr_tex[i].OGL.Header.RenderViewport.Pos.y = fb_tex_height - fb_height; 1.28 + fb_ovr_tex[i].OGL.Header.RenderViewport.Pos.y = 0; 1.29 fb_ovr_tex[i].OGL.Header.RenderViewport.Size.w = fb_width / 2.0; 1.30 fb_ovr_tex[i].OGL.Header.RenderViewport.Size.h = fb_height; 1.31 fb_ovr_tex[i].OGL.TexId = fb_tex; /* both eyes will use the same texture id */ 1.32 @@ -175,15 +177,16 @@ 1.33 } 1.34 1.35 /* enable low-persistence display and dynamic prediction for lattency compensation */ 1.36 - ovrHmd_SetEnabledCaps(hmd, ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction); 1.37 + hmd_caps = ovrHmdCap_LowPersistence | ovrHmdCap_DynamicPrediction; 1.38 + ovrHmd_SetEnabledCaps(hmd, hmd_caps); 1.39 1.40 /* configure SDK-rendering and enable chromatic abberation correction, vignetting, and 1.41 * timewrap, which shifts the image before drawing to counter any lattency between the call 1.42 * to ovrHmd_GetEyePose and ovrHmd_EndFrame. 1.43 */ 1.44 - dcaps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | 1.45 + distort_caps = ovrDistortionCap_Chromatic | ovrDistortionCap_Vignette | ovrDistortionCap_TimeWarp | 1.46 ovrDistortionCap_Overdrive; 1.47 - if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, dcaps, hmd->DefaultEyeFov, eye_rdesc)) { 1.48 + if(!ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc)) { 1.49 fprintf(stderr, "failed to configure distortion renderer\n"); 1.50 } 1.51 1.52 @@ -225,10 +228,28 @@ 1.53 SDL_GetWindowPosition(win, &prev_x, &prev_y); 1.54 SDL_SetWindowPosition(win, hmd->WindowsPos.x, hmd->WindowsPos.y); 1.55 SDL_SetWindowFullscreen(win, SDL_WINDOW_FULLSCREEN_DESKTOP); 1.56 + 1.57 +#ifdef OVR_OS_LINUX 1.58 + /* on linux for now we have to deal with screen rotation during rendering. The docs are promoting 1.59 + * not rotating the DK2 screen globally 1.60 + */ 1.61 + glcfg.OGL.Header.RTSize.w = hmd->Resolution.h; 1.62 + glcfg.OGL.Header.RTSize.h = hmd->Resolution.w; 1.63 + 1.64 + distort_caps |= ovrDistortionCap_LinuxDevFullscreen; 1.65 + ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc); 1.66 +#endif 1.67 } else { 1.68 /* return to windowed mode and move the window back to its original position */ 1.69 SDL_SetWindowFullscreen(win, 0); 1.70 SDL_SetWindowPosition(win, prev_x, prev_y); 1.71 + 1.72 +#ifdef OVR_OS_LINUX 1.73 + glcfg.OGL.Header.RTSize = hmd->Resolution; 1.74 + 1.75 + distort_caps &= ~ovrDistortionCap_LinuxDevFullscreen; 1.76 + ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc); 1.77 +#endif 1.78 } 1.79 } 1.80 1.81 @@ -246,6 +267,8 @@ 1.82 glBindFramebuffer(GL_FRAMEBUFFER, fbo); 1.83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.84 1.85 + glUseProgram(0); 1.86 + 1.87 /* for each eye ... */ 1.88 for(i=0; i<2; i++) { 1.89 ovrEyeType eye = hmd->EyeRenderOrder[i]; 1.90 @@ -294,13 +317,18 @@ 1.91 * compensated for lens distortion and chromatic abberation onto the HMD screen. 1.92 */ 1.93 glBindFramebuffer(GL_FRAMEBUFFER, 0); 1.94 - glViewport(0, 0, win_width, win_height); 1.95 1.96 ovrHmd_EndFrame(hmd, pose, &fb_ovr_tex[0].Texture); 1.97 1.98 assert(glGetError() == GL_NO_ERROR); 1.99 } 1.100 1.101 +void reshape(int x, int y) 1.102 +{ 1.103 + win_width = x; 1.104 + win_height = y; 1.105 +} 1.106 + 1.107 void draw_scene(void) 1.108 { 1.109 int i; 1.110 @@ -459,6 +487,12 @@ 1.111 } 1.112 break; 1.113 1.114 + case SDL_WINDOWEVENT: 1.115 + if(ev->window.event == SDL_WINDOWEVENT_RESIZED) { 1.116 + reshape(ev->window.data1, ev->window.data2); 1.117 + } 1.118 + break; 1.119 + 1.120 default: 1.121 break; 1.122 } 1.123 @@ -482,6 +516,7 @@ 1.124 return -1; 1.125 1.126 case ' ': 1.127 + case 'r': 1.128 /* allow the user to recenter by pressing space */ 1.129 ovrHmd_RecenterPose(hmd); 1.130 break; 1.131 @@ -491,6 +526,30 @@ 1.132 toggle_hmd_fullscreen(); 1.133 break; 1.134 1.135 + case 'v': 1.136 + distort_caps ^= ovrDistortionCap_Vignette; 1.137 + printf("Vignette: %s\n", distort_caps & ovrDistortionCap_Vignette ? "on" : "off"); 1.138 + ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc); 1.139 + break; 1.140 + 1.141 + case 't': 1.142 + distort_caps ^= ovrDistortionCap_TimeWarp; 1.143 + printf("Time-warp: %s\n", distort_caps & ovrDistortionCap_TimeWarp ? "on" : "off"); 1.144 + ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc); 1.145 + break; 1.146 + 1.147 + case 'o': 1.148 + distort_caps ^= ovrDistortionCap_Overdrive; 1.149 + printf("OLED over-drive: %s\n", distort_caps & ovrDistortionCap_Overdrive ? "on" : "off"); 1.150 + ovrHmd_ConfigureRendering(hmd, &glcfg.Config, distort_caps, hmd->DefaultEyeFov, eye_rdesc); 1.151 + break; 1.152 + 1.153 + case 'l': 1.154 + hmd_caps ^= ovrHmdCap_LowPersistence; 1.155 + printf("Low-persistence display: %s\n", hmd_caps & ovrHmdCap_LowPersistence ? "on" : "off"); 1.156 + ovrHmd_SetEnabledCaps(hmd, hmd_caps); 1.157 + break; 1.158 + 1.159 default: 1.160 break; 1.161 }