Skip to content

Commit

Permalink
More OpenXR work
Browse files Browse the repository at this point in the history
  • Loading branch information
The Judge committed Oct 21, 2024
1 parent 1eb0328 commit c0c6ab9
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/main/assets/lwjgl/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1729135685550
1729544610054
2 changes: 0 additions & 2 deletions src/main/jni/environ/environ.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ struct pojav_environ_s {
JavaVM* dalvikJavaVMPtr;
JNIEnv* dalvikJNIEnvPtr_ANDROID;
jobject activity;
XrInstanceCreateInfoAndroidKHR *XRAndroidInstanceBinding;
XrGraphicsBindingOpenGLESAndroidKHR *XRAndroidGLESBinding;
long showingWindow;
bool isInputReady, isCursorEntered, isUseStackQueueCall, shouldUpdateMouse;
int savedWidth, savedHeight;
Expand Down
5 changes: 0 additions & 5 deletions src/main/jni/input_bridge_v3.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ jint JNI_OnLoad(JavaVM* vm, __attribute__((unused)) void* reserved) {
hookExec();
installLinkerBugMitigation();
installEMUIIteratorMititgation();

pojav_environ->XRAndroidInstanceBinding = malloc(sizeof(XrInstanceCreateInfoAndroidKHR));
pojav_environ->XRAndroidInstanceBinding->type = XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR;
pojav_environ->XRAndroidInstanceBinding->applicationVM = (void*) pojav_environ->dalvikJavaVMPtr;
pojav_environ->XRAndroidInstanceBinding->applicationActivity = (void*) pojav_environ->activity;
}

if(pojav_environ->dalvikJavaVMPtr == vm) {
Expand Down
79 changes: 46 additions & 33 deletions src/main/jni/vloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,66 +18,79 @@

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getEGLGlobal(JNIEnv* env, jclass clazz) {
if(pojav_environ->XRAndroidGLESBinding == nullptr) {
EGLConfig cfg;
EGLint num_configs;
Java_org_vivecraft_util_VLoader_getEGLDisplay(JNIEnv* env, jclass clazz) {
return reinterpret_cast<jlong>(eglGetCurrentDisplay());
}

static const EGLint attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
// Minecraft required on initial 24
EGL_DEPTH_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};
extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getEGLContext(JNIEnv* env, jclass clazz) {
return reinterpret_cast<jlong>(eglGetCurrentContext());
}

eglChooseConfig(eglGetCurrentDisplay(), attribs, &cfg, 1, &num_configs);
pojav_environ->XRAndroidGLESBinding = new XrGraphicsBindingOpenGLESAndroidKHR{
XR_TYPE_GRAPHICS_BINDING_OPENGL_ES_ANDROID_KHR,
nullptr,
(void *) eglGetCurrentDisplay(),
(void *) cfg,
(void *) eglGetCurrentContext()
};
}
extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getEGLConfig(JNIEnv* env, jclass clazz) {
EGLConfig cfg;
EGLint num_configs;

return reinterpret_cast<jlong>(pojav_environ->XRAndroidGLESBinding);
static const EGLint attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
// Minecraft required on initial 24
EGL_DEPTH_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES3_BIT,
EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
EGL_NONE
};

eglChooseConfig(eglGetCurrentDisplay(), attribs, &cfg, 1, &num_configs);
return reinterpret_cast<jlong>(cfg);
}

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getAndroidCreateInfo(JNIEnv* env, jclass clazz) {
JNIEXPORT void JNICALL
Java_org_vivecraft_util_VLoader_initOpenXRLoader(JNIEnv* env, jclass clazz) {
PFN_xrInitializeLoaderKHR initializeLoader = nullptr;
XrResult res;

res = xrGetInstanceProcAddr(XR_NULL_HANDLE, "xrInitializeLoaderKHR",
(PFN_xrVoidFunction *) (&initializeLoader));

if(!XR_SUCCEEDED(res)) {
if (!XR_SUCCEEDED(res)) {
printf("xrGetInstanceProcAddr returned %d.\n", res);
}

XrLoaderInitInfoAndroidKHR loaderInitInfoAndroidKhr = {
XR_TYPE_LOADER_INIT_INFO_ANDROID_KHR,
nullptr,
(void*) pojav_environ->dalvikJavaVMPtr,
(void*) pojav_environ->activity
(void *) pojav_environ->dalvikJavaVMPtr,
(void *) pojav_environ->activity
};

res = initializeLoader((const XrLoaderInitInfoBaseHeaderKHR *) &loaderInitInfoAndroidKhr);
if(!XR_SUCCEEDED(res)) {
if (!XR_SUCCEEDED(res)) {
printf("xrInitializeLoaderKHR returned %d.\n", res);
}

JNIEnv* newEnv;
JNIEnv *newEnv;
pojav_environ->dalvikJavaVMPtr->AttachCurrentThread(&newEnv, NULL);
}

return reinterpret_cast<jlong>(pojav_environ->XRAndroidInstanceBinding);
extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getDalvikVM(JNIEnv* env, jclass clazz) {
return reinterpret_cast<jlong>(pojav_environ->dalvikJavaVMPtr);
}

extern "C"
JNIEXPORT jlong JNICALL
Java_org_vivecraft_util_VLoader_getDalvikActivity(JNIEnv* env, jclass clazz) {
return reinterpret_cast<jlong>(pojav_environ->activity);
}

extern "C"
JNIEXPORT void JNICALL
Java_pojlib_util_VLoader_setAndroidInitInfo(JNIEnv *env, jclass clazz, jobject ctx) {
Expand Down

0 comments on commit c0c6ab9

Please sign in to comment.