2 #include "stereocombiner.h"
3 #include "stereoview.h"
10 StereoView::StereoView(unsigned w, unsigned h, const Camera &c, const Renderable &r, const StereoCombiner &m):
18 set_eye_spacing(0.07);
21 void StereoView::set_combiner(const StereoCombiner &c)
25 unsigned w = width/combiner->get_width_divisor();
26 unsigned h = height/combiner->get_height_divisor();
27 left.create_target(w, h);
28 right.create_target(w, h);
31 void StereoView::set_eye_spacing(float s)
36 void StereoView::setup_frame() const
38 offset_axis = normalize(cross(base_camera.get_look_direction(), base_camera.get_up_direction()))*0.5f;
41 params.fov = combiner->get_field_of_view();
42 if(params.fov==Geometry::Angle<float>::zero())
43 params.fov = base_camera.get_field_of_view();
45 params.aspect = base_camera.get_aspect();
46 if(!combiner->is_aspect_kept())
47 params.aspect = params.aspect*combiner->get_height_divisor()/combiner->get_width_divisor();
49 params.near_clip = base_camera.get_near_clip();
50 params.far_clip = base_camera.get_far_clip();
52 left.setup_frame(base_camera, offset_axis*-eye_spacing, params);
53 right.setup_frame(base_camera, offset_axis*eye_spacing, params);
55 renderable.setup_frame();
58 void StereoView::finish_frame() const
60 renderable.finish_frame();
63 void StereoView::render(const Tag &tag) const
66 left.render(renderable, tag);
67 right.render(renderable, tag);
68 combiner->render(left.target->color, right.target->color);
72 void StereoView::render(Renderer &renderer, const Tag &tag) const
79 StereoView::RenderTarget::RenderTarget(unsigned width, unsigned height)
81 color.set_min_filter(LINEAR);
82 color.set_wrap(CLAMP_TO_EDGE);
83 color.storage(RGB, width, height);
84 fbo.attach(COLOR_ATTACHMENT0, color);
86 depth.storage(DEPTH_COMPONENT, width, height);
87 fbo.attach(DEPTH_ATTACHMENT, depth);
91 StereoView::Eye::Eye():
95 void StereoView::Eye::create_target(unsigned w, unsigned h)
98 target = new RenderTarget(w, h);
101 void StereoView::Eye::setup_frame(const Camera &base_camera, const Vector3 &offset, const EyeParams ¶ms) const
103 camera.set_position(base_camera.get_position()+offset);
104 camera.set_up_direction(base_camera.get_up_direction());
105 camera.set_look_direction(base_camera.get_look_direction());
107 camera.set_field_of_view(params.fov);
108 camera.set_aspect(params.aspect);
109 camera.set_depth_clip(params.near_clip, params.far_clip);
112 void StereoView::Eye::render(const Renderable &renderable, const Tag &tag) const
114 Bind bind_fbo(target->fbo);
115 Renderer renderer(&camera);
116 renderable.render(renderer, tag);