From: Mikko Rasa Date: Fri, 16 Sep 2016 08:39:42 +0000 (+0300) Subject: Provide absolute render target dimensions from StereoCombiner X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=cb460150f6870c172a70237f283c9753250be361;p=libs%2Fvr.git Provide absolute render target dimensions from StereoCombiner --- diff --git a/source/ovr/oculusriftcombiner.cpp b/source/ovr/oculusriftcombiner.cpp index 0d883fa..d71a93d 100644 --- a/source/ovr/oculusriftcombiner.cpp +++ b/source/ovr/oculusriftcombiner.cpp @@ -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); diff --git a/source/sidebysidecombiner.cpp b/source/sidebysidecombiner.cpp index c5aef04..ac35313 100644 --- a/source/sidebysidecombiner.cpp +++ b/source/sidebysidecombiner.cpp @@ -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(target_width)/target_height; left_shdata.uniform("texture", 0); right_shdata.uniform("texture", 0); diff --git a/source/sidebysidecombiner.h b/source/sidebysidecombiner.h index 52eda28..4a395fd 100644 --- a/source/sidebysidecombiner.h +++ b/source/sidebysidecombiner.h @@ -4,6 +4,7 @@ #include #include #include +#include #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); diff --git a/source/stereocombiner.cpp b/source/stereocombiner.cpp index 1730e9a..c24a937 100644 --- a/source/stereocombiner.cpp +++ b/source/stereocombiner.cpp @@ -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) { } diff --git a/source/stereocombiner.h b/source/stereocombiner.h index 41c5a56..8a351ea 100644 --- a/source/stereocombiner.h +++ b/source/stereocombiner.h @@ -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 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 &get_field_of_view() const { return fov; } float get_frustum_skew() const { return frustum_skew; } diff --git a/source/stereoview.cpp b/source/stereoview.cpp index efc54dd..459abba 100644 --- a/source/stereoview.cpp +++ b/source/stereoview.cpp @@ -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::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(); diff --git a/source/stereoview.h b/source/stereoview.h index f9e9a56..911f5f8 100644 --- a/source/stereoview.h +++ b/source/stereoview.h @@ -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 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);