#include <cmath>
-#include "meshbuilder.h"
+#include <msp/gl/meshbuilder.h>
+#include <msp/gl/texture2d.h>
#include "oculusriftcombiner.h"
-#include "texture2d.h"
using namespace std;
}
namespace Msp {
-namespace GL {
+namespace VR {
OculusRiftCombiner::OculusRiftCombiner():
- mesh(VERTEX2),
+ mesh(GL::VERTEX2),
shprog(vs_source, fs_source),
// Default values copied from the SDK
view_distance(0.438f),
// This will also call update_parameters
set_distortion(1.0f, 0.22f, 0.24f);
- 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);
}
}
-void OculusRiftCombiner::render(const Texture2D &left, const Texture2D &right) const
+void OculusRiftCombiner::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();
mesh.draw();
}
-} // namespace GL
+} // namespace VR
} // namespace Msp
-#ifndef MSP_GL_OCULUSRIFTCOMBINER_H_
-#define MSP_GL_OCULUSRIFTCOMBINER_H_
+#ifndef MSP_VR_OCULUSRIFTCOMBINER_H_
+#define MSP_VR_OCULUSRIFTCOMBINER_H_
-#include "mesh.h"
-#include "program.h"
-#include "programdata.h"
+#include <msp/gl/mesh.h>
+#include <msp/gl/program.h>
+#include <msp/gl/programdata.h>
#include "stereocombiner.h"
namespace Msp {
-namespace GL {
+namespace VR {
/**
Presents a stereo view in a way suitable for an Oculus Rift HMD. All distances
class OculusRiftCombiner: public StereoCombiner
{
private:
- Mesh mesh;
- Program shprog;
- ProgramData left_shdata;
- ProgramData right_shdata;
+ GL::Mesh mesh;
+ GL::Program shprog;
+ GL::ProgramData left_shdata;
+ GL::ProgramData right_shdata;
float view_distance;
float lens_separation;
float eye_separation;
float undistort(float) const;
public:
- virtual void render(const Texture2D &, const Texture2D &) const;
+ virtual void render(const GL::Texture2D &, const GL::Texture2D &) const;
};
-} // namespace GL
+} // namespace VR
} // namespace Msp
#endif
-#include "meshbuilder.h"
+#include <msp/gl/meshbuilder.h>
+#include <msp/gl/texture2d.h>
#include "sidebysidecombiner.h"
-#include "texture2d.h"
namespace {
}
namespace Msp {
-namespace GL {
+namespace VR {
SideBySideCombiner::SideBySideCombiner(bool c):
- mesh(VERTEX2),
+ mesh(GL::VERTEX2),
shprog(vs_source, fs_source)
{
width_div = 2;
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);
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();
mesh.draw();
}
-} // namespace GL
+} // namespace VR
} // namespace Msp
-#ifndef MSP_GL_SIDEBYSIDECOMBINER_H_
-#define MSP_GL_SIDEBYSIDECOMBINER_H_
+#ifndef MSP_VR_SIDEBYSIDECOMBINER_H_
+#define MSP_VR_SIDEBYSIDECOMBINER_H_
-#include "mesh.h"
-#include "program.h"
-#include "programdata.h"
+#include <msp/gl/mesh.h>
+#include <msp/gl/program.h>
+#include <msp/gl/programdata.h>
#include "stereocombiner.h"
namespace Msp {
-namespace GL {
+namespace VR {
class SideBySideCombiner: public StereoCombiner
{
private:
- Mesh mesh;
- Program shprog;
- ProgramData left_shdata;
- ProgramData right_shdata;
+ GL::Mesh mesh;
+ GL::Program shprog;
+ GL::ProgramData left_shdata;
+ GL::ProgramData right_shdata;
bool cross_eyed;
public:
void set_cross_eyed(bool);
- virtual void render(const Texture2D &, const Texture2D &) const;
+ virtual void render(const GL::Texture2D &, const GL::Texture2D &) const;
};
-} // namespace GL
+} // namespace VR
} // namespace Msp
#endif
#include "stereocombiner.h"
namespace Msp {
-namespace GL {
+namespace VR {
StereoCombiner::StereoCombiner():
width_div(1),
oversize(1.0f)
{ }
-} // namespace GL
+} // namespace VR
} // namespace Msp
-#ifndef MSP_GL_STEREOCOMBINER_H_
-#define MSP_GL_STEREOCOMBINER_H_
+#ifndef MSP_VR_STEREOCOMBINER_H_
+#define MSP_VR_STEREOCOMBINER_H_
#include <msp/geometry/angle.h>
+#include <msp/gl/texture2d.h>
namespace Msp {
-namespace GL {
-
-class Texture2D;
+namespace VR {
class StereoCombiner
{
const Geometry::Angle<float> &get_field_of_view() const { return fov; }
float get_oversize() const { return oversize; }
- virtual void render(const Texture2D &, const Texture2D &) const = 0;
+ virtual void render(const GL::Texture2D &, const GL::Texture2D &) const = 0;
};
-} // namespace GL
+} // namespace VR
} // namespace Msp
#endif
-#include "renderer.h"
+#include <msp/gl/renderer.h>
#include "stereocombiner.h"
#include "stereoview.h"
using namespace std;
namespace Msp {
-namespace GL {
+namespace VR {
-StereoView::StereoView(unsigned w, unsigned h, const Camera &c, const Renderable &r, const StereoCombiner &m):
+StereoView::StereoView(unsigned w, unsigned h, const GL::Camera &c, const GL::Renderable &r, const StereoCombiner &m):
width(w),
height(h),
base_camera(c),
renderable.finish_frame();
}
-void StereoView::render(const Tag &tag) const
+void StereoView::render(const GL::Tag &tag) const
{
setup_frame();
left.render(renderable, tag);
finish_frame();
}
-void StereoView::render(Renderer &renderer, const Tag &tag) const
+void StereoView::render(GL::Renderer &renderer, const GL::Tag &tag) const
{
renderer.escape();
return render(tag);
StereoView::RenderTarget::RenderTarget(unsigned width, unsigned height)
{
- color.set_min_filter(LINEAR);
- color.set_wrap(CLAMP_TO_EDGE);
- color.storage(RGB, width, height);
- fbo.attach(COLOR_ATTACHMENT0, color);
+ color.set_min_filter(GL::LINEAR);
+ color.set_wrap(GL::CLAMP_TO_EDGE);
+ color.storage(GL::RGB, width, height);
+ fbo.attach(GL::COLOR_ATTACHMENT0, color);
- depth.storage(DEPTH_COMPONENT, width, height);
- fbo.attach(DEPTH_ATTACHMENT, depth);
+ depth.storage(GL::DEPTH_COMPONENT, width, height);
+ fbo.attach(GL::DEPTH_ATTACHMENT, depth);
}
target = new RenderTarget(w, h);
}
-void StereoView::Eye::setup_frame(const Camera &base_camera, const Vector3 &offset, const EyeParams ¶ms) const
+void StereoView::Eye::setup_frame(const GL::Camera &base_camera, const GL::Vector3 &offset, const EyeParams ¶ms) const
{
camera.set_position(base_camera.get_position()+offset);
camera.set_up_direction(base_camera.get_up_direction());
camera.set_depth_clip(params.near_clip, params.far_clip);
}
-void StereoView::Eye::render(const Renderable &renderable, const Tag &tag) const
+void StereoView::Eye::render(const GL::Renderable &renderable, const GL::Tag &tag) const
{
- Bind bind_fbo(target->fbo);
- Renderer renderer(&camera);
+ GL::Bind bind_fbo(target->fbo);
+ GL::Renderer renderer(&camera);
renderable.render(renderer, tag);
}
-} // namespace GL
+} // namespace VR
} // namespace Msp
-#ifndef MSP_GL_STEREOVIEW_H_
-#define MSP_GL_STEREOVIEW_H_
+#ifndef MSP_VR_STEREOVIEW_H_
+#define MSP_VR_STEREOVIEW_H_
#include <msp/geometry/angle.h>
-#include "camera.h"
-#include "framebuffer.h"
-#include "renderable.h"
-#include "renderbuffer.h"
-#include "texture2d.h"
+#include <msp/gl/camera.h>
+#include <msp/gl/framebuffer.h>
+#include <msp/gl/renderable.h>
+#include <msp/gl/renderbuffer.h>
+#include <msp/gl/texture2d.h>
namespace Msp {
-namespace GL {
+namespace VR {
class StereoCombiner;
-class StereoView: public Renderable
+class StereoView: public GL::Renderable
{
private:
struct RenderTarget
{
- Framebuffer fbo;
- Texture2D color;
- Renderbuffer depth;
+ GL::Framebuffer fbo;
+ GL::Texture2D color;
+ GL::Renderbuffer depth;
RenderTarget(unsigned, unsigned);
};
struct Eye
{
- mutable Camera camera;
+ mutable GL::Camera camera;
RenderTarget *target;
Eye();
void create_target(unsigned, unsigned);
- void setup_frame(const Camera &, const Vector3 &, const EyeParams &) const;
- void render(const Renderable &, const Tag &) const;
+ void setup_frame(const GL::Camera &, const GL::Vector3 &, const EyeParams &) const;
+ void render(const GL::Renderable &, const GL::Tag &) const;
};
unsigned width;
unsigned height;
- const Camera &base_camera;
- const Renderable &renderable;
+ const GL::Camera &base_camera;
+ const GL::Renderable &renderable;
const StereoCombiner *combiner;
Eye left;
Eye right;
float eye_spacing;
- mutable Vector3 offset_axis;
+ mutable GL::Vector3 offset_axis;
public:
- StereoView(unsigned, unsigned, const Camera &, const Renderable &, const StereoCombiner &);
+ StereoView(unsigned, unsigned, const GL::Camera &, const GL::Renderable &, const StereoCombiner &);
void set_combiner(const StereoCombiner &);
void set_eye_spacing(float);
virtual void setup_frame() const;
virtual void finish_frame() const;
- virtual void render(const Tag & = Tag()) const;
- virtual void render(Renderer &, const Tag & = Tag()) const;
+ virtual void render(const GL::Tag & = GL::Tag()) const;
+ virtual void render(GL::Renderer &, const GL::Tag & = GL::Tag()) const;
};
-} // namespace GL
+} // namespace VR
} // namespace Msp
#endif