]> git.tdb.fi Git - libs/vr.git/commitdiff
Give combiners more control over rendering
authorMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 23:36:29 +0000 (02:36 +0300)
committerMikko Rasa <tdb@tdb.fi>
Fri, 16 Sep 2016 23:36:29 +0000 (02:36 +0300)
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
source/ovr/oculusriftcombiner.cpp
source/ovr/oculusriftcombiner.h
source/ovr/oculusriftdevice.cpp
source/ovr/oculusriftdevice.h
source/sidebysidecombiner.cpp
source/sidebysidecombiner.h
source/stereocombiner.h
source/stereoview.cpp

index 81a9d240adb8189b24d64b0c54eac92f242fc5b1..cc015a8f6136c3139cbc6df09b69317f661428db 100644 (file)
@@ -2,6 +2,7 @@
 #define MSP_VR_DISPLAYDEVICE_H_
 
 #include <msp/gl/camera.h>
+#include <msp/gl/view.h>
 
 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
index d71a93d2e1d6f61913a78887bfc2182741d04206..edbe08ae56e4ce9b0dcc833df9109b65d9ce9b85 100644 (file)
@@ -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
index 65809a3a2c6827c79d1d529d234b4f95d30d0181..27c3c83bac49caa7ad8a0d7e590e34d7ac8b4ea9 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 <msp/vr/stereocombiner.h>
 
 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;
 };
 
index 32558e049aab576cc82403789c65058b78f9d7f9..146f04a7c0ad32a12c94dead97ea46265bec34fa 100644 (file)
@@ -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()
index a5105d603181dea5682a8528b11a4c38a3e06853..62cc0473bb6748895eebd9baf96bdcff0bf0c881 100644 (file)
@@ -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;
index ac353133bac26ea5abb2387b9731cc4b5db7589f..b1b8f9db06ed2e25537164bf0d4459b943dd0a76 100644 (file)
@@ -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
index 4a395fdfbce08152503d490868f165f418693efc..77012b8b3a12edf1e1c6d717924cb62d6bff6a9d 100644 (file)
@@ -13,6 +13,7 @@ namespace VR {
 class SideBySideCombiner: public StereoCombiner
 {
 private:
+       GL::View &view;
        GL::Mesh mesh;
        GL::Program shprog;
        GL::ProgramData left_shdata;
index 8a351eaeb5d6f594b78733822c5731d04b14c059..5439aeba673da3a0d46de75a60e1445995e2dd7a 100644 (file)
@@ -26,6 +26,7 @@ public:
        const Geometry::Angle<float> &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;
 };
 
index d9f5822a4913204e3f9b8bb7997ba46f65e97b74..7a72a452c279a31b1e64b663441a8621aefc04a3 100644 (file)
@@ -59,6 +59,7 @@ void StereoView::setup_frame() const
 
 void StereoView::render() const
 {
+       combiner.prepare();
        setup_frame();
        if(content)
        {