Skip to content

Commit 0d176df

Browse files
committed
Fix quest native performance in locomotion example, expose near/far planes on Viewer
1 parent c61d56c commit 0d176df

File tree

9 files changed

+10990
-119
lines changed

9 files changed

+10990
-119
lines changed

examples/interaction_locomotion/game.cpp

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
#include "interactions/interaction_teleport.h"
1010
#include "interactions/interaction_slide.h"
1111

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)
1313
: _xrInstance(xrInstance)
1414
, _vr(vr)
1515
, _desktopViewer(desktopViewer)
16+
, _desktopWindowEnabled(displayDesktopWindow)
1617
{
1718
loadScene();
1819
initVR();
@@ -62,17 +63,20 @@ void Game::initVR()
6263
// 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)
6364
_vr->compile();
6465

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+
}
7680
}
7781

7882
void Game::initActions()
@@ -181,29 +185,32 @@ void Game::frame()
181185
_controllerRight->matrix = _rightHandPose->getTransform();
182186
}
183187

184-
// Match the desktop camera to the HMD view
185-
_desktopCamera->viewMatrix = _xrCameras.front()->viewMatrix;
186-
_desktopCamera->projectionMatrix = _xrCameras.front()->projectionMatrix;
187-
188188
// The session is running in some form, and a frame must be processed
189189
// The OpenXR frame loop takes priority - Acquire a frame to render into
190190
auto shouldQuit = false;
191191

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)
196193
{
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+
}
207214
}
208215

209216
if (_vr->advanceToNextFrame())

examples/interaction_locomotion/game.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
class Game {
1616
public:
17-
Game(vsg::ref_ptr<vsgvr::Instance> xrInstance, vsg::ref_ptr<vsgvr::Viewer> vr, vsg::ref_ptr<vsg::Viewer> desktopViewer);
17+
Game(vsg::ref_ptr<vsgvr::Instance> xrInstance, vsg::ref_ptr<vsgvr::Viewer> vr, vsg::ref_ptr<vsg::Viewer> desktopViewer, bool displayDesktopWindow);
1818
~Game();
1919

2020
bool shouldExit = false;
@@ -31,6 +31,7 @@ class Game {
3131
vsg::ref_ptr<vsgvr::Instance> _xrInstance;
3232
vsg::ref_ptr<vsgvr::Viewer> _vr;
3333
vsg::ref_ptr<vsg::Viewer> _desktopViewer;
34+
bool _desktopWindowEnabled = false;
3435

3536
// The user / OpenXR root space - Contains elements such as controllers
3637
vsg::ref_ptr<vsg::Group> _sceneRoot;

examples/interaction_locomotion/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ int main(int argc, char** argv) {
104104
// Set up a renderer to OpenXR, similar to a vsg::Viewer
105105
auto vr = vsgvr::Viewer::create(xrInstance, xrTraits, graphicsBinding);
106106

107-
Game game(xrInstance, vr, desktopViewer);
107+
Game game(xrInstance, vr, desktopViewer, true);
108108

109109
while (!game.shouldExit)
110110
{

examples/quest_interaction_locomotion/app/cpp/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ static int vsg_init(struct AppData* appData)
101101
// cast the window to an android window so we can pass it events
102102
appData->window = window.cast<vsgAndroid::Android_Window>();
103103

104-
// attach the window to the viewer
104+
// Attach the window to the viewer
105+
// Android: The window is present, but will not be rendered by the Game class
105106
appData->viewer->addWindow(window);
106107

107108
// Ensure the correct physical device is selected
@@ -131,7 +132,7 @@ static int vsg_init(struct AppData* appData)
131132
// Set up a renderer to OpenXR, similar to a vsg::Viewer
132133
appData->vr = vsgvr::Viewer::create(xrInstance, xrTraits, graphicsBinding);
133134

134-
appData->game.reset(new Game(xrInstance, appData->vr, appData->viewer));
135+
appData->game.reset(new Game(xrInstance, appData->vr, appData->viewer, false));
135136

136137
return 0;
137138
}

models/world/world.blend

864 KB
Binary file not shown.

0 commit comments

Comments
 (0)