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

@ -19,7 +19,8 @@
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,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) { 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 {
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) { if (!eglInitialize(potatoBridge.eglDisplay, NULL, NULL)) {
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); printf("EGLBridge: Error eglInitialize() failed\n");
if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
printf("EGLBridge: Error eglGetDefaultDisplay() failed: %p\n", eglGetError());
return JNI_FALSE; 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[] = { static const EGLint attribs[] = {
EGL_RED_SIZE, 8, EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8, EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8, EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8, EGL_ALPHA_SIZE, 8,
// Minecraft required on initial 24 // Minecraft required on initial 24
EGL_DEPTH_SIZE, 24, // 16 EGL_DEPTH_SIZE, 24, // 16
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE EGL_NONE
}; };
static const EGLint ctx_attribs[] = { static const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2, EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE EGL_NONE
}; };
EGLConfig config; EGLConfig config;
EGLint num_configs; EGLint num_configs;
EGLint vid; EGLint vid;
if (!eglChooseConfig(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) { if (!eglChooseConfig(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) {
printf("EGLBridge: Error couldn't get an EGL visual config\n"); 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); 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);
if (!potatoBridge.eglSurface) { 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(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);
} }