X-Git-Url: http://git.tdb.fi/?p=libs%2Fvr.git;a=blobdiff_plain;f=source%2Fovr%2Foculusriftcombiner.cpp;h=e0c2c4d0ffc9146106d0d999191973b0daa7d05d;hp=0d883fa575f9e7b09450f9f87a1ad4ab4fd668a4;hb=b6de7d24475dec8f5d6b8148a69cf8b561bc0761;hpb=12044b218363bdd93f9fc1b3c71167d700144e45 diff --git a/source/ovr/oculusriftcombiner.cpp b/source/ovr/oculusriftcombiner.cpp index 0d883fa..e0c2c4d 100644 --- a/source/ovr/oculusriftcombiner.cpp +++ b/source/ovr/oculusriftcombiner.cpp @@ -1,9 +1,8 @@ -#include #include #include #include "oculusriftcombiner.h" -#include "oculusriftdevice.h" -#include "oculusriftdevice_private.h" +#include "oculusriftsystem.h" +#include "oculusriftsystem_private.h" using namespace std; @@ -76,8 +75,15 @@ void create_distortion_mesh(Msp::GL::Mesh &mesh, ovrHmd hmd, ovrEyeType eye, con namespace Msp { namespace VR { -OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): +struct OculusRiftCombiner::Frustum: StereoCombiner::Frustum +{ + Frustum(const ovrFovPort &); +}; + + +OculusRiftCombiner::OculusRiftCombiner(OculusRiftSystem &d, GL::View &v): device(d), + view(v), left_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2, GL::TEXCOORD2,3)), right_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2, GL::TEXCOORD2,3)), shprog(vs_source, fs_source) @@ -86,26 +92,20 @@ OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): ovrFovPort left_fov = hmd->DefaultEyeFov[ovrEye_Left]; ovrFovPort right_fov = hmd->DefaultEyeFov[ovrEye_Right]; - float vertical = max(max(left_fov.UpTan, left_fov.DownTan), max(right_fov.UpTan, right_fov.DownTan)); - fov = Geometry::atan(vertical)*2.0f; + configure_eye_frustums(Frustum(left_fov), Frustum(right_fov)); - float inner = max(left_fov.RightTan, right_fov.LeftTan); - float outer = max(left_fov.LeftTan, right_fov.RightTan); - frustum_skew = (inner-outer)/(inner+outer); - - left_fov.UpTan = right_fov.UpTan = vertical; - left_fov.DownTan = right_fov.DownTan = vertical; - left_fov.RightTan = right_fov.LeftTan = inner; - left_fov.LeftTan = right_fov.RightTan = outer; + left_fov.UpTan = left_fov.DownTan = tan(fov/2.0f); + left_fov.LeftTan = left_fov.UpTan*render_aspect*(1-frustum_skew); + left_fov.RightTan = left_fov.UpTan*render_aspect*(1+frustum_skew); + right_fov = left_fov; + swap(right_fov.LeftTan, right_fov.RightTan); create_distortion_mesh(left_mesh, hmd, ovrEye_Left, left_fov); create_distortion_mesh(right_mesh, hmd, ovrEye_Right, right_fov); ovrSizei tex_size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, left_fov, 1.0); - width_factor = tex_size.w*1.0f/hmd->Resolution.w; - height_factor = tex_size.h*1.0f/hmd->Resolution.h; - float aspect = (inner+outer)/(vertical*2); - aspect_factor = aspect*hmd->Resolution.h/hmd->Resolution.w; + target_width = tex_size.w; + target_height = tex_size.h; left_shdata.uniform("texture", 0); right_shdata.uniform("texture", 0); @@ -121,6 +121,13 @@ OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): ovrHmd_GetRenderScaleAndOffset(right_fov, tex_size, view_rect, uv_scale_offset); right_shdata.uniform("uv_scale", uv_scale_offset[0].x, -uv_scale_offset[0].y); right_shdata.uniform("uv_offset", uv_scale_offset[1].x, 1-uv_scale_offset[1].y); + + device.configure_window(view.get_window()); +} + +void OculusRiftCombiner::prepare() const +{ + device.begin_frame(); } void OculusRiftCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const @@ -155,7 +162,15 @@ void OculusRiftCombiner::render(const GL::Texture2D &left, const GL::Texture2D & right.bind(); right_shdata.apply(); right_mesh.draw(); + + view.get_context().swap_buffers(); + device.end_frame(); } + +OculusRiftCombiner::Frustum::Frustum(const ovrFovPort &fov): + StereoCombiner::Frustum(-fov.LeftTan, fov.RightTan, -fov.DownTan, fov.UpTan) +{ } + } // namespace VR } // namespace Msp