From b17410965e84e378c4cc85ffb732365552edc584 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 23 Dec 2014 00:44:28 +0200 Subject: [PATCH] Make the StereoCombiner information interface more flexible Different non-integer sizing factors may be required for width and height, and visual aspect ratio does not necessarily match that of the render target. --- source/oculusriftcombiner.cpp | 7 ++++--- source/sidebysidecombiner.cpp | 3 ++- source/stereocombiner.cpp | 7 +++---- source/stereocombiner.h | 14 ++++++-------- source/stereoview.cpp | 9 +++------ 5 files changed, 18 insertions(+), 22 deletions(-) diff --git a/source/oculusriftcombiner.cpp b/source/oculusriftcombiner.cpp index e6b2908..492f5fd 100644 --- a/source/oculusriftcombiner.cpp +++ b/source/oculusriftcombiner.cpp @@ -78,8 +78,6 @@ OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): right_mesh((GL::VERTEX2, GL::TEXCOORD2,0, GL::TEXCOORD2,1, GL::TEXCOORD2,2)), shprog(vs_source, fs_source) { - width_div = 2; - const OculusRiftDevice::Private &dev_priv = device.get_private(); ovrHmd hmd = dev_priv.ovr_hmd; @@ -101,7 +99,10 @@ OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): create_distortion_mesh(right_mesh, hmd, ovrEye_Right, right_fov); ovrSizei tex_size = ovrHmd_GetFovTextureSize(hmd, ovrEye_Left, left_fov, 1.0); - oversize = max(tex_size.w*2.0f/hmd->Resolution.w, tex_size.h*1.0f/hmd->Resolution.h); + 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; shdata.uniform("texture", 0); diff --git a/source/sidebysidecombiner.cpp b/source/sidebysidecombiner.cpp index 213b544..c5aef04 100644 --- a/source/sidebysidecombiner.cpp +++ b/source/sidebysidecombiner.cpp @@ -30,7 +30,8 @@ SideBySideCombiner::SideBySideCombiner(bool c): mesh(GL::VERTEX2), shprog(vs_source, fs_source) { - width_div = 2; + width_factor = 0.5f; + aspect_factor = 0.5f; left_shdata.uniform("texture", 0); right_shdata.uniform("texture", 0); diff --git a/source/stereocombiner.cpp b/source/stereocombiner.cpp index a276c3b..1730e9a 100644 --- a/source/stereocombiner.cpp +++ b/source/stereocombiner.cpp @@ -4,10 +4,9 @@ namespace Msp { namespace VR { StereoCombiner::StereoCombiner(): - width_div(1), - height_div(1), - keep_aspect(false), - oversize(1.0f), + width_factor(1.0f), + height_factor(1.0f), + aspect_factor(1.0f), frustum_skew(0.0f) { } diff --git a/source/stereocombiner.h b/source/stereocombiner.h index 23d4822..41c5a56 100644 --- a/source/stereocombiner.h +++ b/source/stereocombiner.h @@ -10,22 +10,20 @@ namespace VR { class StereoCombiner { protected: - unsigned width_div; - unsigned height_div; - bool keep_aspect; + float width_factor; + float height_factor; + float aspect_factor; Geometry::Angle fov; - float oversize; float frustum_skew; StereoCombiner(); public: virtual ~StereoCombiner() { } - unsigned get_width_divisor() const { return width_div; } - unsigned get_height_divisor() const { return height_div; } - bool is_aspect_kept() const { return keep_aspect; } + float get_width_factor() const { return width_factor; } + float get_height_factor() const { return height_factor; } + float get_aspect_factor() const { return aspect_factor; } const Geometry::Angle &get_field_of_view() const { return fov; } - float get_oversize() const { return oversize; } float get_frustum_skew() const { return frustum_skew; } virtual void render(const GL::Texture2D &, const GL::Texture2D &) const = 0; diff --git a/source/stereoview.cpp b/source/stereoview.cpp index 08949e6..dd825ed 100644 --- a/source/stereoview.cpp +++ b/source/stereoview.cpp @@ -22,8 +22,8 @@ void StereoView::set_combiner(const StereoCombiner &c) { combiner = &c; - unsigned w = width/combiner->get_width_divisor()*combiner->get_oversize(); - unsigned h = height/combiner->get_height_divisor()*combiner->get_oversize(); + unsigned w = width*combiner->get_width_factor(); + unsigned h = height*combiner->get_height_factor(); left.create_target(w, h); right.create_target(w, h); } @@ -42,10 +42,7 @@ void StereoView::setup_frame() const if(params.fov==Geometry::Angle::zero()) params.fov = base_camera.get_field_of_view(); - params.aspect = base_camera.get_aspect(); - if(!combiner->is_aspect_kept()) - params.aspect = params.aspect*combiner->get_height_divisor()/combiner->get_width_divisor(); - + params.aspect = base_camera.get_aspect()*combiner->get_aspect_factor(); params.near_clip = base_camera.get_near_clip(); params.far_clip = base_camera.get_far_clip(); -- 2.45.2