Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to check if a current EGLContext exists in Android

I'm trying to find a way to check to see if a current EGLContext exists and is ready to use on Android. By specification, I've tried using

((EGL10)EGLContext.getEGL()).eglGetCurrentContext()

and then comparing it to EGL10.EGL_NO_CONTEXT (tried .equals() and != ). However, even though through debugging it 'seems' that it is returning an instance of 'EGL_NO_CONTEXT' (seems meaning all the internal values are uninitialized) however no matter what comparison I do I can't get it to work.

Anyone know of another/proper method to get this done? I don't want to do it by throwing a random GL call and catching the EGLError...

like image 799
Moncader Avatar asked Jun 22 '10 09:06

Moncader


2 Answers

I ran into the problem of not being able to re-use the current EGLContext when trying to render what was on screen in a GLSurfaceView to an offscreen EGLPixelBufferSurface. From what I can tell, the problem with using the static method

EGLContext.getEgl()

is that it creates a default EGL instance - this would mean that the EGLContext associated with it is equivalent to EGL10.EGL_NO_CONTEXT.

Also, in Android the EGLContext can only be associated with one thread (Android developer Romain Guy says so here). So in order to properly use

EGL.getCurrentContext()

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

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

like image 81
John Thompson Avatar answered Oct 27 '22 03:10

John Thompson


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

result.equals(EGL10.EGL_NO_CONTEXT)

rather than

result == EGL10.EGL_NO_CONTEXT

For example:

if (((EGL10) EGLContext.getEGL()).eglGetCurrentContext().equals(EGL10.EGL_NO_CONTEXT)) {
    // no current context.
}
like image 28
Jack Palevich Avatar answered Oct 27 '22 01:10

Jack Palevich