2020-06-21 21:40:07 +00:00
|
|
|
#include "openxrinput.hpp"
|
|
|
|
|
|
|
|
#include "vrenvironment.hpp"
|
|
|
|
#include "openxrmanager.hpp"
|
|
|
|
#include "openxrmanagerimpl.hpp"
|
|
|
|
#include "openxraction.hpp"
|
|
|
|
|
|
|
|
#include <openxr/openxr.h>
|
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
#include <components/misc/stringops.hpp>
|
|
|
|
|
2020-06-21 21:40:07 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace MWVR
|
|
|
|
{
|
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
OpenXRInput::OpenXRInput()
|
2020-06-26 21:02:48 +00:00
|
|
|
{
|
2020-08-09 10:55:09 +00:00
|
|
|
mActionSets.emplace(ActionSet::Gameplay, "Gameplay");
|
|
|
|
mActionSets.emplace(ActionSet::GUI, "GUI");
|
2020-06-26 21:02:48 +00:00
|
|
|
};
|
2020-06-21 21:40:07 +00:00
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
OpenXRActionSet& OpenXRInput::getActionSet(ActionSet actionSet)
|
2020-06-26 21:02:48 +00:00
|
|
|
{
|
2020-08-09 10:55:09 +00:00
|
|
|
auto it = mActionSets.find(actionSet);
|
|
|
|
if (it == mActionSets.end())
|
|
|
|
throw std::logic_error("No such action set");
|
|
|
|
return it->second;
|
2020-06-26 21:02:48 +00:00
|
|
|
}
|
2020-06-21 21:40:07 +00:00
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
void OpenXRInput::suggestBindings(ActionSet actionSet, std::string profile, const SuggestedBindings& mwSuggestedBindings)
|
2020-06-26 21:02:48 +00:00
|
|
|
{
|
2020-08-09 10:55:09 +00:00
|
|
|
getActionSet(actionSet).suggestBindings(mSuggestedBindings[profile], mwSuggestedBindings);
|
2020-06-26 21:02:48 +00:00
|
|
|
}
|
2020-06-21 21:40:07 +00:00
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
void OpenXRInput::attachActionSets()
|
2020-06-21 21:40:07 +00:00
|
|
|
{
|
2020-06-26 21:02:48 +00:00
|
|
|
auto* xr = Environment::get().getManager();
|
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
// Suggest bindings before attaching
|
|
|
|
for (auto& profile : mSuggestedBindings)
|
2020-06-21 21:40:07 +00:00
|
|
|
{
|
2020-08-09 10:55:09 +00:00
|
|
|
XrPath profilePath;
|
|
|
|
CHECK_XRCMD(
|
|
|
|
xrStringToPath(xr->impl().xrInstance(), profile.first.c_str(), &profilePath));
|
|
|
|
XrInteractionProfileSuggestedBinding xrProfileSuggestedBindings{ XR_TYPE_INTERACTION_PROFILE_SUGGESTED_BINDING };
|
|
|
|
xrProfileSuggestedBindings.interactionProfile = profilePath;
|
|
|
|
xrProfileSuggestedBindings.suggestedBindings = profile.second.data();
|
|
|
|
xrProfileSuggestedBindings.countSuggestedBindings = (uint32_t)profile.second.size();
|
|
|
|
CHECK_XRCMD(xrSuggestInteractionProfileBindings(xr->impl().xrInstance(), &xrProfileSuggestedBindings));
|
2020-06-21 21:40:07 +00:00
|
|
|
}
|
|
|
|
|
2020-08-09 10:55:09 +00:00
|
|
|
// OpenXR requires that xrAttachSessionActionSets be called at most once per session.
|
|
|
|
// So collect all action sets
|
|
|
|
std::vector<XrActionSet> actionSets;
|
|
|
|
for (auto& actionSet : mActionSets)
|
|
|
|
actionSets.push_back(actionSet.second.xrActionSet());
|
|
|
|
|
|
|
|
// Attach
|
|
|
|
XrSessionActionSetsAttachInfo attachInfo{ XR_TYPE_SESSION_ACTION_SETS_ATTACH_INFO };
|
|
|
|
attachInfo.countActionSets = actionSets.size();
|
|
|
|
attachInfo.actionSets = actionSets.data();
|
|
|
|
CHECK_XRCMD(xrAttachSessionActionSets(xr->impl().xrSession(), &attachInfo));
|
2020-06-21 21:40:07 +00:00
|
|
|
}
|
|
|
|
}
|