]> git.tdb.fi Git - libs/vr.git/commitdiff
Make the StereoCombiner information interface more flexible
authorMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 22:44:28 +0000 (00:44 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 22 Dec 2014 22:44:28 +0000 (00:44 +0200)
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
source/sidebysidecombiner.cpp
source/stereocombiner.cpp
source/stereocombiner.h
source/stereoview.cpp

index e6b2908655a9a5d08520124b29e0a7dcbfe3ab21..492f5fdbcb220ee40b5f73207fb0f7ee6a94a12c 100644 (file)
@@ -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);
 
index 213b5448249b894736d392e55c741235d10e438b..c5aef041ecf3f123501d9fc062d5c497f1abe1de 100644 (file)
@@ -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);
index a276c3bc3c677ad2ba24f49df1b435e572842156..1730e9a4d9eaa8d4cbce026213988b0d74dbd726 100644 (file)
@@ -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)
 { }
 
index 23d482267e0ad706a1575a70657d4dbd1725d7da..41c5a56945080b2edea0e0503b06128b62ee67b8 100644 (file)
@@ -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<float> 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<float> &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;
index 08949e653599509021f24eb29b2f9b37f41a6826..dd825ed1f276839cb76c614215ca15b1d4776a55 100644 (file)
@@ -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<float>::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();