]> git.tdb.fi Git - libs/vr.git/blobdiff - source/sidebysidecombiner.cpp
Update camera pose as part of the render call
[libs/vr.git] / source / sidebysidecombiner.cpp
index b9d1d89c243023faf1def099df849dc7b05b8d56..b1b8f9db06ed2e25537164bf0d4459b943dd0a76 100644 (file)
@@ -1,6 +1,6 @@
-#include "meshbuilder.h"
+#include <msp/gl/meshbuilder.h>
+#include <msp/gl/texture2d.h>
 #include "sidebysidecombiner.h"
-#include "texture2d.h"
 
 namespace {
 
@@ -24,21 +24,24 @@ const char fs_source[] =
 }
 
 namespace Msp {
-namespace GL {
+namespace VR {
 
-SideBySideCombiner::SideBySideCombiner(bool c):
-       mesh(VERTEX2),
+SideBySideCombiner::SideBySideCombiner(GL::View &v, bool c):
+       view(v),
+       mesh(GL::VERTEX2),
        shprog(vs_source, fs_source)
 {
-       width_div = 2;
+       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);
 
        set_cross_eyed(c);
 
-       MeshBuilder bld(mesh);
-       bld.begin(TRIANGLE_STRIP);
+       GL::MeshBuilder bld(mesh);
+       bld.begin(GL::TRIANGLE_STRIP);
        bld.vertex(-1, 1);
        bld.vertex(-1, -1);
        bld.vertex(1, 1);
@@ -54,18 +57,20 @@ void SideBySideCombiner::set_cross_eyed(bool c)
        right_shdata.uniform("offset", m);
 }
 
-void SideBySideCombiner::render(const Texture2D &left, const Texture2D &right) const
+void SideBySideCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const
 {
-       Bind bind_shprog(shprog);
+       GL::Bind bind_shprog(shprog);
 
-       Bind bind_tex(left);
+       GL::Bind bind_tex(left);
        left_shdata.apply();
        mesh.draw();
 
        right.bind();
        right_shdata.apply();
        mesh.draw();
+
+       view.get_context().swap_buffers();
 }
 
-} // namespace GL
+} // namespace VR
 } // namespace Msp