]> git.tdb.fi Git - libs/vr.git/blob - source/openvr/openvrcombiner.cpp
Rename DisplayDevice to System
[libs/vr.git] / source / openvr / openvrcombiner.cpp
1 #include <openvr.h>
2 #include "openvrcombiner.h"
3 #include "openvrsystem.h"
4
5 namespace Msp {
6 namespace VR {
7
8 struct OpenVRCombiner::Private
9 {
10         static Frustum get_projection(vr::EVREye);
11 };
12
13
14 OpenVRCombiner::OpenVRCombiner(OpenVRSystem &d, GL::View &v):
15         device(d),
16         view(v)
17 {
18         vr::IVRSystem *vr_sys = vr::VRSystem();
19         uint32_t w, h;
20         vr_sys->GetRecommendedRenderTargetSize(&w, &h);
21         target_width = w;
22         target_height = h;
23
24         Frustum left_frustum = Private::get_projection(vr::Eye_Left);
25         Frustum right_frustum = Private::get_projection(vr::Eye_Right);
26         configure_eye_frustums(left_frustum, right_frustum);
27
28         set_mirroring(true);
29 }
30
31 void OpenVRCombiner::prepare() const
32 {
33         device.update_pose_matrices();
34 }
35
36 void OpenVRCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const
37 {
38         vr::Texture_t tex;
39         tex.eType = vr::API_OpenGL;
40         tex.eColorSpace = vr::ColorSpace_Gamma;
41
42         vr::IVRCompositor *compositor = vr::VRCompositor();
43         tex.handle = reinterpret_cast<void *>(left.get_id());
44         compositor->Submit(vr::Eye_Left, &tex);
45         tex.handle = reinterpret_cast<void *>(right.get_id());
46         compositor->Submit(vr::Eye_Right, &tex);
47
48         if(mirror)
49         {
50                 mirror->shdata.uniform("scale", view.get_aspect()/render_aspect/2, 0.5f);
51                 render_mirror(left);
52                 view.get_context().swap_buffers();
53         }
54 }
55
56
57 StereoCombiner::Frustum OpenVRCombiner::Private::get_projection(vr::EVREye eye)
58 {
59         Frustum frustum;
60         /* The parameter order is documented as left, right, top, bottom; however
61         the third parameter is actually negative and fourth one positive. */
62         vr::VRSystem()->GetProjectionRaw(eye, &frustum.left, &frustum.right, &frustum.bottom, &frustum.top);
63         return frustum;
64 }
65
66 } // namespace VR
67 } // namespace Msp