Call eglGetDisplay() before make current to no context

This commit is contained in:
khanhduytran0 2020-09-16 19:35:28 +07:00
parent 696c415564
commit 8331aeaf73

View File

@ -49,87 +49,88 @@ 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.eglDisplay == NULL || potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
printf("Error: eglGetDefaultDisplay() failed: %p\n", eglGetError());
return JNI_FALSE;
}
}
eglMakeCurrent(potatoBridge.eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if (potatoBridge.eglContext == NULL || potatoBridge.eglContext == EGL_NO_CONTEXT) {
printf("EGLBridge: Initializing\n");
printf("ANativeWindow pointer = %p\n", potatoBridge.androidWindow);
printf("ANativeWindow pointer = %p\n", potatoBridge.androidWindow);
potatoBridge.eglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if (potatoBridge.eglDisplay == EGL_NO_DISPLAY) {
printf("Error: eglGetDefaultDisplay() failed: %p\n", eglGetError());
return JNI_FALSE;
}
if (!eglInitialize(potatoBridge.eglDisplay, NULL, NULL)) {
printf("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,
EGL_DEPTH_SIZE, 24,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_NONE
};
static const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
if (!eglInitialize(potatoBridge.eglDisplay, NULL, NULL)) {
printf("Error: eglInitialize() failed\n");
return JNI_FALSE;
}
EGLConfig config;
EGLint num_configs;
EGLint vid;
static const EGLint attribs[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_DEPTH_SIZE, 24,
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;
if (!eglChooseConfig(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) {
printf("Error: couldn't get an EGL visual config\n");
return JNI_FALSE;
}
if (!eglChooseConfig(potatoBridge.eglDisplay, attribs, &config, 1, &num_configs)) {
printf("Error: couldn't get an EGL visual config\n");
return JNI_FALSE;
}
assert(config);
assert(num_configs > 0);
assert(config);
assert(num_configs > 0);
if (!eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
return JNI_FALSE;
}
if (!eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_NATIVE_VISUAL_ID, &vid)) {
printf("Error: eglGetConfigAttrib() failed\n");
return JNI_FALSE;
}
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);
if (!potatoBridge.eglContext) {
printf("Error: eglCreateContext failed\n");
return JNI_FALSE;
}
potatoBridge.eglContext = eglCreateContext(potatoBridge.eglDisplay, config, EGL_NO_CONTEXT, ctx_attribs);
if (!potatoBridge.eglContext) {
printf("Error: eglCreateContext failed\n");
return JNI_FALSE;
}
// test eglQueryContext()
{
EGLint val;
eglQueryContext(potatoBridge.eglDisplay, potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val);
printf("OpenGL ES from eglQueryContext: %i\n", val);
// assert(val >= 2);
}
// test eglQueryContext()
{
EGLint val;
eglQueryContext(potatoBridge.eglDisplay, potatoBridge.eglContext, EGL_CONTEXT_CLIENT_VERSION, &val);
printf("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) {
printf("Error: eglCreateWindowSurface failed: %p\n", eglGetError());
return JNI_FALSE;
}
if (!potatoBridge.eglSurface) {
printf("Error: eglCreateWindowSurface failed: %p\n", eglGetError());
return JNI_FALSE;
}
// sanity checks
{
EGLint val;
assert(eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val));
assert(val & EGL_WINDOW_BIT);
}
// sanity checks
{
EGLint val;
assert(eglGetConfigAttrib(potatoBridge.eglDisplay, config, EGL_SURFACE_TYPE, &val));
assert(val & EGL_WINDOW_BIT);
}
// return JNI_TRUE;
}
printf("EGLBridge: Making current\n");