|
9 | 9 | #include "interactions/interaction_teleport.h"
|
10 | 10 | #include "interactions/interaction_slide.h"
|
11 | 11 |
|
12 |
| -Game::Game(vsg::ref_ptr<vsgvr::Instance> xrInstance, vsg::ref_ptr<vsgvr::Viewer> vr, vsg::ref_ptr<vsg::Viewer> desktopViewer) |
| 12 | +Game::Game(vsg::ref_ptr<vsgvr::Instance> xrInstance, vsg::ref_ptr<vsgvr::Viewer> vr, vsg::ref_ptr<vsg::Viewer> desktopViewer, bool displayDesktopWindow) |
13 | 13 | : _xrInstance(xrInstance)
|
14 | 14 | , _vr(vr)
|
15 | 15 | , _desktopViewer(desktopViewer)
|
| 16 | + , _desktopWindowEnabled(displayDesktopWindow) |
16 | 17 | {
|
17 | 18 | loadScene();
|
18 | 19 | initVR();
|
@@ -62,17 +63,20 @@ void Game::initVR()
|
62 | 63 | // OpenXRViewer can't be a child class of Viewer yet (Think this was due to the assumption that a Window/Viewer has presentation / A Surface)
|
63 | 64 | _vr->compile();
|
64 | 65 |
|
65 |
| - // Create a CommandGraph to render the desktop window |
66 |
| - auto lookAt = vsg::LookAt::create(vsg::dvec3(-4.0, -15.0, 25.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 0.0, 1.0)); |
67 |
| - auto desktopWindow = _desktopViewer->windows().front(); |
68 |
| - auto perspective = vsg::Perspective::create(30.0, |
69 |
| - static_cast<double>(desktopWindow->extent2D().width) / static_cast<double>(desktopWindow->extent2D().height) |
70 |
| - , 0.1, 100.0 |
71 |
| - ); |
72 |
| - _desktopCamera = vsg::Camera::create(perspective, lookAt, vsg::ViewportState::create(desktopWindow->extent2D())); |
73 |
| - auto desktopCommandGraph = vsg::createCommandGraphForView(desktopWindow, _desktopCamera, _sceneRoot, VK_SUBPASS_CONTENTS_INLINE, false); |
74 |
| - _desktopViewer->assignRecordAndSubmitTaskAndPresentation({ desktopCommandGraph }); |
75 |
| - _desktopViewer->compile(); |
| 66 | + if(_desktopWindowEnabled) |
| 67 | + { |
| 68 | + // Create a CommandGraph to render the desktop window |
| 69 | + auto lookAt = vsg::LookAt::create(vsg::dvec3(-4.0, -15.0, 25.0), vsg::dvec3(0.0, 0.0, 0.0), vsg::dvec3(0.0, 0.0, 1.0)); |
| 70 | + auto desktopWindow = _desktopViewer->windows().front(); |
| 71 | + auto perspective = vsg::Perspective::create(30.0, |
| 72 | + static_cast<double>(desktopWindow->extent2D().width) / static_cast<double>(desktopWindow->extent2D().height) |
| 73 | + , 0.1, 100.0 |
| 74 | + ); |
| 75 | + _desktopCamera = vsg::Camera::create(perspective, lookAt, vsg::ViewportState::create(desktopWindow->extent2D())); |
| 76 | + auto desktopCommandGraph = vsg::createCommandGraphForView(desktopWindow, _desktopCamera, _sceneRoot, VK_SUBPASS_CONTENTS_INLINE, false); |
| 77 | + _desktopViewer->assignRecordAndSubmitTaskAndPresentation({ desktopCommandGraph }); |
| 78 | + _desktopViewer->compile(); |
| 79 | + } |
76 | 80 | }
|
77 | 81 |
|
78 | 82 | void Game::initActions()
|
@@ -181,29 +185,32 @@ void Game::frame()
|
181 | 185 | _controllerRight->matrix = _rightHandPose->getTransform();
|
182 | 186 | }
|
183 | 187 |
|
184 |
| - // Match the desktop camera to the HMD view |
185 |
| - _desktopCamera->viewMatrix = _xrCameras.front()->viewMatrix; |
186 |
| - _desktopCamera->projectionMatrix = _xrCameras.front()->projectionMatrix; |
187 |
| - |
188 | 188 | // The session is running in some form, and a frame must be processed
|
189 | 189 | // The OpenXR frame loop takes priority - Acquire a frame to render into
|
190 | 190 | auto shouldQuit = false;
|
191 | 191 |
|
192 |
| - // Desktop render |
193 |
| - // * The scene graph is updated by the desktop render |
194 |
| - // * if PollEventsResult::RunningDontRender the desktop render could be skipped |
195 |
| - if (_desktopViewer->advanceToNextFrame()) |
| 192 | + if(_desktopWindowEnabled) |
196 | 193 | {
|
197 |
| - _desktopViewer->handleEvents(); |
198 |
| - _desktopViewer->update(); |
199 |
| - _desktopViewer->recordAndSubmit(); |
200 |
| - _desktopViewer->present(); |
201 |
| - } |
202 |
| - else |
203 |
| - { |
204 |
| - // Desktop window was closed |
205 |
| - shouldQuit = true; |
206 |
| - return; |
| 194 | + // Match the desktop camera to the HMD view |
| 195 | + _desktopCamera->viewMatrix = _xrCameras.front()->viewMatrix; |
| 196 | + _desktopCamera->projectionMatrix = _xrCameras.front()->projectionMatrix; |
| 197 | + |
| 198 | + // Desktop render |
| 199 | + // * The scene graph is updated by the desktop render |
| 200 | + // * if PollEventsResult::RunningDontRender the desktop render could be skipped |
| 201 | + if (_desktopViewer->advanceToNextFrame()) |
| 202 | + { |
| 203 | + _desktopViewer->handleEvents(); |
| 204 | + _desktopViewer->update(); |
| 205 | + _desktopViewer->recordAndSubmit(); |
| 206 | + _desktopViewer->present(); |
| 207 | + } |
| 208 | + else |
| 209 | + { |
| 210 | + // Desktop window was closed |
| 211 | + shouldQuit = true; |
| 212 | + return; |
| 213 | + } |
207 | 214 | }
|
208 | 215 |
|
209 | 216 | if (_vr->advanceToNextFrame())
|
|
0 commit comments