// Note: Usually the surface shall be locked within [makeCurrent .. swap .. release] protected void releaseImpl() throws GLException { try { super.releaseImpl(); } finally { if (!isOptimizable() && drawable.isSurfaceLocked()) { drawable.unlockSurface(); } } }
// EGL buffer flip public void flipEGL() { try { EGL10 egl = (EGL10) EGLContext.getEGL(); egl.eglWaitNative(EGL10.EGL_NATIVE_RENDERABLE, null); // drawing here egl.eglWaitGL(); egl.eglSwapBuffers(mEGLDisplay, mEGLSurface); } catch (Exception e) { Log.v("SDL", "flipEGL(): " + e); for (StackTraceElement s : e.getStackTrace()) { Log.v("SDL", s.toString()); } } }
// EGL functions public boolean initEGL(int majorVersion, int minorVersion) { Log.v("SDL", "Starting up OpenGL ES " + majorVersion + "." + minorVersion); try { EGL10 egl = (EGL10) EGLContext.getEGL(); EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); int[] version = new int[2]; egl.eglInitialize(dpy, version); int EGL_OPENGL_ES_BIT = 1; int EGL_OPENGL_ES2_BIT = 4; int renderableType = 0; if (majorVersion == 2) { renderableType = EGL_OPENGL_ES2_BIT; } else if (majorVersion == 1) { renderableType = EGL_OPENGL_ES_BIT; } int[] configSpec = { // EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_RENDERABLE_TYPE, renderableType, EGL10.EGL_NONE }; EGLConfig[] configs = new EGLConfig[1]; int[] num_config = new int[1]; if (!egl.eglChooseConfig(dpy, configSpec, configs, 1, num_config) || num_config[0] == 0) { Log.e("SDL", "No EGL config available"); return false; } EGLConfig config = configs[0]; EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, null); if (ctx == EGL10.EGL_NO_CONTEXT) { Log.e("SDL", "Couldn't create context"); return false; } EGLSurface surface = egl.eglCreateWindowSurface(dpy, config, this, null); if (surface == EGL10.EGL_NO_SURFACE) { Log.e("SDL", "Couldn't create surface"); return false; } if (!egl.eglMakeCurrent(dpy, surface, surface, ctx)) { Log.e("SDL", "Couldn't make context current"); return false; } mEGLContext = ctx; mEGLDisplay = dpy; mEGLSurface = surface; } catch (Exception e) { Log.v("SDL", e + ""); for (StackTraceElement s : e.getStackTrace()) { Log.v("SDL", s.toString()); } } return true; }