| 1 | // Copyright (C) 2024 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QOPENXRHELPERS_H |
| 5 | #define QOPENXRHELPERS_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | |
| 19 | #include <openxr/openxr.h> |
| 20 | #include <QtQuick3DXr/qtquick3dxrglobal.h> |
| 21 | #include <QQuaternion> |
| 22 | #include <QString> |
| 23 | #include <QVector3D> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | namespace OpenXRHelpers |
| 28 | { |
| 29 | QString getXrResultAsString(XrResult result, XrInstance instance); |
| 30 | bool checkXrResult(XrResult result, XrInstance instance); |
| 31 | |
| 32 | inline QQuaternion toQQuaternion(const XrQuaternionf &q) |
| 33 | { |
| 34 | return { q.w, q.x, q.y, q.z }; |
| 35 | } |
| 36 | |
| 37 | inline QVector3D toQVector(const XrVector3f &v) |
| 38 | { |
| 39 | return { v.x * 100, v.y * 100, v.z * 100 }; |
| 40 | } |
| 41 | |
| 42 | /*! |
| 43 | * \brief Safe call to OpenXR function |
| 44 | * \param f - OpenXR function pointer that returns a XrResult |
| 45 | * \param args - arguments for the function pointed to by f |
| 46 | * \return a XrResult indicating the result of the function call. |
| 47 | * |
| 48 | * \note This function is used to "safely" call OpenXR functions without having to check if the function pointer is nullptr. |
| 49 | * If the function pointer is nullptr XR_ERROR_FUNCTION_UNSUPPORTED is returned. |
| 50 | * |
| 51 | * \note If the function returns XR_ERROR_FUNCTION_UNSUPPORTED the caller should avoid calling the function again. |
| 52 | */ |
| 53 | |
| 54 | template <typename T> |
| 55 | [[nodiscard]] XrResult safeCall(); |
| 56 | template <typename... A> |
| 57 | [[nodiscard]] XrResult safeCall(XrResult (XRAPI_PTR *f)(A...), A... args) |
| 58 | { |
| 59 | return f ? f(args...) : XR_ERROR_FUNCTION_UNSUPPORTED; |
| 60 | } |
| 61 | |
| 62 | } |
| 63 | |
| 64 | QT_END_NAMESPACE |
| 65 | |
| 66 | #endif // QOPENXRHELPERS_H |
| 67 | |