mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2025-04-06 00:20:56 +00:00
OpenXR initialization added
This commit is contained in:
parent
96bf69cb15
commit
f2fefbf708
6 changed files with 108 additions and 44 deletions
2
Makefile
2
Makefile
|
@ -468,7 +468,7 @@ ifeq ($(PLATFORM),android)
|
|||
CLIENT_EXTRA_FILES += $(LIBSDIR)/android/arm64-v8a/libSDL2.so
|
||||
|
||||
# OpenXR
|
||||
BASE_CFLAGS += -I$(OPENXRDIR)/Include -I$(OPENXRSDKDIR)/Include
|
||||
BASE_CFLAGS += -I$(OPENXRDIR)/Include -I$(OPENXRSDKDIR)/include
|
||||
CLIENT_LIBS += $(OPENXRDIR)/Libs/Android/arm64-v8a/Release/libopenxr_loader.so
|
||||
RENDERER_LIBS += $(OPENXRDIR)/Libs/Android/arm64-v8a/Release/libopenxr_loader.so
|
||||
CLIENT_EXTRA_FILES += $(OPENXRDIR)/Libs/Android/arm64-v8a/Release/libopenxr_loader.so
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
### Prerequisites
|
||||
1. Install your copy of Quake III Arena from Steam.
|
||||
2. Android Studio with NDK version 21.1.6352462.
|
||||
3. Download the Oculus VR SDK from https://developer.oculus.com/downloads/package/oculus-mobile-sdk/
|
||||
3. Download the Oculus OpenXR SDK from https://developer.oculus.com/downloads/package/oculus-openxr-mobile-sdk/
|
||||
4. Extract the OpenXR folder to ./android/app/src/main/cpp/code/OpenXR/
|
||||
5. Extract the 3rdParty/khronos/openxr/OpenXR-SDK folder to ./android/app/src/main/cpp/code/OpenXR-SDK/
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ add_custom_target(copy_libs
|
|||
add_dependencies(main copy_libs)
|
||||
|
||||
target_include_directories(main PRIVATE
|
||||
${CMAKE_SOURCE_DIR}/code/OpenXR/Include
|
||||
${CMAKE_SOURCE_DIR}/code/OpenXR-SDK/include
|
||||
${CMAKE_SOURCE_DIR}/code/SDL2/include
|
||||
${CMAKE_SOURCE_DIR}/code)
|
||||
|
||||
|
|
|
@ -5,16 +5,26 @@
|
|||
|
||||
//#if __ANDROID__
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wstrict-prototypes"
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#include <EGL/egl.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static engine_t vr_engine;
|
||||
|
||||
const char* const requiredExtensionNames[] = {
|
||||
XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME,
|
||||
XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME,
|
||||
XR_KHR_ANDROID_THREAD_SETTINGS_EXTENSION_NAME,
|
||||
XR_KHR_COMPOSITION_LAYER_CUBE_EXTENSION_NAME,
|
||||
XR_KHR_COMPOSITION_LAYER_CYLINDER_EXTENSION_NAME,
|
||||
XR_KHR_COMPOSITION_LAYER_EQUIRECT2_EXTENSION_NAME,
|
||||
XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME,
|
||||
XR_FB_COLOR_SPACE_EXTENSION_NAME,
|
||||
XR_FB_SWAPCHAIN_UPDATE_STATE_EXTENSION_NAME,
|
||||
XR_FB_SWAPCHAIN_UPDATE_STATE_OPENGL_ES_EXTENSION_NAME,
|
||||
XR_FB_FOVEATION_EXTENSION_NAME,
|
||||
XR_FB_FOVEATION_CONFIGURATION_EXTENSION_NAME};
|
||||
const uint32_t numRequiredExtensions =
|
||||
sizeof(requiredExtensionNames) / sizeof(requiredExtensionNames[0]);
|
||||
|
||||
cvar_t *vr_worldscale = NULL;
|
||||
cvar_t *vr_hudDepth = NULL;
|
||||
cvar_t *vr_righthanded = NULL;
|
||||
|
@ -39,20 +49,45 @@ cvar_t *vr_weaponSelectorWithHud = NULL;
|
|||
|
||||
engine_t* VR_Init( ovrJava java )
|
||||
{
|
||||
//TODO:
|
||||
/*
|
||||
ovrInitParms initParams;
|
||||
ovrResult initResult;
|
||||
PFN_xrInitializeLoaderKHR xrInitializeLoaderKHR;
|
||||
xrGetInstanceProcAddr(
|
||||
XR_NULL_HANDLE, "xrInitializeLoaderKHR", (PFN_xrVoidFunction*)&xrInitializeLoaderKHR);
|
||||
if (xrInitializeLoaderKHR != NULL) {
|
||||
XrLoaderInitInfoAndroidKHR loaderInitializeInfoAndroid;
|
||||
memset(&loaderInitializeInfoAndroid, 0, sizeof(loaderInitializeInfoAndroid));
|
||||
loaderInitializeInfoAndroid.type = XR_TYPE_LOADER_INIT_INFO_ANDROID_KHR;
|
||||
loaderInitializeInfoAndroid.next = NULL;
|
||||
loaderInitializeInfoAndroid.applicationVM = java.Vm;
|
||||
loaderInitializeInfoAndroid.applicationContext = java.ActivityObject;
|
||||
xrInitializeLoaderKHR((XrLoaderInitInfoBaseHeaderKHR*)&loaderInitializeInfoAndroid);
|
||||
}
|
||||
|
||||
memset(&vr_engine, 0, sizeof(vr_engine));
|
||||
// Create the OpenXR instance.
|
||||
XrApplicationInfo appInfo;
|
||||
memset(&appInfo, 0, sizeof(appInfo));
|
||||
strcpy(appInfo.applicationName, "Quake 3 Arena");
|
||||
appInfo.applicationVersion = 0;
|
||||
strcpy(appInfo.engineName, "Quake 3 Arena");
|
||||
appInfo.engineVersion = 0;
|
||||
appInfo.apiVersion = XR_CURRENT_API_VERSION;
|
||||
|
||||
initParams = vrapi_DefaultInitParms(&java);
|
||||
initResult = vrapi_Initialize(&initParams);
|
||||
assert(initResult == VRAPI_INITIALIZE_SUCCESS);
|
||||
*/
|
||||
vr_engine.java = java;
|
||||
XrInstanceCreateInfo instanceCreateInfo;
|
||||
memset(&instanceCreateInfo, 0, sizeof(instanceCreateInfo));
|
||||
instanceCreateInfo.type = XR_TYPE_INSTANCE_CREATE_INFO;
|
||||
instanceCreateInfo.next = NULL;
|
||||
instanceCreateInfo.createFlags = 0;
|
||||
instanceCreateInfo.applicationInfo = appInfo;
|
||||
instanceCreateInfo.enabledApiLayerCount = 0;
|
||||
instanceCreateInfo.enabledApiLayerNames = NULL;
|
||||
instanceCreateInfo.enabledExtensionCount = numRequiredExtensions;
|
||||
instanceCreateInfo.enabledExtensionNames = requiredExtensionNames;
|
||||
if (xrCreateInstance(&instanceCreateInfo, &vr_engine.Instance) != XR_SUCCESS) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return &vr_engine;
|
||||
memset(&vr_engine, 0, sizeof(vr_engine));
|
||||
vr_engine.java = java;
|
||||
return &vr_engine;
|
||||
}
|
||||
|
||||
void VR_InitCvars( void )
|
||||
|
@ -174,38 +209,55 @@ void VR_InitCvars( void )
|
|||
|
||||
void VR_Destroy( engine_t* engine )
|
||||
{
|
||||
if (engine == &vr_engine) {
|
||||
//TODO:vrapi_Shutdown();
|
||||
}
|
||||
if (engine == &vr_engine) {
|
||||
xrDestroyInstance(engine->Instance);
|
||||
}
|
||||
}
|
||||
|
||||
void VR_EnterVR( engine_t* engine, ovrJava java ) {
|
||||
//TODO:
|
||||
/*
|
||||
if (!engine->ovr) {
|
||||
ovrModeParms modeParams = vrapi_DefaultModeParms(&java);
|
||||
modeParams.Display = (size_t)eglGetCurrentDisplay();
|
||||
modeParams.WindowSurface = (size_t)eglGetCurrentSurface(EGL_DRAW);
|
||||
modeParams.ShareContext = (size_t)eglGetCurrentContext();
|
||||
|
||||
engine->ovr = vrapi_EnterVrMode(&modeParams);
|
||||
engine->frameIndex = 0;
|
||||
XrSystemId systemId;
|
||||
XrSystemGetInfo systemGetInfo;
|
||||
memset(&systemGetInfo, 0, sizeof(systemGetInfo));
|
||||
systemGetInfo.type = XR_TYPE_SYSTEM_GET_INFO;
|
||||
systemGetInfo.next = NULL;
|
||||
systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
|
||||
if (xrGetSystem(engine->Instance, &systemGetInfo, &systemId) != XR_SUCCESS) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
vrapi_SetTrackingSpace(engine->ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
|
||||
// Get the graphics requirements.
|
||||
PFN_xrGetOpenGLESGraphicsRequirementsKHR pfnGetOpenGLESGraphicsRequirementsKHR = NULL;
|
||||
xrGetInstanceProcAddr(
|
||||
engine->Instance,
|
||||
"xrGetOpenGLESGraphicsRequirementsKHR",
|
||||
(PFN_xrVoidFunction*)(&pfnGetOpenGLESGraphicsRequirementsKHR));
|
||||
XrGraphicsRequirementsOpenGLESKHR graphicsRequirements = {};
|
||||
graphicsRequirements.type = XR_TYPE_GRAPHICS_REQUIREMENTS_OPENGL_ES_KHR;
|
||||
pfnGetOpenGLESGraphicsRequirementsKHR(engine->Instance, systemId, &graphicsRequirements);
|
||||
|
||||
vrapi_SetClockLevels(engine->ovr, 4, 4);
|
||||
}
|
||||
*/
|
||||
// Create the OpenXR Session.
|
||||
XrGraphicsBindingOpenGLESAndroidKHR graphicsBindingAndroidGLES = {};
|
||||
graphicsBindingAndroidGLES.type = XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR;
|
||||
graphicsBindingAndroidGLES.next = NULL;
|
||||
graphicsBindingAndroidGLES.display = eglGetCurrentDisplay();
|
||||
graphicsBindingAndroidGLES.config = eglGetCurrentSurface(EGL_DRAW);
|
||||
graphicsBindingAndroidGLES.context = eglGetCurrentContext();
|
||||
|
||||
XrSessionCreateInfo sessionCreateInfo = {};
|
||||
memset(&sessionCreateInfo, 0, sizeof(sessionCreateInfo));
|
||||
sessionCreateInfo.type = XR_TYPE_SESSION_CREATE_INFO;
|
||||
sessionCreateInfo.next = &graphicsBindingAndroidGLES;
|
||||
sessionCreateInfo.createFlags = 0;
|
||||
sessionCreateInfo.systemId = systemId;
|
||||
|
||||
if (xrCreateSession(engine->Instance, &sessionCreateInfo, &engine->Session) != XR_SUCCESS) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void VR_LeaveVR( engine_t* engine ) {
|
||||
//TODO:
|
||||
/*
|
||||
if (engine->ovr) {
|
||||
vrapi_LeaveVrMode(engine->ovr);
|
||||
engine->ovr = NULL;
|
||||
}
|
||||
*/
|
||||
xrDestroySession(engine->Session);
|
||||
}
|
||||
|
||||
engine_t* VR_GetEngine( void ) {
|
||||
|
|
|
@ -75,6 +75,10 @@ void VR_GetResolution(engine_t* engine, int *pWidth, int *pHeight)
|
|||
*pWidth = width;
|
||||
*pHeight = height;
|
||||
}
|
||||
|
||||
//TODO:remove hardcoded values
|
||||
*pWidth = 3664 / 2;
|
||||
*pHeight = 1920;
|
||||
}
|
||||
|
||||
void VR_InitRenderer( engine_t* engine ) {
|
||||
|
|
|
@ -9,7 +9,14 @@
|
|||
# include <SDL_opengles2.h>
|
||||
#endif
|
||||
|
||||
//OpenXR
|
||||
#define XR_USE_GRAPHICS_API_OPENGL_ES 1
|
||||
#define XR_USE_PLATFORM_ANDROID 1
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#include <jni.h>
|
||||
#include <openxr/openxr.h>
|
||||
#include <openxr/openxr_platform.h>
|
||||
|
||||
typedef struct {
|
||||
JavaVM* Vm;
|
||||
|
@ -27,11 +34,12 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
uint64_t frameIndex;
|
||||
//TODO:ovrMobile* ovr;
|
||||
ovrJava java;
|
||||
double predictedDisplayTime;
|
||||
//TODO:ovrTracking2 tracking;
|
||||
framebuffer_t framebuffers[2];
|
||||
XrInstance Instance;
|
||||
XrSession Session;
|
||||
} engine_t;
|
||||
|
||||
typedef enum {
|
||||
|
|
Loading…
Reference in a new issue