How to share a texture among several thread ?

Hello,

I on android and i have a main shared Context on the main thread and several background context on several background thread

main shared context is created like :

eglGetDisplay(EGL_DEFAULT_DISPLAY);
sharedSurface = eglCreateWindowSurface(…)
SharedContext = eglCreateContext(…)
eglMakeCurrent(…)

the background context are create like :

backgroundSurface = eglCreatePbufferSurface(…)
backgroundcontext = eglCreateContext(…,ShareContext, …)
eglMakeCurrent(…)

now my problem is that when the application go in pause, then i must destroy all the context :

eglDestroyContext(SharedContext)
eglDestroySurface(SharedSurface)

and the same for all background contexts :

eglDestroyContext(backgroundContext)
eglDestroySurface(backgroundSurface)

and recreate them later when the app go back to active (same procedure as in the top).

now my problem is that after recreating the SharedContext on the main thread,
some of my texture made by the background context seam to have gone :frowning: a black box is print in the place of the picture :frowning:
not all, just very few of them…

any idea what i do wrong? and what i can do to not lost the texture ?

[QUOTE=loki5100;1282381]…on android … i have a main shared Context on the main thread and several background context on several background thread…
now my problem is that when the application go in pause, then i must destroy all the context … and recreate them later when the app go back to active …
now my problem is that after recreating the SharedContext on the main thread, some of my texture made by the background context seam to have gone …
what i can do to not lost the texture ?[/QUOTE]

I’m puzzled. If you delete your EGL contexts, why would you think the textures referenced by the contexts would survive?

Moreover, why do you think you need to destroy your EGL contexts in the first place?

Referring to this for context:

[ul]
[li]Fixing Common Android Lifecycle Issues in Games (NVidia) [/li][/ul]
your Android NDK app only creates EGL/GL resources and renders when it’s in a ( resumed && focused && has_window state ). Your app should at least stop rendering when it’s not in this state, but as far as I know, what cleanup you do (including deleting EGL contexts) if any as your app moves in and out of this tri-state is at your discretion …with one exception:

If your window is about to be destroyed out from under you (onNativeWindowDestroyed), and you have a referencing EGL window surface, you have to clean that up. If you want to keep your context(s) (and the objects reference by them), when the window is deleted, just unbind the context bound for the window surface (if any) and delete the referencing EGL window surface. And do the reverse if/when you get a new window back later (onNativeWindowCreated). If you were using Java SDK and GLSurfaceView, this kind of thing is exposed with setPreserveEGLContextOnPause. With the NDK, you just roll your own as described above.

Now if instead, you are getting an EGL_CONTEXT_LOST error back at some point (e.g. from eglSwapBuffers), that’s totally different. That means that your contexts have already been deleted right out from under you. Here you need to clean up and recreate everything from scratch. I’m pretty new to Android NDK development, but the only time I’ve seen emitted so far was due to a Qualcomm Adreno GPU driver bug (specifically: writing gl_FragDepth in a frag shader caused their kernel driver to crash/deadlock, and their usermode driver bubbled that failure up to the application as an “oh crap” GL_OUT_OF_MEMORY / EGL_CONTEXT_LOST error).

Related to this general topic, check out the NVidia GameWorks OpenGL Code Samples for some useful Android NDK EGL interaction handling code.