mirror of
https://github.com/DrBeef/ioq3quest.git
synced 2024-11-10 14:52:00 +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
|
CLIENT_EXTRA_FILES += $(LIBSDIR)/android/arm64-v8a/libSDL2.so
|
||||||
|
|
||||||
# OpenXR
|
# 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
|
CLIENT_LIBS += $(OPENXRDIR)/Libs/Android/arm64-v8a/Release/libopenxr_loader.so
|
||||||
RENDERER_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
|
CLIENT_EXTRA_FILES += $(OPENXRDIR)/Libs/Android/arm64-v8a/Release/libopenxr_loader.so
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
### Prerequisites
|
### Prerequisites
|
||||||
1. Install your copy of Quake III Arena from Steam.
|
1. Install your copy of Quake III Arena from Steam.
|
||||||
2. Android Studio with NDK version 21.1.6352462.
|
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/
|
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/
|
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)
|
add_dependencies(main copy_libs)
|
||||||
|
|
||||||
target_include_directories(main PRIVATE
|
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/SDL2/include
|
||||||
${CMAKE_SOURCE_DIR}/code)
|
${CMAKE_SOURCE_DIR}/code)
|
||||||
|
|
||||||
|
|
|
@ -5,16 +5,26 @@
|
||||||
|
|
||||||
//#if __ANDROID__
|
//#if __ANDROID__
|
||||||
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wstrict-prototypes"
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
|
|
||||||
#include <EGL/egl.h>
|
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
static engine_t vr_engine;
|
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_worldscale = NULL;
|
||||||
cvar_t *vr_hudDepth = NULL;
|
cvar_t *vr_hudDepth = NULL;
|
||||||
cvar_t *vr_righthanded = NULL;
|
cvar_t *vr_righthanded = NULL;
|
||||||
|
@ -39,19 +49,44 @@ cvar_t *vr_weaponSelectorWithHud = NULL;
|
||||||
|
|
||||||
engine_t* VR_Init( ovrJava java )
|
engine_t* VR_Init( ovrJava java )
|
||||||
{
|
{
|
||||||
//TODO:
|
PFN_xrInitializeLoaderKHR xrInitializeLoaderKHR;
|
||||||
/*
|
xrGetInstanceProcAddr(
|
||||||
ovrInitParms initParams;
|
XR_NULL_HANDLE, "xrInitializeLoaderKHR", (PFN_xrVoidFunction*)&xrInitializeLoaderKHR);
|
||||||
ovrResult initResult;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
memset(&vr_engine, 0, sizeof(vr_engine));
|
memset(&vr_engine, 0, sizeof(vr_engine));
|
||||||
|
|
||||||
initParams = vrapi_DefaultInitParms(&java);
|
|
||||||
initResult = vrapi_Initialize(&initParams);
|
|
||||||
assert(initResult == VRAPI_INITIALIZE_SUCCESS);
|
|
||||||
*/
|
|
||||||
vr_engine.java = java;
|
vr_engine.java = java;
|
||||||
|
|
||||||
return &vr_engine;
|
return &vr_engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,37 +210,54 @@ void VR_InitCvars( void )
|
||||||
void VR_Destroy( engine_t* engine )
|
void VR_Destroy( engine_t* engine )
|
||||||
{
|
{
|
||||||
if (engine == &vr_engine) {
|
if (engine == &vr_engine) {
|
||||||
//TODO:vrapi_Shutdown();
|
xrDestroyInstance(engine->Instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void VR_EnterVR( engine_t* engine, ovrJava java ) {
|
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);
|
XrSystemId systemId;
|
||||||
engine->frameIndex = 0;
|
XrSystemGetInfo systemGetInfo;
|
||||||
|
memset(&systemGetInfo, 0, sizeof(systemGetInfo));
|
||||||
vrapi_SetTrackingSpace(engine->ovr, VRAPI_TRACKING_SPACE_LOCAL_FLOOR);
|
systemGetInfo.type = XR_TYPE_SYSTEM_GET_INFO;
|
||||||
|
systemGetInfo.next = NULL;
|
||||||
vrapi_SetClockLevels(engine->ovr, 4, 4);
|
systemGetInfo.formFactor = XR_FORM_FACTOR_HEAD_MOUNTED_DISPLAY;
|
||||||
|
if (xrGetSystem(engine->Instance, &systemGetInfo, &systemId) != XR_SUCCESS) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
// 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 ) {
|
void VR_LeaveVR( engine_t* engine ) {
|
||||||
//TODO:
|
xrDestroySession(engine->Session);
|
||||||
/*
|
|
||||||
if (engine->ovr) {
|
|
||||||
vrapi_LeaveVrMode(engine->ovr);
|
|
||||||
engine->ovr = NULL;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
engine_t* VR_GetEngine( void ) {
|
engine_t* VR_GetEngine( void ) {
|
||||||
|
|
|
@ -75,6 +75,10 @@ void VR_GetResolution(engine_t* engine, int *pWidth, int *pHeight)
|
||||||
*pWidth = width;
|
*pWidth = width;
|
||||||
*pHeight = height;
|
*pHeight = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO:remove hardcoded values
|
||||||
|
*pWidth = 3664 / 2;
|
||||||
|
*pHeight = 1920;
|
||||||
}
|
}
|
||||||
|
|
||||||
void VR_InitRenderer( engine_t* engine ) {
|
void VR_InitRenderer( engine_t* engine ) {
|
||||||
|
|
|
@ -9,7 +9,14 @@
|
||||||
# include <SDL_opengles2.h>
|
# include <SDL_opengles2.h>
|
||||||
#endif
|
#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 <jni.h>
|
||||||
|
#include <openxr/openxr.h>
|
||||||
|
#include <openxr/openxr_platform.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
JavaVM* Vm;
|
JavaVM* Vm;
|
||||||
|
@ -27,11 +34,12 @@ typedef struct {
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint64_t frameIndex;
|
uint64_t frameIndex;
|
||||||
//TODO:ovrMobile* ovr;
|
|
||||||
ovrJava java;
|
ovrJava java;
|
||||||
double predictedDisplayTime;
|
double predictedDisplayTime;
|
||||||
//TODO:ovrTracking2 tracking;
|
//TODO:ovrTracking2 tracking;
|
||||||
framebuffer_t framebuffers[2];
|
framebuffer_t framebuffers[2];
|
||||||
|
XrInstance Instance;
|
||||||
|
XrSession Session;
|
||||||
} engine_t;
|
} engine_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
Loading…
Reference in a new issue