#define MSP_VR_DISPLAYDEVICE_H_
#include <msp/gl/camera.h>
+#include <msp/gl/view.h>
namespace Msp {
namespace VR {
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
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)
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);
right.bind();
right_shdata.apply();
right_mesh.draw();
+
+ view.get_context().swap_buffers();
+ device.end_frame();
}
} // namespace VR
#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 {
class OculusRiftCombiner: public StereoCombiner
{
private:
- const OculusRiftDevice &device;
+ OculusRiftDevice &device;
+ GL::View &view;
GL::Mesh left_mesh;
GL::Mesh right_mesh;
GL::Program shprog;
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;
};
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()
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;
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)
{
right.bind();
right_shdata.apply();
mesh.draw();
+
+ view.get_context().swap_buffers();
}
} // namespace VR
class SideBySideCombiner: public StereoCombiner
{
private:
+ GL::View &view;
GL::Mesh mesh;
GL::Program shprog;
GL::ProgramData left_shdata;
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;
};
void StereoView::render() const
{
+ combiner.prepare();
setup_frame();
if(content)
{