简体   繁体   中英

EGL from android native activity back to Java

I have a little issue that I am trying to solve.

Basically I am creating a EGL context with the NDK something similar to this: http://developer.android.com/reference/android/app/NativeActivity.html

In android if you extend surfaceview.renderer , it also creates an EGL context behind the scenes after the onCreated & onSurfaceChange calls. You can see more here: http://developer.android.com/reference/android/opengl/GLSurfaceView.Renderer.html

My question is, since I am creating my EGL context within the native Activity but I need to access some lifecycle functions from the Java side. Is it possible to pass my EGL context from the native Activity and use it to setup a android surfaceview.renderer and then use the glsurfaceview.renderer to call back to native with JNI calls?

You're going about it the wrong way.

The point of GLSurfaceView is to combine a SurfaceView with some code that takes care of EGL context and thread management for you. If you're doing your own EGL setup, and you don't mind dealing with the threading issues, there's no reason to use a GLSurfaceView -- and doing so makes things more complicated.

If you want to create and manage your own EGL context, use a plain SurfaceView. Create an EGLSurface from the SurfaceView's Surface.

If you prefer GLSurfaceView, don't create a separate EGL context. Just use the one that GLSurfaceView creates for you. Understand that it will be destroyed and recreated when the Activity pauses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM