- width_div = 2;
-
- left_shdata.uniform("texture", 0);
- left_shdata.uniform("offset", -0.5f);
- right_shdata.uniform("texture", 0);
- right_shdata.uniform("offset", 0.5f);
-
- // This will also call update_parameters
- set_distortion(1.0f, 0.22f, 0.24f);
-
- MeshBuilder bld(mesh);
- bld.begin(TRIANGLE_STRIP);
- bld.vertex(-1, 1);
- bld.vertex(-1, -1);
- bld.vertex(1, 1);
- bld.vertex(1, -1);
- bld.end();
-}
-
-void OculusRiftCombiner::set_view_distance(float d)
-{
- view_distance = d;
- update_parameters();
-}
+ ovrDistortionMesh ovr_mesh;
+ ovrHmd_CreateDistortionMesh(hmd, eye, fov, ovrDistortionCap_Chromatic|ovrDistortionCap_Vignette, &ovr_mesh);
+
+ ovrSizei tex_size = ovrHmd_GetFovTextureSize(hmd, eye, fov, 1.0);
+ ovrRecti view_rect;
+ view_rect.Pos.x = 0;
+ view_rect.Pos.y = 0;
+ view_rect.Size = tex_size;
+ ovrVector2f uv_scale_offset[2];
+ ovrHmd_GetRenderScaleAndOffset(fov, tex_size, view_rect, uv_scale_offset);
+ ovrVector2f &scale = uv_scale_offset[0];
+ ovrVector2f &offset = uv_scale_offset[1];
+
+ Msp::GL::MeshBuilder bld(mesh);
+ for(unsigned i=0; i<ovr_mesh.VertexCount; ++i)
+ {
+ ovrDistortionVertex &v = ovr_mesh.pVertexData[i];
+ bld.multitexcoord(0, v.TanEyeAnglesR.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesR.y*scale.y+offset.y));
+ bld.multitexcoord(1, v.TanEyeAnglesG.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesG.y*scale.y+offset.y));
+ bld.multitexcoord(2, v.TanEyeAnglesB.x*scale.x+offset.x, 1.0f-(v.TanEyeAnglesB.y*scale.y+offset.y));
+ bld.multitexcoord(3, v.VignetteFactor);
+ bld.vertex(v.ScreenPosNDC.x, v.ScreenPosNDC.y);
+ }