| 1 | // SPDX-License-Identifier: LGPL-2.1-only |
| 2 | // Copyright (C) 2021 James Hogan <[email protected]> |
| 3 | |
| 4 | #include "Path.h" |
| 5 | |
| 6 | using namespace osgXR::OpenXR; |
| 7 | |
| 8 | Path::Path(Instance *instance, |
| 9 | XrPath path) : |
| 10 | _instance(instance), |
| 11 | _path(path) |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | Path::Path(Instance *instance, |
| 16 | const std::string &path) : |
| 17 | _instance(instance), |
| 18 | _path(XR_NULL_PATH) |
| 19 | { |
| 20 | check(xrStringToPath(getXrInstance(), path.c_str(), &_path), |
| 21 | "create OpenXR path from string"); |
| 22 | } |
| 23 | |
| 24 | std::string Path::toString() const |
| 25 | { |
| 26 | if (!valid()) |
| 27 | return ""; |
| 28 | |
| 29 | uint32_t count; |
| 30 | if (!check(xrPathToString(getXrInstance(), _path, |
| 31 | 0, &count, nullptr), |
| 32 | "size OpenXR path string")) |
| 33 | return ""; |
| 34 | std::vector<char> buffer(count); |
| 35 | if (!check(xrPathToString(getXrInstance(), _path, |
| 36 | buffer.size(), &count, buffer.data()), |
| 37 | "get OpenXR path string")) |
| 38 | return ""; |
| 39 | |
| 40 | return buffer.data(); |
| 41 | } |