Fix compile warnings; pbuffer for 2+ EGL contexts

This commit is contained in:
khanhduytran0 2021-02-21 10:56:48 +07:00
parent 661272b183
commit 63cbaa7b00
3 changed files with 51 additions and 30 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
/.gradle
/build
/*/build

View File

@ -6,6 +6,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <EGL/egl.h>
@ -61,7 +62,7 @@ JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeWindow
}
JNIEXPORT jlong JNICALL Java_org_lwjgl_glfw_GLFW_nativeEglGetCurrentContext(JNIEnv* env, jclass clazz) {
return eglGetCurrentContext();
return (jlong) eglGetCurrentContext();
}
static const EGLint es3_ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 3,
@ -147,34 +148,53 @@ 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, jlong window) {
if (window != 0x1) {
printf("Making current on window %p\n", window);
EGLBoolean success = eglMakeCurrent(
EGLContext *currCtx = eglGetCurrentContext();
printf("EGLBridge: Comparing: thr=%d, this=%p, curr=%p\n", gettid(), window, currCtx);
if (window != 0x1 && currCtx == EGL_NO_CONTEXT || currCtx == (EGLContext *) window) {
if (potatoBridge.eglContextOld != NULL && potatoBridge.eglContextOld != (void *) window) {
// Create new pbuffer per thread
// TODO get window size for 2nd+ window!
int surfaceWidth, surfaceHeight;
eglQuerySurface(potatoBridge.eglDisplay, potatoBridge.eglSurface, EGL_WIDTH, &surfaceWidth);
eglQuerySurface(potatoBridge.eglDisplay, potatoBridge.eglSurface, EGL_HEIGHT, &surfaceHeight);
int surfaceAttr[] = {
EGL_WIDTH, surfaceWidth,
EGL_HEIGHT, surfaceHeight,
EGL_NONE
};
potatoBridge.eglSurface = eglCreatePbufferSurface(potatoBridge.eglDisplay, config, surfaceAttr);
printf("EGLBridge: created pbuffer surface %p for context %p\n", potatoBridge.eglSurface, window);
}
potatoBridge.eglContextOld = (void *) window;
// eglMakeCurrent(potatoBridge.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
printf("EGLBridge: Making current on window %p on thread %d\n", window, gettid());
EGLBoolean success = eglMakeCurrent(
potatoBridge.eglDisplay,
potatoBridge.eglSurface,
potatoBridge.eglSurface,
/* window==0 ? EGL_NO_CONTEXT : */ (EGLContext *) window
);
if (success == EGL_FALSE) {
printf("Error: eglMakeCurrent() failed: %p\n", eglGetError());
}
);
if (success == EGL_FALSE) {
printf("EGLBridge: Error: eglMakeCurrent() failed: %p\n", eglGetError());
} else {
printf("EGLBridge: eglMakeCurrent() succeed!\n");
}
// Test
#ifdef GLES_TEST
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface);
printf("First frame error: %p\n", eglGetError());
glClearColor(0.4f, 0.4f, 0.4f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(potatoBridge.eglDisplay, potatoBridge.eglSurface);
printf("First frame error: %p\n", eglGetError());
#endif
// idk this should convert or just `return success;`...
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
}else{
(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception");
//return JNI_TRUE;
}
// idk this should convert or just `return success;`...
return success == EGL_TRUE ? JNI_TRUE : JNI_FALSE;
} else {
// (*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception");
return JNI_FALSE;
}
}
JNIEXPORT void JNICALL
Java_org_lwjgl_glfw_GLFW_nativeEglDetachOnCurrentThread(JNIEnv *env, jclass clazz) {
@ -185,14 +205,14 @@ JNIEXPORT jlong JNICALL
Java_org_lwjgl_glfw_GLFW_nativeEglCreateContext(JNIEnv *env, jclass clazz, jlong contextSrc) {
EGLContext* ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es3_ctx_attribs);
if (ctx == EGL_NO_CONTEXT) {
printf("Could not create ES3 context, fallbacking to ES2\n");
printf("EGLBridge: Could not create ES3 context, fallbacking to ES2\n");
setenv("LIBGL_ES", "2", 1);
ctx = eglCreateContext(potatoBridge.eglDisplay,config,(void*)contextSrc,es2_ctx_attribs);
} else {
setenv("LIBGL_ES", "3", 1);
}
printf("Created CTX pointer = %p\n",ctx);
printf("EGLBridge: Created CTX pointer = %p\n",ctx);
//(*env)->ThrowNew(env,(*env)->FindClass(env,"java/lang/Exception"),"Trace exception");
return (long)ctx;
}

View File

@ -229,7 +229,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendChar(JNI
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_CHAR, codepoint, 0, 0, 0);
} else {
GLFW_invoke_Char(showingWindow, (unsigned int) codepoint);
GLFW_invoke_Char((void*) showingWindow, (unsigned int) codepoint);
// return lwjgl2_triggerCharEvent(codepoint);
}
return JNI_TRUE;
@ -242,7 +242,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCharMods
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_CHAR_MODS, (unsigned int) codepoint, mods, 0, 0);
} else {
GLFW_invoke_CharMods(showingWindow, codepoint, mods);
GLFW_invoke_CharMods((void*) showingWindow, codepoint, mods);
}
return JNI_TRUE;
}
@ -263,7 +263,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_CURSOR_ENTER, 1, 0, 0, 0);
} else {
GLFW_invoke_CursorEnter(showingWindow, 1);
GLFW_invoke_CursorEnter((void*) showingWindow, 1);
}
} else if (isGrabbing) {
// Some Minecraft versions does not use GLFWCursorEnterCallback
@ -288,7 +288,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendCursorPos(JN
}
if (!isUseStackQueueCall) {
GLFW_invoke_CursorPos(showingWindow, (double) (x), (double) (y));
GLFW_invoke_CursorPos((void*) showingWindow, (double) (x), (double) (y));
} else {
sendData(EVENT_TYPE_CURSOR_POS, (isGrabbing ? grabCursorX : x), (isGrabbing ? grabCursorY : y), 0, 0);
}
@ -303,7 +303,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendKey(JNIEnv*
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_KEY, key, scancode, action, mods);
} else {
GLFW_invoke_Key(showingWindow, key, scancode, action, mods);
GLFW_invoke_Key((void*) showingWindow, key, scancode, action, mods);
}
}
}
@ -319,7 +319,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendMouseButton(
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_MOUSE_BUTTON, button, action, mods, 0);
} else {
GLFW_invoke_MouseButton(showingWindow, button, action, mods);
GLFW_invoke_MouseButton((void*) showingWindow, button, action, mods);
}
}
}
@ -334,7 +334,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_FRAMEBUFFER_SIZE, width, height, 0, 0);
} else {
GLFW_invoke_FramebufferSize(showingWindow, width, height);
GLFW_invoke_FramebufferSize((void*) showingWindow, width, height);
}
}
@ -342,7 +342,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScreenSize(J
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_WINDOW_SIZE, width, height, 0, 0);
} else {
GLFW_invoke_WindowSize(showingWindow, width, height);
GLFW_invoke_WindowSize((void*) showingWindow, width, height);
}
}
}
@ -355,7 +355,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_glfw_CallbackBridge_nativeSendScroll(JNIEn
if (isUseStackQueueCall) {
sendData(EVENT_TYPE_SCROLL, xoffset, yoffset, 0, 0);
} else {
GLFW_invoke_Scroll(showingWindow, (double) xoffset, (double) yoffset);
GLFW_invoke_Scroll((void*) showingWindow, (double) xoffset, (double) yoffset);
}
}
}