OpenXRVkUtils.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <OpenXRVk/OpenXRVkUtils.h>
  9. #include <AzCore/Debug/Trace.h>
  10. namespace OpenXRVk
  11. {
  12. AZ::RHI::ResultCode ConvertResult(XrResult xrResult)
  13. {
  14. switch (xrResult)
  15. {
  16. case XR_SUCCESS:
  17. return AZ::RHI::ResultCode::Success;
  18. case XR_ERROR_OUT_OF_MEMORY:
  19. return AZ::RHI::ResultCode::OutOfMemory;
  20. default:
  21. return AZ::RHI::ResultCode::Fail;
  22. }
  23. }
  24. bool IsSuccess(XrResult result)
  25. {
  26. if (result != XR_SUCCESS)
  27. {
  28. AZ_Error("XR", false, "ERROR: XR API method failed: %s", GetResultString(result));
  29. return false;
  30. }
  31. return true;
  32. }
  33. bool IsError(XrResult result)
  34. {
  35. return IsSuccess(result) == false;
  36. }
  37. const char* GetResultString(const XrResult result)
  38. {
  39. return to_string(result);
  40. }
  41. XR::RawStringList FilterList(const XR::RawStringList& source, const XR::StringList& filter)
  42. {
  43. XR::RawStringList filteredList;
  44. for (auto& item : source)
  45. {
  46. if (AZStd::find(filter.begin(), filter.end(), item) != filter.end())
  47. {
  48. filteredList.push_back(item);
  49. }
  50. }
  51. return filteredList;
  52. }
  53. AZStd::vector<const char*> ParseExtensionString(char* names)
  54. {
  55. AZStd::vector<const char*> list;
  56. while (*names != 0)
  57. {
  58. list.push_back(names);
  59. while (*(++names) != 0)
  60. {
  61. if (*names == ' ')
  62. {
  63. *names++ = '\0';
  64. break;
  65. }
  66. }
  67. }
  68. return list;
  69. }
  70. }