From 224c08aa5d6821e5145ebb96f2233e772963c2c8 Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Mon, 12 Oct 2020 15:27:18 +0700 Subject: [PATCH] Try to get Forge 1.14+ work by try to get multiple GL contexts work --- app/src/main/jni/Android.mk | 5 +- app/src/main/jni/egl_bridge.c | 99 ++++++++++++++++++----------------- 2 files changed, 54 insertions(+), 50 deletions(-) diff --git a/app/src/main/jni/Android.mk b/app/src/main/jni/Android.mk index 5f5925846..53eb458f0 100644 --- a/app/src/main/jni/Android.mk +++ b/app/src/main/jni/Android.mk @@ -3,9 +3,10 @@ HERE_PATH := $(LOCAL_PATH) include $(CLEAR_VARS) # Link GLESv2 for test -LOCAL_LDLIBS := -ldl -llog -landroid -lEGL -lGLESv2 +LOCAL_LDLIBS := -ldl -llog -landroid -lEGL +# -lGLESv2 LOCAL_MODULE := pojavexec -LOCAL_CFLAGS += -DGLES_TEST +# LOCAL_CFLAGS += -DGLES_TEST LOCAL_SRC_FILES := \ egl_bridge.c \ input_bridge.c \ diff --git a/app/src/main/jni/egl_bridge.c b/app/src/main/jni/egl_bridge.c index 6830d782c..a7b177ade 100644 --- a/app/src/main/jni/egl_bridge.c +++ b/app/src/main/jni/egl_bridge.c @@ -19,7 +19,8 @@ struct PotatoBridge { /* ANativeWindow */ void* androidWindow; - + + /* EGLContext */ void* eglContextOld; /* EGLContext */ void* eglContext; /* EGLDisplay */ void* eglDisplay; /* EGLSurface */ void* eglSurface; @@ -63,45 +64,43 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglInit(JNIEnv* env, j JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* env, jclass clazz) { if (potatoBridge.eglContext != EGL_NO_CONTEXT) { - terminateEgl(); - } + potatoBridge.eglContextOld = potatoBridge.eglContext; + potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, potatoBridge.eglContextOld, ctx_attribs); + } else { + if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) { + potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) { + printf("EGLBridge: Error eglGetDefaultDisplay() failed: %p\n", eglGetError()); + return JNI_FALSE; + } + } - // dlopen("libgl04es.so", RTLD_NOW + RTLD_GLOBAL); + printf("EGLBridge: Initializing\n"); + printf("EGLBridge: ANativeWindow pointer = %p\n", potatoBridge.androidWindow); - if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) { - potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); - if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) { - printf("EGLBridge: Error eglGetDefaultDisplay() failed: %p\n", eglGetError()); + if (!eglInitialize(potatoBridge.eglDisplay, NULL, NULL)) { + printf("EGLBridge: Error eglInitialize() failed\n"); return JNI_FALSE; } - } - - printf("EGLBridge: Initializing\n"); - printf("EGLBridge: ANativeWindow pointer = %p\n", potatoBridge.androidWindow); - - if (!eglInitialize(potatoBridge.eglDisplay, NULL, NULL)) { - printf("EGLBridge: Error eglInitialize() failed\n"); - return JNI_FALSE; - } - 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, // 16 - EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, - EGL_NONE - }; - static const EGLint ctx_attribs[] = { - EGL_CONTEXT_CLIENT_VERSION, 2, - EGL_NONE - }; + 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, // 16 + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_NONE + }; + static const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; - EGLConfig config; - EGLint num_configs; - EGLint vid; + EGLConfig config; + EGLint num_configs; + EGLint vid; if (!eglChooseConfig(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) { printf("EGLBridge: Error couldn't get an EGL visual config\n"); @@ -119,21 +118,8 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* ANativeWindow_setBuffersGeometry(potatoBridge.androidWindow, 0, 0, vid); eglBindAPI(EGL_OPENGL_ES_API); - potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, EGL_NO_CONTEXT, ctx_attribs); - if (!potatoBridge.eglContext) { - printf("EGLBridge: Error eglCreateContext failed\n"); - return JNI_FALSE; - } - - // test eglQueryContext() - { - EGLint val; - eglQueryContext(potatoBridge.eglDisplay, potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val); - printf("EGLBridge: OpenGL ES from eglQueryContext: %i\n", val); - // assert(val >= 2); - } - + potatoBridge.eglSurface = eglCreateWindowSurface(potatoBridge.eglDisplay, config, potatoBridge.androidWindow, NULL); if (!potatoBridge.eglSurface) { @@ -147,6 +133,20 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* assert(eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val)); assert(val & EGL_WINDOW_BIT); } + } + if (!potatoBridge.eglContext) { + printf("EGLBridge: Error eglCreateContext failed\n"); + return JNI_FALSE; + } + + // test eglQueryContext() + { + EGLint val; + eglQueryContext(potatoBridge.eglDisplay, potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val); + printf("EGLBridge: OpenGL ES from eglQueryContext: %i\n", val); + // assert(val >= 2); + } + // return JNI_TRUE; printf("EGLBridge: Making current\n"); @@ -180,6 +180,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglTerminate(JNIEnv* e JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_nativeRegalMakeCurrent(JNIEnv *env, jclass clazz) { printf("Regal: making current"); + + + RegalMakeCurrent_func *RegalMakeCurrent = (RegalMakeCurrent_func *) dlsym(RTLD_DEFAULT, "RegalMakeCurrent"); RegalMakeCurrent(potatoBridge.eglContext); }