上传YomovSDK
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <locale>
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <string>
|
||||
|
||||
// Macro to generate stringify functions for OpenXR enumerations based data provided in openxr_reflection.h
|
||||
// clang-format off
|
||||
#define ENUM_CASE_STR(name, val) case name: return #name;
|
||||
#define MAKE_TO_STRING_FUNC(enumType) \
|
||||
inline const char* to_string(enumType e) { \
|
||||
switch (e) { \
|
||||
XR_LIST_ENUM_##enumType(ENUM_CASE_STR) \
|
||||
default: return "Unknown " #enumType; \
|
||||
} \
|
||||
}
|
||||
// clang-format on
|
||||
|
||||
MAKE_TO_STRING_FUNC(XrReferenceSpaceType);
|
||||
MAKE_TO_STRING_FUNC(XrViewConfigurationType);
|
||||
MAKE_TO_STRING_FUNC(XrEnvironmentBlendMode);
|
||||
MAKE_TO_STRING_FUNC(XrSessionState);
|
||||
MAKE_TO_STRING_FUNC(XrResult);
|
||||
MAKE_TO_STRING_FUNC(XrFormFactor);
|
||||
MAKE_TO_STRING_FUNC(XrStructureType);
|
||||
31
Packages/com.unity.xr.openxr/Shared/Native~/openxr_utils.h
Normal file
31
Packages/com.unity.xr.openxr/Shared/Native~/openxr_utils.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
template <class TOUT, class TIN>
|
||||
TOUT* FindNextPointerType(TIN* typeIn, XrStructureType structureType)
|
||||
{
|
||||
auto* baseStruct = reinterpret_cast<XrBaseOutStructure*>(typeIn);
|
||||
|
||||
// Loop over the next pointers and look for structureType
|
||||
while ((baseStruct = static_cast<XrBaseOutStructure*>(baseStruct->next)) != nullptr &&
|
||||
baseStruct->type != structureType)
|
||||
{
|
||||
}
|
||||
|
||||
// If we found it, cast to out type. If not we'll return nullptr.
|
||||
return reinterpret_cast<TOUT*>(baseStruct);
|
||||
}
|
||||
|
||||
template <class TOUT, class TIN>
|
||||
const TOUT* FindNextPointerType(const TIN* typeIn, XrStructureType structureType)
|
||||
{
|
||||
auto* baseStruct = reinterpret_cast<const XrBaseOutStructure*>(typeIn);
|
||||
|
||||
// Loop over the next pointers and look for structureType
|
||||
while ((baseStruct = static_cast<const XrBaseOutStructure*>(baseStruct->next)) != nullptr &&
|
||||
baseStruct->type != structureType)
|
||||
{
|
||||
}
|
||||
|
||||
// If we found it, cast to out type. If not we'll return nullptr.
|
||||
return reinterpret_cast<const TOUT*>(baseStruct);
|
||||
}
|
||||
133
Packages/com.unity.xr.openxr/Shared/Native~/plugin_load.cpp
Normal file
133
Packages/com.unity.xr.openxr/Shared/Native~/plugin_load.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
#include "plugin_load.h"
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#if defined(XR_USE_PLATFORM_WIN32) && !defined(XR_USE_PLATFORM_UWP)
|
||||
|
||||
PluginHandle Plugin_LoadLibrary(const wchar_t* libName)
|
||||
{
|
||||
std::wstring lib(libName);
|
||||
if ((lib.size() >= 1 && lib[0] == L'.') ||
|
||||
lib.find(L'/') == std::string::npos && lib.find(L'\\') == std::string::npos)
|
||||
{
|
||||
// Look up path of current dll
|
||||
wchar_t path[MAX_PATH];
|
||||
HMODULE hm = NULL;
|
||||
if (GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
||||
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
||||
(LPCWSTR)&Plugin_LoadLibrary, &hm) == 0)
|
||||
{
|
||||
int ret = GetLastError();
|
||||
fprintf(stderr, "GetModuleHandle failed, error = %d\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
if (GetModuleFileNameW(hm, path, MAX_PATH) == 0)
|
||||
{
|
||||
int ret = GetLastError();
|
||||
fprintf(stderr, "GetModuleFileNameW failed, error = %d\n", ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
std::wstring basePath(path);
|
||||
basePath = basePath.substr(0, basePath.find_last_of(L'\\') + 1);
|
||||
|
||||
lib = basePath + lib + L".dll";
|
||||
}
|
||||
|
||||
HMODULE handle = LoadLibraryW(lib.c_str());
|
||||
if (handle == NULL)
|
||||
{
|
||||
int ret = GetLastError();
|
||||
fprintf(stderr, "LoadLibraryW failed, error = %d\n", ret);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Plugin_FreeLibrary(PluginHandle handle)
|
||||
{
|
||||
FreeLibrary(handle);
|
||||
}
|
||||
|
||||
PluginFunc Plugin_GetSymbol(PluginHandle handle, const char* symbol)
|
||||
{
|
||||
return GetProcAddress(handle, symbol);
|
||||
}
|
||||
|
||||
#elif defined(XR_USE_PLATFORM_UWP)
|
||||
|
||||
PluginHandle Plugin_LoadLibrary(const wchar_t* libName)
|
||||
{
|
||||
if (libName == NULL)
|
||||
return NULL;
|
||||
HMODULE handle = LoadPackagedLibrary(libName, 0);
|
||||
if (handle == NULL)
|
||||
{
|
||||
int ret = GetLastError();
|
||||
fprintf(stderr, "LoadPackagedLibrary failed, error = %d\n", ret);
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
void Plugin_FreeLibrary(PluginHandle handle)
|
||||
{
|
||||
FreeLibrary(handle);
|
||||
}
|
||||
|
||||
PluginFunc Plugin_GetSymbol(PluginHandle handle, const char* symbol)
|
||||
{
|
||||
return GetProcAddress(handle, symbol);
|
||||
}
|
||||
|
||||
#else // Posix
|
||||
|
||||
PluginHandle Plugin_LoadLibrary(const wchar_t* libName)
|
||||
{
|
||||
std::wstring lib(libName);
|
||||
std::string mbLibName;
|
||||
|
||||
size_t len = std::wcstombs(nullptr, lib.c_str(), lib.size());
|
||||
if (len <= 0)
|
||||
return NULL;
|
||||
mbLibName.resize(len);
|
||||
std::wcstombs(&mbLibName[0], lib.c_str(), lib.size());
|
||||
|
||||
if ((lib.size() >= 1 && lib[0] == L'.') ||
|
||||
(lib.find(L'/') == std::string::npos && lib.find(L'\\') == std::string::npos))
|
||||
{
|
||||
Dl_info info;
|
||||
if (dladdr((const void*)&Plugin_LoadLibrary, &info) != 0)
|
||||
{
|
||||
std::string basePath(info.dli_fname);
|
||||
basePath = basePath.substr(0, basePath.find_last_of('/') + 1);
|
||||
|
||||
#if !defined(XR_USE_PLATFORM_OSX)
|
||||
if (mbLibName[0] != '.')
|
||||
mbLibName = basePath + "lib" + mbLibName;
|
||||
else
|
||||
#endif
|
||||
mbLibName = basePath + mbLibName;
|
||||
#if defined(XR_USE_PLATFORM_OSX)
|
||||
mbLibName += ".dylib";
|
||||
#else
|
||||
mbLibName += ".so";
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (mbLibName.size() <= 0)
|
||||
return NULL;
|
||||
|
||||
auto ret = dlopen(mbLibName.c_str(), RTLD_LAZY);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Plugin_FreeLibrary(PluginHandle handle)
|
||||
{
|
||||
dlclose(handle);
|
||||
}
|
||||
|
||||
PluginFunc Plugin_GetSymbol(PluginHandle handle, const char* symbol)
|
||||
{
|
||||
return dlsym(handle, symbol);
|
||||
}
|
||||
#endif
|
||||
43
Packages/com.unity.xr.openxr/Shared/Native~/plugin_load.h
Normal file
43
Packages/com.unity.xr.openxr/Shared/Native~/plugin_load.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
//
|
||||
// Platform Headers
|
||||
//
|
||||
#ifdef XR_USE_PLATFORM_WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif // !WIN32_LEAN_AND_MEAN
|
||||
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif // !NOMINMAX
|
||||
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(XR_USE_PLATFORM_WIN32) && !defined(XR_USE_PLATFORM_UWP)
|
||||
#include "errhandlingapi.h"
|
||||
#include "libloaderapi.h"
|
||||
|
||||
typedef HMODULE PluginHandle;
|
||||
typedef FARPROC PluginFunc;
|
||||
|
||||
#elif defined(XR_USE_PLATFORM_UWP)
|
||||
|
||||
#include "errhandlingapi.h"
|
||||
|
||||
typedef HMODULE PluginHandle;
|
||||
typedef FARPROC PluginFunc;
|
||||
|
||||
#else // Posix
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
typedef void* PluginHandle;
|
||||
typedef void* PluginFunc;
|
||||
|
||||
#endif
|
||||
|
||||
PluginHandle Plugin_LoadLibrary(const wchar_t* libName);
|
||||
void Plugin_FreeLibrary(PluginHandle handle);
|
||||
PluginFunc Plugin_GetSymbol(PluginHandle handle, const char* symbol);
|
||||
Reference in New Issue
Block a user