Give combiners more control over rendering
[libs/vr.git] / source / ovr / oculusriftcombiner.cpp
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