]> git.tdb.fi Git - libs/vr.git/commitdiff
Provide absolute render target dimensions from StereoCombiner
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 08:39:42 +0000 (11:39 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 09:45:12 +0000 (12:45 +0300)
source/ovr/oculusriftcombiner.cpp
source/sidebysidecombiner.cpp
source/sidebysidecombiner.h
source/stereocombiner.cpp
source/stereocombiner.h
source/stereoview.cpp
source/stereoview.h

index 0d883fa575f9e7b09450f9f87a1ad4ab4fd668a4..d71a93d2e1d6f61913a78887bfc2182741d04206 100644 (file)
@@ -102,10 +102,9 @@ 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);
-       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;
+       render_aspect = (inner+outer)/(vertical*2);
 
        left_shdata.uniform("texture", 0);
        right_shdata.uniform("texture", 0);
index c5aef041ecf3f123501d9fc062d5c497f1abe1de..ac353133bac26ea5abb2387b9731cc4b5db7589f 100644 (file)
@@ -26,12 +26,13 @@ const char fs_source[] =
 namespace Msp {
 namespace VR {
 
-SideBySideCombiner::SideBySideCombiner(bool c):
+SideBySideCombiner::SideBySideCombiner(GL::View &view, bool c):
        mesh(GL::VERTEX2),
        shprog(vs_source, fs_source)
 {
-       width_factor = 0.5f;
-       aspect_factor = 0.5f;
+       target_width = view.get_width()/2;
+       target_height = view.get_height()/2;
+       render_aspect = static_cast<float>(target_width)/target_height;
 
        left_shdata.uniform("texture", 0);
        right_shdata.uniform("texture", 0);
index 52eda28ab75ec5361574f49ac9ec7e8a095b801d..4a395fdfbce08152503d490868f165f418693efc 100644 (file)
@@ -4,6 +4,7 @@
 #include <msp/gl/mesh.h>
 #include <msp/gl/program.h>
 #include <msp/gl/programdata.h>
+#include <msp/gl/view.h>
 #include "stereocombiner.h"
 
 namespace Msp {
@@ -19,7 +20,7 @@ private:
        bool cross_eyed;
 
 public:
-       SideBySideCombiner(bool = false);
+       SideBySideCombiner(GL::View &, bool = false);
 
        void set_cross_eyed(bool);
 
index 1730e9a4d9eaa8d4cbce026213988b0d74dbd726..c24a937484aae3c162de692dee4d143959cc2176 100644 (file)
@@ -4,9 +4,9 @@ namespace Msp {
 namespace VR {
 
 StereoCombiner::StereoCombiner():
-       width_factor(1.0f),
-       height_factor(1.0f),
-       aspect_factor(1.0f),
+       target_width(0),
+       target_height(0),
+       render_aspect(1.0f),
        frustum_skew(0.0f)
 { }
 
index 41c5a56945080b2edea0e0503b06128b62ee67b8..8a351eaeb5d6f594b78733822c5731d04b14c059 100644 (file)
@@ -10,9 +10,9 @@ namespace VR {
 class StereoCombiner
 {
 protected:
-       float width_factor;
-       float height_factor;
-       float aspect_factor;
+       unsigned target_width;
+       unsigned target_height;
+       float render_aspect;
        Geometry::Angle<float> fov;
        float frustum_skew;
 
@@ -20,9 +20,9 @@ protected:
 public:
        virtual ~StereoCombiner() { }
 
-       float get_width_factor() const { return width_factor; }
-       float get_height_factor() const { return height_factor; }
-       float get_aspect_factor() const { return aspect_factor; }
+       float get_target_width() const { return target_width; }
+       float get_target_height() const { return target_height; }
+       float get_render_aspect() const { return render_aspect; }
        const Geometry::Angle<float> &get_field_of_view() const { return fov; }
        float get_frustum_skew() const { return frustum_skew; }
 
index efc54dd5f3a38e9158f9e10ec4de640b32eea2e5..459abba7417c64128b645d15c0fa4f10caeaf134 100644 (file)
@@ -7,9 +7,7 @@ using namespace std;
 namespace Msp {
 namespace VR {
 
-StereoView::StereoView(unsigned w, unsigned h, const GL::Camera &c, const GL::Renderable &r, const StereoCombiner &m):
-       width(w),
-       height(h),
+StereoView::StereoView(const GL::Camera &c, const GL::Renderable &r, const StereoCombiner &m):
        base_camera(c),
        renderable(r),
        combiner(0)
@@ -23,8 +21,8 @@ void StereoView::set_combiner(const StereoCombiner &c)
 {
        combiner = &c;
 
-       unsigned w = width*combiner->get_width_factor();
-       unsigned h = height*combiner->get_height_factor();
+       unsigned w = combiner->get_target_width();
+       unsigned h = combiner->get_target_height();
        left.create_target(w, h);
        right.create_target(w, h);
 }
@@ -48,7 +46,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()*combiner->get_aspect_factor();
+       params.aspect = combiner->get_render_aspect();
        params.near_clip = base_camera.get_near_clip();
        params.far_clip = base_camera.get_far_clip();
 
index f9e9a560ea7eefc21b8f4081cf627267e4e601db..911f5f8f1ffd922984d4c705782f07c7af9cdc7f 100644 (file)
@@ -45,8 +45,6 @@ private:
                void render(const GL::Renderable &) const;
        };
 
-       unsigned width;
-       unsigned height;
        const GL::Camera &base_camera;
        const GL::Renderable &renderable;
        const StereoCombiner *combiner;
@@ -56,7 +54,7 @@ private:
        Geometry::Angle<float> strabismus;
 
 public:
-       StereoView(unsigned, unsigned, const GL::Camera &, const GL::Renderable &, const StereoCombiner &);
+       StereoView(const GL::Camera &, const GL::Renderable &, const StereoCombiner &);
 
        void set_combiner(const StereoCombiner &);
        void set_eye_spacing(float);