Try to get Forge 1.14+ work by try to get multiple GL contexts work

This commit is contained in:
khanhduytran0 2020-10-12 15:27:18 +07:00
parent ab7c6584e2
commit 224c08aa5d
2 changed files with 54 additions and 50 deletions

View File

@ -3,9 +3,10 @@ HERE_PATH := $(LOCAL_PATH)
include $(CLEAR_VARS) include $(CLEAR_VARS)
# Link GLESv2 for test # Link GLESv2 for test
LOCAL_LDLIBS := -ldl -llog -landroid -lEGL -lGLESv2 LOCAL_LDLIBS := -ldl -llog -landroid -lEGL
# -lGLESv2
LOCAL_MODULE := pojavexec LOCAL_MODULE := pojavexec
LOCAL_CFLAGS += -DGLES_TEST # LOCAL_CFLAGS += -DGLES_TEST
LOCAL_SRC_FILES := \ LOCAL_SRC_FILES := \
egl_bridge.c \ egl_bridge.c \
input_bridge.c \ input_bridge.c \

View File

@ -20,6 +20,7 @@
struct PotatoBridge { struct PotatoBridge {
/* ANativeWindow */ void* androidWindow; /* ANativeWindow */ void* androidWindow;
/* EGLContext */ void* eglContextOld;
/* EGLContext */ void* eglContext; /* EGLContext */ void* eglContext;
/* EGLDisplay */ void* eglDisplay; /* EGLDisplay */ void* eglDisplay;
/* EGLSurface */ void* eglSurface; /* EGLSurface */ void* eglSurface;
@ -63,11 +64,9 @@ 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) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv* env, jclass clazz) {
if (potatoBridge.eglContext != EGL_NO_CONTEXT) { if (potatoBridge.eglContext != EGL_NO_CONTEXT) {
terminateEgl(); potatoBridge.eglContextOld = potatoBridge.eglContext;
} potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, potatoBridge.eglContextOld, ctx_attribs);
} else {
// dlopen("libgl04es.so", RTLD_NOW + RTLD_GLOBAL);
if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) { if (potatoBridge.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) { if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
@ -119,20 +118,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv*
ANativeWindow_setBuffersGeometry(potatoBridge.androidWindow, 0, 0, vid); ANativeWindow_setBuffersGeometry(potatoBridge.androidWindow, 0, 0, vid);
eglBindAPI(EGL_OPENGL_ES_API); eglBindAPI(EGL_OPENGL_ES_API);
potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, EGL_NO_CONTEXT, ctx_attribs); 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); potatoBridge.eglSurface = eglCreateWindowSurface(potatoBridge.eglDisplay, config, potatoBridge.androidWindow, NULL);
@ -147,6 +133,20 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglMakeCurrent(JNIEnv*
assert(eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val)); assert(eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val));
assert(val & EGL_WINDOW_BIT); 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; // return JNI_TRUE;
printf("EGLBridge: Making current\n"); 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) { JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL_nativeRegalMakeCurrent(JNIEnv *env, jclass clazz) {
printf("Regal: making current"); printf("Regal: making current");
RegalMakeCurrent_func *RegalMakeCurrent = (RegalMakeCurrent_func *) dlsym(RTLD_DEFAULT, "RegalMakeCurrent"); RegalMakeCurrent_func *RegalMakeCurrent = (RegalMakeCurrent_func *) dlsym(RTLD_DEFAULT, "RegalMakeCurrent");
RegalMakeCurrent(potatoBridge.eglContext); RegalMakeCurrent(potatoBridge.eglContext);
} }