Call to check if current EGLContext exists in Android

I am trying to find a way to check if the current EGLContext exists and is ready for use on Android. According to the specification, I tried to use

((EGL10) EGLContext.getEGL ()). EglGetCurrentContext ()

and then comparing it to EGL10.EGL_NO_CONTEXT (verified .equals () and! =). However, despite the fact that it seems “through” the debugging, it returns an instance of “EGL_NO_CONTEXT” (it seems that all internal values ​​are uninitialized), however, no matter what comparison I do, I cannot get it to work.

Does anyone know of a different / proper method to do this? I don't want to do this by throwing a random GL call and capturing an EGLError ...

+6
android opengl-es
source share
3 answers

There seems to be a bug in the implementation of Android EGL10.eglGetCurrentContext (), where the result of eglGetCurrentContxt () should be compared using

result.equals(EGL10.EGL_NO_CONTEXT) 

but not

 result == EGL10.EGL_NO_CONTEXT 

For example:

 if (((EGL10) EGLContext.getEGL()).eglGetCurrentContext().equals(EGL10.EGL_NO_CONTEXT)) { // no current context. } 
+2
source share

I ran into the problem of being unable to reuse the current EGLContext when trying to display what was on the screen in GLSurfaceView on an off-screen EGLPixelBufferSurface. From what I can tell, the problem is using the static method

EGLContext.getEgl()

is that it creates an EGL instance by default - this will mean that the associated EGLContext is equivalent to EGL10.EGL_NO_CONTEXT.

Furthermore, in Android, an EGLContext can only be associated with one thread (Android developer Romain Guy says here ). Therefore, to properly use

EGL.getCurrentContext()

you will need to have a pre-existing EGL instance and call the getCurrentContext() method on the thread that created the EGLContext.

NOTE. Android now handles saving EGLContext when GLThread is paused / resumed in the GLSurfaceView class (look at the setPreserveEGLContextOnPause(boolean preserveOnPause) method).

+2
source share

You can try checking it to see if it is null and not equal to the given context. This is what I would do in the standard opengl program.

[EDIT] Here is an example here that uses it as follows:

 if ((eglGetCurrentContext () != context->egl_context) || (eglGetCurrentSurface ( EGL_READ ) != drawable->egl_surface)) 

I do not know if this will help.

0
source share

All Articles