I'm working on an app that needs to load textures for frame animations at certain times while it's executing, the rendering thread needs to continue to run and I need to load the textures in a bg thread. Is there a way to do this in android? I was able to in ios by creating a separate opengl context on the other thread that used the same sharegroup but am not sure if there is a similar facility on android?
1 Answer
Yes, you can share textures between contexts (as long as your driver supports it). Create your background loading context like this (meaning you want to share objects with rendering_context):
eglCreateContext(display, config, rendering_context, attrs);
Then after doing something like this in your background context:
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(...);
You can then bind and use tex from your rendering context.
2 Comments
marchinram
ok thanks for quick response, i'm not super familiar with opengl on android, is eglCreateContext a method called from the ndk or java? Is that all i have to do, create the context and the load up the textures, then kill the thread? Thanks
Chris
eglCreateContext() is how you create a context in C/C++. I couldn't tell you about Java, but there's probably something similar. So all you have to do is create the context, passing in your rendering context for the share context. Then start making textures and they'll be available in the rendering context with the same GLuint.