From 11d105c5183b401e5f52e9abb16cf659298cf035 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 17 Sep 2016 02:36:29 +0300 Subject: [PATCH] Give combiners more control over rendering In particular, allow the combiner to decide whether to present the result through the application window or in a device-specific way. It's also easier to take care of proper timing within the library. --- source/displaydevice.h | 8 +++----- source/ovr/oculusriftcombiner.cpp | 11 ++++++++++- source/ovr/oculusriftcombiner.h | 7 +++++-- source/ovr/oculusriftdevice.cpp | 6 +++--- source/ovr/oculusriftdevice.h | 8 ++++---- source/sidebysidecombiner.cpp | 5 ++++- source/sidebysidecombiner.h | 1 + source/stereocombiner.h | 1 + source/stereoview.cpp | 1 + 9 files changed, 32 insertions(+), 16 deletions(-) diff --git a/source/displaydevice.h b/source/displaydevice.h index 81a9d24..cc015a8 100644 --- a/source/displaydevice.h +++ b/source/displaydevice.h @@ -2,6 +2,7 @@ #define MSP_VR_DISPLAYDEVICE_H_ #include +#include namespace Msp { namespace VR { @@ -18,11 +19,8 @@ public: virtual ~DisplayDevice() { } virtual void configure_view(StereoView &) const = 0; - virtual HeadTrackingCamera *create_camera(const GL::Camera &) const = 0; - virtual StereoCombiner *create_combiner() const = 0; - - virtual void begin_frame() = 0; - virtual void end_frame() = 0; + virtual HeadTrackingCamera *create_camera(const GL::Camera &) = 0; + virtual StereoCombiner *create_combiner(GL::View &) = 0; }; } // namespace VR diff --git a/source/ovr/oculusriftcombiner.cpp b/source/ovr/oculusriftcombiner.cpp index d71a93d..edbe08a 100644 --- a/source/ovr/oculusriftcombiner.cpp +++ b/source/ovr/oculusriftcombiner.cpp @@ -76,8 +76,9 @@ void create_distortion_mesh(Msp::GL::Mesh &mesh, ovrHmd hmd, ovrEyeType eye, con namespace Msp { namespace VR { -OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): +OculusRiftCombiner::OculusRiftCombiner(OculusRiftDevice &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) @@ -122,6 +123,11 @@ OculusRiftCombiner::OculusRiftCombiner(const OculusRiftDevice &d): right_shdata.uniform("uv_offset", uv_scale_offset[1].x, 1-uv_scale_offset[1].y); } +void OculusRiftCombiner::prepare() const +{ + device.begin_frame(); +} + void OculusRiftCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const { GL::Bind bind_shprog(shprog); @@ -154,6 +160,9 @@ 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(); } } // namespace VR diff --git a/source/ovr/oculusriftcombiner.h b/source/ovr/oculusriftcombiner.h index 65809a3..27c3c83 100644 --- a/source/ovr/oculusriftcombiner.h +++ b/source/ovr/oculusriftcombiner.h @@ -4,6 +4,7 @@ #include #include #include +#include #include namespace Msp { @@ -18,7 +19,8 @@ are specified in multiples of the screen width. class OculusRiftCombiner: public StereoCombiner { private: - const OculusRiftDevice &device; + OculusRiftDevice &device; + GL::View &view; GL::Mesh left_mesh; GL::Mesh right_mesh; GL::Program shprog; @@ -26,8 +28,9 @@ private: mutable GL::ProgramData right_shdata; public: - OculusRiftCombiner(const OculusRiftDevice &); + OculusRiftCombiner(OculusRiftDevice &, GL::View &); + virtual void prepare() const; virtual void render(const GL::Texture2D &, const GL::Texture2D &) const; }; diff --git a/source/ovr/oculusriftdevice.cpp b/source/ovr/oculusriftdevice.cpp index 32558e0..146f04a 100644 --- a/source/ovr/oculusriftdevice.cpp +++ b/source/ovr/oculusriftdevice.cpp @@ -42,14 +42,14 @@ void OculusRiftDevice::configure_view(StereoView &view) const view.set_eye_spacing(left_desc.HmdToEyeViewOffset.x-right_desc.HmdToEyeViewOffset.x); } -OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) const +OculusRiftCamera *OculusRiftDevice::create_camera(const GL::Camera &bc) { return new OculusRiftCamera(*this, bc); } -OculusRiftCombiner *OculusRiftDevice::create_combiner() const +OculusRiftCombiner *OculusRiftDevice::create_combiner(GL::View &view) { - return new OculusRiftCombiner(*this); + return new OculusRiftCombiner(*this, view); } void OculusRiftDevice::begin_frame() diff --git a/source/ovr/oculusriftdevice.h b/source/ovr/oculusriftdevice.h index a5105d6..62cc047 100644 --- a/source/ovr/oculusriftdevice.h +++ b/source/ovr/oculusriftdevice.h @@ -27,11 +27,11 @@ public: const Private &get_private() const { return *priv; } virtual void configure_view(StereoView &) const; - virtual OculusRiftCamera *create_camera(const GL::Camera &) const; - virtual OculusRiftCombiner *create_combiner() const; + virtual OculusRiftCamera *create_camera(const GL::Camera &); + virtual OculusRiftCombiner *create_combiner(GL::View &); - virtual void begin_frame(); - virtual void end_frame(); + void begin_frame(); + void end_frame(); bool is_timing_active() const { return timing_active; } double get_tracking_time() const; double get_timewarp_time() const; diff --git a/source/sidebysidecombiner.cpp b/source/sidebysidecombiner.cpp index ac35313..b1b8f9d 100644 --- a/source/sidebysidecombiner.cpp +++ b/source/sidebysidecombiner.cpp @@ -26,7 +26,8 @@ const char fs_source[] = namespace Msp { namespace VR { -SideBySideCombiner::SideBySideCombiner(GL::View &view, bool c): +SideBySideCombiner::SideBySideCombiner(GL::View &v, bool c): + view(v), mesh(GL::VERTEX2), shprog(vs_source, fs_source) { @@ -67,6 +68,8 @@ void SideBySideCombiner::render(const GL::Texture2D &left, const GL::Texture2D & right.bind(); right_shdata.apply(); mesh.draw(); + + view.get_context().swap_buffers(); } } // namespace VR diff --git a/source/sidebysidecombiner.h b/source/sidebysidecombiner.h index 4a395fd..77012b8 100644 --- a/source/sidebysidecombiner.h +++ b/source/sidebysidecombiner.h @@ -13,6 +13,7 @@ namespace VR { class SideBySideCombiner: public StereoCombiner { private: + GL::View &view; GL::Mesh mesh; GL::Program shprog; GL::ProgramData left_shdata; diff --git a/source/stereocombiner.h b/source/stereocombiner.h index 8a351ea..5439aeb 100644 --- a/source/stereocombiner.h +++ b/source/stereocombiner.h @@ -26,6 +26,7 @@ public: const Geometry::Angle &get_field_of_view() const { return fov; } float get_frustum_skew() const { return frustum_skew; } + virtual void prepare() const { } virtual void render(const GL::Texture2D &, const GL::Texture2D &) const = 0; }; diff --git a/source/stereoview.cpp b/source/stereoview.cpp index d9f5822..7a72a45 100644 --- a/source/stereoview.cpp +++ b/source/stereoview.cpp @@ -59,6 +59,7 @@ void StereoView::setup_frame() const void StereoView::render() const { + combiner.prepare(); setup_frame(); if(content) { -- 2.45.2