views:

120

answers:

1

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...

A: 

You could try testing it to see if it is null, rather than equal to a given context. This is what I would do in a standard opengl program.

[EDIT] There's an example here which uses it as follows:

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

I don't know if that's any help.

Amos
It never returns null sadly. I've debugged it and the EGLContext that Android gives me from eglGetCurrentContext() is actually not current as any operations using it give me the 'No current context set' error.
Moncader
Is there some sort of error in your initialization process then? When I had a quick look earlier for your problem I found various pieces of example code but nothing with any error checking in it. Maybe you should double check your initialization routines in line with what's in the examples for now and find the error checking stuff later? You could ask on some more Android centric sites too, and keep checking for updates here too. Plus if one of your other avenues pays off make sure to post the solution here to help others find it.
Amos
I already have a fully working application. However I have some situations where I want to load textures in to memory when Android hasn't set a current GL context (If you don't know android, well, this is just how it works). Obviously, this isn't possible so when I detect that there is no current context, I append that bitmap to a queue to be added to VRAM when the context becomes available again.
Moncader
So you need to detect the context in order to know what to do with your texture. Is there some form of exception handling you could do to get around this? For instance try to do whatever you need to do with the context, if it fails because the context isn't current catch the exception and deal with it by adding the texture to the end of the queue.
Amos
I want to avoid doing that as sadly the only way I can get the exception is if I send a command through the GL pipeline, which is slow (relatively speaking).
Moncader
For your edit, it sadly doesn't work.
Moncader