You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
OpenXR: Implement spatial entities extension
This commit is contained in:
@@ -34,13 +34,9 @@
|
||||
|
||||
#include <openxr/openxr_reflection.h>
|
||||
|
||||
#define XR_ENUM_CASE_STR(name, val) \
|
||||
case name: \
|
||||
return #name;
|
||||
#define XR_ENUM_SWITCH(enumType, var) \
|
||||
switch (var) { \
|
||||
XR_LIST_ENUM_##enumType(XR_ENUM_CASE_STR) default : return "Unknown " #enumType ": " + String::num_int64(int64_t(var)); \
|
||||
}
|
||||
String OpenXRUtil::get_result_string(XrResult p_result){
|
||||
XR_ENUM_SWITCH(XrResult, p_result)
|
||||
}
|
||||
|
||||
String OpenXRUtil::get_view_configuration_name(XrViewConfigurationType p_view_configuration){
|
||||
XR_ENUM_SWITCH(XrViewConfigurationType, p_view_configuration)
|
||||
@@ -78,7 +74,105 @@ String OpenXRUtil::make_xr_version_string(XrVersion p_version) {
|
||||
return version;
|
||||
}
|
||||
|
||||
// Based on the OpenXR xr_linear.h private header, so we can still link against
|
||||
String OpenXRUtil::get_handle_as_hex_string(void *p_handle) {
|
||||
String hex;
|
||||
|
||||
if (p_handle == XR_NULL_HANDLE) {
|
||||
return "null";
|
||||
}
|
||||
|
||||
uint64_t handle = (uint64_t)p_handle;
|
||||
|
||||
while (handle != 0) {
|
||||
uint8_t a = handle & 0x0F;
|
||||
uint8_t b = (handle & 0xF0) >> 4;
|
||||
handle = handle >> 8;
|
||||
|
||||
if (a < 10) {
|
||||
hex = (a + '0') + hex;
|
||||
} else {
|
||||
hex = (a + 'a' - 10) + hex;
|
||||
}
|
||||
|
||||
if (b < 10) {
|
||||
hex = (b + '0') + hex;
|
||||
} else {
|
||||
hex = (b + 'a' - 10) + hex;
|
||||
}
|
||||
}
|
||||
|
||||
return "0x" + hex;
|
||||
}
|
||||
|
||||
String OpenXRUtil::string_from_xruuid(const XrUuid &xr_uuid) {
|
||||
String ret;
|
||||
bool non_zero = false;
|
||||
|
||||
for (int i = 0; i < XR_UUID_SIZE; i++) {
|
||||
non_zero |= xr_uuid.data[i] != 0;
|
||||
|
||||
char a = xr_uuid.data[i] & 0xF0 >> 4;
|
||||
char b = xr_uuid.data[i] & 0x0F;
|
||||
|
||||
if (a < 10) {
|
||||
ret += '0' + a;
|
||||
} else {
|
||||
ret += 'a' + a - 10;
|
||||
}
|
||||
|
||||
if (b < 10) {
|
||||
ret += '0' + b;
|
||||
} else {
|
||||
ret += 'a' + b - 10;
|
||||
}
|
||||
}
|
||||
|
||||
if (non_zero) {
|
||||
return ret;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
XrUuid OpenXRUtil::xruuid_from_string(const String &p_uuid) {
|
||||
XrUuid new_uuid = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
int len = p_uuid.length();
|
||||
if (len == 0) {
|
||||
return new_uuid;
|
||||
} else if (len != (2 * XR_UUID_SIZE)) {
|
||||
WARN_PRINT("OpenXR: Unexpected UUID length: " + String::num_int64(len) + " != " + String::num_int64(2 * XR_UUID_SIZE));
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (int i = 0; i < XR_UUID_SIZE; i++) {
|
||||
uint8_t val = 0;
|
||||
|
||||
// 2 chars per byte.
|
||||
for (int k = 0; k < 2; k++) {
|
||||
if (j < len) {
|
||||
val <<= 4;
|
||||
|
||||
char32_t c = p_uuid[j++];
|
||||
if (c >= '0' && c <= '9') {
|
||||
val += uint8_t(c - '0');
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
val += uint8_t(10 + c - 'a');
|
||||
} else if (c >= 'A' && c <= 'F') {
|
||||
val += uint8_t(10 + c - 'A');
|
||||
} else {
|
||||
WARN_PRINT("OpenXR: Unexpected character in UUID: " + String::num_int64(c));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
new_uuid.data[i] = val;
|
||||
}
|
||||
|
||||
return new_uuid;
|
||||
}
|
||||
|
||||
// Copied from OpenXR xr_linear.h private header, so we can still link against
|
||||
// system-provided packages without relying on our `thirdparty` code.
|
||||
|
||||
// Copyright (c) 2017 The Khronos Group Inc.
|
||||
|
||||
Reference in New Issue
Block a user