-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Create OpenGL on Android with GLSurfaceView #1662
Comments
@ljbade has been researching this. |
Progress being made in https://github.com/mapbox/mapbox-gl-native/tree/android-glsurfaceview Currently compiles, have not tried running it yet. Still lots of work remaining currently TODOed. |
Progress now at the first native crash:
|
Fixed that crash caused by something in the GL version logging. This will be moved to Java at some stage. In mean time I just commented it out. I now get a black map but I can move it around and rotate it. Building debug build to see what sort of GL errors we are getting. |
Crashes somewhere in the GL thread at But commenting out this line allows the us to get to an actual GL error which triggers an |
Ah it looks like it is related to the thread context stuff.
@kkaefer When GLSurfaceView calls into C++ to draw a frame it does it from a thread created in Java instead of C++. What do I do to ensure the thread context stuff is correctly set up for such a thread? |
You can call Map::renderSync. It is thread safe. It blocks the calling thread until one frame render finishes in the map thread. |
@mb12 That is the function I am using. |
Are you creating EGLContext in java using egl.eglCreateContext or in native C++ code? If you are creating it on java side, make sure that that egl.eglMakeCurrent is called on map thread from NativeMapView::activate etc. |
After discussion with @kkaefer I think we may have found a fatal mismatch between the design of the native
At this stage I don't think there is a workaround for this. |
Unless I'm misunderstanding, we can do similar to what we do in iOS. Over there, we use Apple's |
GLKView does not create its own thread. GLSurfaceView in that sense is more like GLKViewController. Is GLSurfaceView preferred because it would help get rid of the calls to eglCreateContext, eglSwapBuffers etc.? |
I could be mistaken — did some brief looking into this a while back. My overall point is that we call |
@mb12 yeah the idea was to not rely on EGL/not very well documented parts of the Android system and instead use the OpenGL solution Google support/advertise in their documentation. However it may not be worth the pain. @incanus It is able to be called from any thread. However the Currently we can use EGL to implement these methods. However with GLSurfaceView we cannot use EGL and are stuck with the context being bound to the Java render thread. |
Aha, that's the piece I was missing! |
I was doing a bit of diving in https://android.googlesource.com/platform/frameworks/base/+/master/opengl/java/android/opengl/GLSurfaceView.java It looks like if we implement http://developer.android.com/reference/android/opengl/GLSurfaceView.EGLContextFactory.html we can grab the EGL handle which may allow us to change the bound thread. However we then have to wrangle with getting the context unbound from the Java thread which might be possible but will be very unstable due to the design of |
I think I will close for now. |
Instead of creating the OpenGL context on the C++ side, we should use the
GLSurfaceView
object and only use the JNI bindings to implement theGLSurfaceView.Renderer#onDrawFrame()
method.The text was updated successfully, but these errors were encountered: