Debian Codegraph @

3rdparty/osgXR/src/OpenXR/InteractionProfile.cpp

raw symbols SCIP
1 // SPDX-License-Identifier: LGPL-2.1-only
2 // Copyright (C) 2021 James Hogan <[email protected]>
3
4 #include "InteractionProfile.h"
5
6 #include <cassert>
7 #include <vector>
8
9 using namespace osgXR::OpenXR;
10
11 InteractionProfile::InteractionProfile(const Path &path) :
12 _path(path)
13 {
14 }
15
16 InteractionProfile::InteractionProfile(Instance *instance,
17 const char *vendor, const char *type) :
18 _path(instance, (std::string)"/interaction_profiles/" + vendor + "/" + type)
19 {
20 }
21
22 InteractionProfile::~InteractionProfile()
23 {
24 }
25
26 void InteractionProfile::addBinding(Action *action, const Path &binding)
27 {
28 assert(binding.getInstance() == getInstance());
29 _bindings.insert(ActionBindingPair(action, binding.getXrPath()));
30 }
31
32 bool InteractionProfile::suggestBindings()
33 {
34 // No bindings: nothing to do!
35 if (_bindings.empty())
36 return true;
37
38 // Construct binding vector from _bindings map
39 std::vector<XrActionSuggestedBinding> bindings;
40 bindings.reserve(_bindings.size());
41 for (auto pair: _bindings)
42 {
43 if (pair.first->init())
44 bindings.push_back({ pair.first->getXrAction(),
45 pair.second });
46 }
47
48 // Suggest the bindings
49 XrInteractionProfileSuggestedBinding suggestedBinding{
50 XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING
51 };
52 suggestedBinding.interactionProfile = _path.getXrPath();
53 suggestedBinding.countSuggestedBindings = bindings.size();
54 suggestedBinding.suggestedBindings = bindings.data();
55
56 return check(xrSuggestInteractionProfileBindings(getXrInstance(),
57 &suggestedBinding),
58 "suggest interaction profile bindings");
59 }