Debian Codegraph @

3rdparty/osgXR/src/XRStateCallbacks.h

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-only
2 // Copyright (C) 2021 James Hogan <[email protected]>
3
4 #ifndef OSGXR_XRSTATE_CALLBACKS
5 #define OSGXR_XRSTATE_CALLBACKS 1
6
7 #include "XRState.h"
8
9 #include <osg/Camera>
10 #include <osg/GraphicsContext>
11 #include <osg/View>
12
13 #include <osgUtil/SceneView>
14
15 namespace osgXR {
16
17 class SlaveCamsUpdateSlaveCallback : public osg::View::Slave::UpdateSlaveCallback
18 {
19 public:
20
21 SlaveCamsUpdateSlaveCallback(uint32_t viewIndex,
22 XRState *xrState,
23 osg::MatrixTransform *visMaskTransform) :
24 _viewIndex(viewIndex),
25 _xrState(xrState),
26 _visMaskTransform(visMaskTransform)
27 {
28 }
29
30 void updateSlave(osg::View& view, osg::View::Slave& slave) override
31 {
32 _xrState->updateSlave(_viewIndex, view, slave);
33 if (_visMaskTransform.valid())
34 _xrState->updateVisibilityMaskTransform(slave._camera,
35 _visMaskTransform.get());
36 }
37
38 protected:
39
40 uint32_t _viewIndex;
41 osg::observer_ptr<XRState> _xrState;
42 osg::observer_ptr<osg::MatrixTransform> _visMaskTransform;
43 };
44
45 class SceneViewUpdateSlaveCallback : public osg::View::Slave::UpdateSlaveCallback
46 {
47 public:
48
49 SceneViewUpdateSlaveCallback(osg::ref_ptr<XRState> xrState,
50 osg::ref_ptr<osg::MatrixTransform> visMaskTransform) :
51 _xrState(xrState),
52 _visMaskTransform(visMaskTransform)
53 {
54 }
55
56 void updateSlave(osg::View& view, osg::View::Slave& slave) override
57 {
58 if (_visMaskTransform.valid())
59 _xrState->updateVisibilityMaskTransform(slave._camera,
60 _visMaskTransform.get());
61 }
62
63 protected:
64
65 osg::observer_ptr<XRState> _xrState;
66 osg::observer_ptr<osg::MatrixTransform> _visMaskTransform;
67 };
68
69 class ComputeStereoMatricesCallback : public osgUtil::SceneView::ComputeStereoMatricesCallback
70 {
71 public:
72
73 ComputeStereoMatricesCallback(XRState *xrState,
74 osgUtil::SceneView *sceneView) :
75 _xrState(xrState),
76 _sceneView(sceneView)
77 {
78 }
79
80 osg::Matrixd computeLeftEyeProjection(const osg::Matrixd& projection) const override
81 {
82 return _xrState->getEyeProjection(_sceneView->getFrameStamp(),
83 0, projection);
84 }
85
86 osg::Matrixd computeLeftEyeView(const osg::Matrixd& view) const override
87 {
88 return _xrState->getEyeView(_sceneView->getFrameStamp(),
89 0, view);
90 }
91
92 osg::Matrixd computeRightEyeProjection(const osg::Matrixd& projection) const override
93 {
94 return _xrState->getEyeProjection(_sceneView->getFrameStamp(),
95 1, projection);
96 }
97
98 osg::Matrixd computeRightEyeView(const osg::Matrixd& view) const override
99 {
100 return _xrState->getEyeView(_sceneView->getFrameStamp(),
101 1, view);
102 }
103
104 protected:
105
106 osg::observer_ptr<XRState> _xrState;
107 osg::observer_ptr<osgUtil::SceneView> _sceneView;
108 };
109
110 class InitialDrawCallback : public osg::Camera::DrawCallback
111 {
112 public:
113
114 InitialDrawCallback(osg::ref_ptr<XRState> xrState) :
115 _xrState(xrState)
116 {
117 }
118
119 void operator()(osg::RenderInfo& renderInfo) const override
120 {
121 _xrState->initialDrawCallback(renderInfo);
122 }
123
124 void releaseGLObjects(osg::State* state) const override
125 {
126 _xrState->releaseGLObjects(state);
127 }
128
129 protected:
130
131 osg::observer_ptr<XRState> _xrState;
132 };
133
134 class PreDrawCallback : public osg::Camera::DrawCallback
135 {
136 public:
137
138 PreDrawCallback(osg::ref_ptr<XRState::XRSwapchain> xrSwapchain) :
139 _xrSwapchain(xrSwapchain)
140 {
141 }
142
143 void operator()(osg::RenderInfo& renderInfo) const override
144 {
145 _xrSwapchain->preDrawCallback(renderInfo);
146 }
147
148 protected:
149
150 osg::observer_ptr<XRState::XRSwapchain> _xrSwapchain;
151 };
152
153 class PostDrawCallback : public osg::Camera::DrawCallback
154 {
155 public:
156
157 PostDrawCallback(osg::ref_ptr<XRState::XRSwapchain> xrSwapchain) :
158 _xrSwapchain(xrSwapchain)
159 {
160 }
161
162 void operator()(osg::RenderInfo& renderInfo) const override
163 {
164 _xrSwapchain->postDrawCallback(renderInfo);
165 }
166
167 protected:
168
169 osg::observer_ptr<XRState::XRSwapchain> _xrSwapchain;
170 };
171
172 class SwapCallback : public osg::GraphicsContext::SwapCallback
173 {
174 public:
175
176 explicit SwapCallback(osg::ref_ptr<XRState> xrState) :
177 _xrState(xrState),
178 _frameIndex(0)
179 {
180 }
181
182 void swapBuffersImplementation(osg::GraphicsContext* gc)
183 {
184 _xrState->swapBuffersImplementation(gc);
185 }
186
187 int frameIndex() const
188 {
189 return _frameIndex;
190 }
191
192 private:
193
194 osg::observer_ptr<XRState> _xrState;
195 int _frameIndex;
196 };
197
198 }
199
200 #endif