]> git.tdb.fi Git - libs/vr.git/blob - source/openvr/openvrcombiner.cpp
2272a1a3509dad7b4667b49fb4a6c348d2026078
[libs/vr.git] / source / openvr / openvrcombiner.cpp
1 #include <openvr.h>
2 #include "openvrcombiner.h"
3 #include "openvrdevice.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(OpenVRDevice &d):
15         device(d)
16 {
17         vr::IVRSystem *vr_sys = vr::VRSystem();
18         uint32_t w, h;
19         vr_sys->GetRecommendedRenderTargetSize(&w, &h);
20         target_width = w;
21         target_height = h;
22
23         Frustum left_frustum = Private::get_projection(vr::Eye_Left);
24         Frustum right_frustum = Private::get_projection(vr::Eye_Right);
25         configure_eye_frustums(left_frustum, right_frustum);
26 }
27
28 void OpenVRCombiner::prepare() const
29 {
30         device.update_pose_matrices();
31 }
32
33 void OpenVRCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const
34 {
35         vr::Texture_t tex;
36         tex.eType = vr::API_OpenGL;
37         tex.eColorSpace = vr::ColorSpace_Gamma;
38
39         vr::IVRCompositor *compositor = vr::VRCompositor();
40         tex.handle = reinterpret_cast<void *>(left.get_id());
41         compositor->Submit(vr::Eye_Left, &tex);
42         tex.handle = reinterpret_cast<void *>(right.get_id());
43         compositor->Submit(vr::Eye_Right, &tex);
44 }
45
46
47 StereoCombiner::Frustum OpenVRCombiner::Private::get_projection(vr::EVREye eye)
48 {
49         Frustum frustum;
50         /* The parameter order is documented as left, right, top, bottom; however
51         the third parameter is actually negative and fourth one positive. */
52         vr::VRSystem()->GetProjectionRaw(eye, &frustum.left, &frustum.right, &frustum.bottom, &frustum.top);
53         return frustum;
54 }
55
56 } // namespace VR
57 } // namespace Msp