- Home /
Android plugin calling glTexSubImage2D etc
I want to call glTexSubImage2D periodically from an Android plugin (using the GL texture name I can get from Texture2D.GetNativeTextureID). I'm not sure when it's safe to do this: as I understand it, the OpenGLES context is bound during onDrawFrame which happens on a background thread on Android.
I guess my question is: are all of my Unity scripts called during onDrawFrame on Android? If that's the case then I can make calls to my plugin that calls glTexSubImage2D from those scripts at a time when I know the context is bound. Or maybe my Unity scripts are called from another thread, and only some OpenGLES rendering related things happen in onDrawFrame, and I need to figure some way to synchronize my update? Or maybe some script calls happen during onDrawFrame, and some don't?
Can anyone shed any light on this for me?
Answer by eriQue · Sep 15, 2011 at 04:53 AM
are all of my Unity scripts called during onDrawFrame on Android?
Yes, the Unity main thread is the GLThread (in GLSurfaceView terms) so it is possible to update textures from a native plugin. You have to be careful to not assume a particular render state, only access the GL context when it's active (like in the render callbacks; onPreRender etc), and reset the render state afterwards with GL.InvalidateState().
Answer by PaulaCL · Jan 10, 2012 at 03:16 PM
Great! Now I know it's possible, it's just i don't know how to do it, could you please explain it more in depth?
I been searching a lot about this issue, I tried to integrate Unity in Eclipse, following http://unity3d.com/support/documentation/Manual/Android-Integrating%20Unity%20With%20Eclipse.html , but I don't know how to get GL context in order to call glTexImage2D, also I don't know how to access a TextureID from a .cs script in Unity to Java.
I also tried the other way back, integrating a Java plugin into Unity, following this tutorial http://randomactsofdev.wordpress.com/2011/08/19/accessing-the-android-compass-through-unity-3d/ but still I don't know how to get onDrawFrame(GL10 gl) or anything to control and call openGL functions.
Please I need advice, I relative new to unity and I'm trying to get the plugins architecture in mind. Any help will be great!
Thanks in advance!!! Paula.,Great! Now I know it's possible, it's just i don't know how to do it, could you please explain it more in depth?
I been searching a lot about this issue, I tried to integrate Unity in Eclipse, following http://unity3d.com/support/documentation/Manual/Android-Integrating%20Unity%20With%20Eclipse.html , but I don't know how to get GL context in order to call glTexImage2D, also I don't know how to access a TextureID from a .cs script in Unity to Java.
I also tried the other way back, integrating a Java plugin into Unity, following this tutorial http://randomactsofdev.wordpress.com/2011/08/19/accessing-the-android-compass-through-unity-3d/ but still I don't know how to get onDrawFrame(GL10 gl) or anything to control and call openGL functions.
Please I need advice, I relative new to unity and I'm trying to get the plugins architecture in mind. Any help will be great!
Thanks in advance!!! Paula.
Answer by PaulaCL · Jan 10, 2012 at 03:16 PM
Great! Now I know it's possible, it's just i don't know how to do it, could you please explain it more in depth?
I been searching a lot about this issue, I tried to integrate Unity in Eclipse, following http://unity3d.com/support/documentation/Manual/Android-Integrating%20Unity%20With%20Eclipse.html , but I don't know how to get GL context in order to call glTexImage2D, also I don't know how to access a TextureID from a .cs script in Unity to Java.
I also tried the other way back, integrating a Java plugin into Unity, following this tutorial http://randomactsofdev.wordpress.com/2011/08/19/accessing-the-android-compass-through-unity-3d/ but still I don't know how to get onDrawFrame(GL10 gl) or anything to control and call openGL functions.
Please I need advice, I relative new to unity and I'm trying to get the plugins architecture in mind. Any help will be great!
Thanks in advance!!! Paula.