{"payload":{"allShortcutsEnabled":false,"fileTree":{"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils":{"items":[{"name":"AndroidGLES20Util.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/AndroidGLES20Util.java","contentType":"file"},{"name":"AndroidGLES30Util.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/AndroidGLES30Util.java","contentType":"file"},{"name":"AndroidGLES31Util.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/AndroidGLES31Util.java","contentType":"file"},{"name":"AndroidGLESUtil.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/AndroidGLESUtil.java","contentType":"file"},{"name":"FBOUtil.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/FBOUtil.java","contentType":"file"},{"name":"GLBuffer.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/GLBuffer.java","contentType":"file"},{"name":"GLBufferUtil.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/GLBufferUtil.java","contentType":"file"},{"name":"GLSurfaceView2.java","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/GLSurfaceView2.java","contentType":"file"}],"totalCount":8},"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl":{"items":[{"name":"utils","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main/java/org/typhonrt/android/java6":{"items":[{"name":"opengl","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main/java/org/typhonrt/android":{"items":[{"name":"java6","path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main/java/org/typhonrt":{"items":[{"name":"android","path":"java6-android-glutils/src/main/java/org/typhonrt/android","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main/java/org":{"items":[{"name":"typhonrt","path":"java6-android-glutils/src/main/java/org/typhonrt","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main/java":{"items":[{"name":"org","path":"java6-android-glutils/src/main/java/org","contentType":"directory"}],"totalCount":1},"java6-android-glutils/src/main":{"items":[{"name":"java","path":"java6-android-glutils/src/main/java","contentType":"directory"},{"name":"AndroidManifest.xml","path":"java6-android-glutils/src/main/AndroidManifest.xml","contentType":"file"}],"totalCount":2},"java6-android-glutils/src":{"items":[{"name":"main","path":"java6-android-glutils/src/main","contentType":"directory"}],"totalCount":1},"java6-android-glutils":{"items":[{"name":"src","path":"java6-android-glutils/src","contentType":"directory"},{"name":".gitignore","path":"java6-android-glutils/.gitignore","contentType":"file"},{"name":"build.gradle","path":"java6-android-glutils/build.gradle","contentType":"file"},{"name":"proguard-rules.pro","path":"java6-android-glutils/proguard-rules.pro","contentType":"file"}],"totalCount":4},"":{"items":[{"name":"gradle","path":"gradle","contentType":"directory"},{"name":"java6-android-glutils","path":"java6-android-glutils","contentType":"directory"},{"name":"java6-glutils-commons","path":"java6-glutils-commons","contentType":"directory"},{"name":"java6-math","path":"java6-math","contentType":"directory"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"AUTHORS.md","path":"AUTHORS.md","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"build.gradle","path":"build.gradle","contentType":"file"},{"name":"gradle.properties","path":"gradle.properties","contentType":"file"},{"name":"gradlew","path":"gradlew","contentType":"file"},{"name":"gradlew.bat","path":"gradlew.bat","contentType":"file"},{"name":"settings.gradle","path":"settings.gradle","contentType":"file"}],"totalCount":13}},"fileTreeProcessingTime":39.818154,"foldersToFetch":[],"repo":{"id":27989471,"defaultBranch":"master","name":"java6-android-glframework","ownerLogin":"modern-java-graphics","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2014-12-14T09:24:09.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/18384086?v=4","public":true,"private":false,"isOrgOwned":true},"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"master","listCacheKey":"v0:1613749551.7505112","canEdit":false,"refType":"branch","currentOid":"1327362c33b8a38915f05de8b4b281e2085986c3"},"path":"java6-android-glutils/src/main/java/org/typhonrt/android/java6/opengl/utils/GLSurfaceView2.java","currentUser":null,"blob":{"rawLines":["/**"," * Copyright 2015 Michael Leahy / TyphonRT, Inc."," *"," * This Source Code Form is subject to the terms of the Mozilla Public"," * License, v. 2.0. If a copy of the MPL was not distributed with this"," * file, You can obtain one at http://mozilla.org/MPL/2.0/."," */","package org.typhonrt.android.java6.opengl.utils;","","/**"," * ORIGINAL SOURCE -"," * Copyright (C) 2008 The Android Open Source Project"," *"," * Licensed under the Apache License, Version 2.0 (the \"License\");"," * you may not use this file except in compliance with the License."," * You may obtain a copy of the License at"," *"," * http://www.apache.org/licenses/LICENSE-2.0"," *"," * Unless required by applicable law or agreed to in writing, software"," * distributed under the License is distributed on an \"AS IS\" BASIS,"," * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied."," * See the License for the specific language governing permissions and"," * limitations under the License."," */","import android.content.Context;","import android.opengl.EGL14;","import android.opengl.EGLConfig;","import android.opengl.EGLContext;","import android.opengl.EGLDisplay;","import android.opengl.EGLExt;","import android.opengl.EGLSurface;","import android.util.AttributeSet;","import android.util.Log;","import android.view.SurfaceHolder;","import android.view.SurfaceView;","","import org.typhonrt.commons.java6.opengl.utils.IGLVersion;","import org.typhonrt.commons.java6.opengl.utils.XeGLUnknown;","","import java.lang.ref.WeakReference;","import java.util.ArrayList;","","/**"," * An implementation of SurfaceView that uses the dedicated surface for displaying OpenGL rendering."," *
"," * A GLSurfaceView2 provides the following features:"," *
"," *
For more information about how to use OpenGL, read the"," * OpenGL developer guide.
"," *"," * class MyGLSurfaceView extends GLSurfaceView2 {"," * "," * private MyRenderer mMyRenderer;"," * "," * public void start() {"," * mMyRenderer = ...;"," * setRenderer(mMyRenderer);"," * }"," * "," * public boolean onKeyDown(int keyCode, KeyEvent event) {"," * if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {"," * queueEvent(new Runnable() {"," * // This method will be called on the rendering"," * // thread:"," * public void run() {"," * mMyRenderer.handleDpadCenter();"," * }});"," * return true;"," * }"," * return super.onKeyDown(keyCode, event);"," * }"," * }"," *"," */","public class GLSurfaceView2 extends SurfaceView implements SurfaceHolder.Callback","{"," private final static String s_TAG = \"GLSurfaceView2\";"," private final static boolean s_LOG_ATTACH_DETACH = false;"," private final static boolean s_LOG_THREADS = false;"," private final static boolean s_LOG_PAUSE_RESUME = false;"," private final static boolean s_LOG_SURFACE = false;"," private final static boolean s_LOG_RENDERER = false;"," private final static boolean s_LOG_RENDERER_DRAW_FRAME = false;"," private final static boolean s_LOG_EGL = false;",""," private static final int s_DEFAULT_SURFACE_ATTRIBS[] = { EGL14.EGL_NONE };",""," /**"," * The renderer only renders"," * when the surface is created, or when {@link #requestRender} is called."," *"," * @see #getRenderMode()"," * @see #setRenderMode(int)"," * @see #requestRender()"," */"," public final static int s_RENDERMODE_WHEN_DIRTY = 0;"," /**"," * The renderer is called"," * continuously to re-render the scene."," *"," * @see #getRenderMode()"," * @see #setRenderMode(int)"," */"," public final static int s_RENDERMODE_CONTINUOUSLY = 1;",""," private static final GLThreadManager s_GLThreadManager = new GLThreadManager();",""," private final WeakReference
This method should be called once and only once in the life-cycle of"," * a GLSurfaceView2."," *
The following GLSurfaceView2 methods can only be called before"," * setRenderer is called:"," *
If this method is"," * called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
"," * If this method is not called, then by default"," * a context will be created with no shared context and"," * with a null attribute list."," */"," public void setEGLContextFactory(EGLContextFactory factory)"," {"," checkRenderThreadState();"," eglContextFactory = factory;"," }",""," /**"," * Install a custom EGLWindowSurfaceFactory."," *If this method is"," * called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
"," * If this method is not called, then by default"," * a window surface will be created with a null attribute list."," */"," public void setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory factory)"," {"," checkRenderThreadState();"," eglWindowSurfaceFactory = factory;"," }",""," /**"," * Install a custom EGLConfigChooser."," *If this method is"," * called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
"," * If no setEGLConfigChooser method is called, then by default the"," * view will choose an EGLConfig that is compatible with the current"," * android.view.Surface, with a depth buffer depth of"," * at least 16 bits."," *"," * @param configChooser"," */"," public void setEGLConfigChooser(EGLConfigChooser configChooser)"," {"," checkRenderThreadState();"," eglConfigChooser = configChooser;"," }",""," /**"," * Install a config chooser which will choose a config"," * as close to 16-bit RGB as possible, with or without an optional depth"," * buffer as close to 16-bits as possible."," *If this method is"," * called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
"," * If no setEGLConfigChooser method is called, then by default the"," * view will choose an RGB_888 surface with a depth buffer depth of"," * at least 16 bits."," *"," * @param needDepth"," */"," public void setEGLConfigChooser(boolean needDepth)"," {"," setEGLConfigChooser(new SimpleEGLConfigChooser(needDepth));"," }",""," /**"," * Install a config chooser which will choose a config"," * with at least the specified depthSize and stencilSize,"," * and exactly the specified redSize, greenSize, blueSize and alphaSize."," *If this method is"," * called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
"," * If no setEGLConfigChooser method is called, then by default the"," * view will choose an RGB_888 surface with a depth buffer depth of"," * at least 16 bits."," */"," public void setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize,"," int stencilSize)"," {"," setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize,"," blueSize, alphaSize, depthSize, stencilSize));"," }",""," public void setPresentationTime(long timestamp)"," {"," glThread.setPresentationTime(timestamp);"," setPresentationTime(timestamp);"," }",""," /**"," * Inform the default EGLContextFactory and default EGLConfigChooser"," * which EGLContext client version to pick."," *Use this method to create an OpenGL ES 2.0-compatible context."," * Example:"," *
"," * public MyView(Context context) {"," * super(context);"," * setEGLContextClientVersion(2); // Pick an OpenGL ES 2.0 context."," * setRenderer(new MyRenderer());"," * }"," *"," *
Note: Activities which require OpenGL ES 2.0 should indicate this by"," * setting @lt;uses-feature android:glEsVersion=\"0x00020000\" /> in the activity's"," * AndroidManifest.xml file."," *
If this method is called, it must be called before {@link #setRenderer(Renderer)}"," * is called."," *
This method only affects the behavior of the default EGLContexFactory and the"," * default EGLConfigChooser. If"," * {@link #setEGLContextFactory(EGLContextFactory)} has been called, then the supplied"," * EGLContextFactory is responsible for creating an OpenGL ES 2.0-compatible context."," * If"," * {@link #setEGLConfigChooser(EGLConfigChooser)} has been called, then the supplied"," * EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config."," *"," * @param version The EGLContext client version to choose. Use 2 for OpenGL ES 2.0"," */"," public void setEGLContextGLESVersion(IGLVersion version)"," {"," checkRenderThreadState();"," eglContextGLESVersion = version;"," }",""," /**"," * Set the rendering mode. When renderMode is"," * s_RENDERMODE_CONTINUOUSLY, the renderer is called"," * repeatedly to re-render the scene. When renderMode"," * is s_RENDERMODE_WHEN_DIRTY, the renderer only rendered when the surface"," * is created, or when {@link #requestRender} is called. Defaults to s_RENDERMODE_CONTINUOUSLY."," *
"," * Using s_RENDERMODE_WHEN_DIRTY can improve battery life and overall system performance"," * by allowing the GPU and CPU to idle when the view does not need to be updated."," * "," * This method can only be called after {@link #setRenderer(Renderer)}"," *"," * @param renderMode one of the RENDERMODE_X constants"," * @see #s_RENDERMODE_CONTINUOUSLY"," * @see #s_RENDERMODE_WHEN_DIRTY"," */"," public void setRenderMode(int renderMode)"," {"," glThread.setRenderMode(renderMode);"," }",""," /**"," * Get the current rendering mode. May be called"," * from any thread. Must not be called before a renderer has been set."," *"," * @return the current rendering mode."," * @see #s_RENDERMODE_CONTINUOUSLY"," * @see #s_RENDERMODE_WHEN_DIRTY"," */"," public int getRenderMode()"," {"," return glThread.getRenderMode();"," }",""," /**"," * Request that the renderer render a frame."," * This method is typically used when the render mode has been set to"," * {@link #s_RENDERMODE_WHEN_DIRTY}, so that frames are only rendered on demand."," * May be called"," * from any thread. Must not be called before a renderer has been set."," */"," public void requestRender()"," {"," glThread.requestRender();"," }",""," /**"," * This method is part of the SurfaceHolder.Callback interface, and is"," * not normally called or subclassed by clients of GLSurfaceView2."," */"," public void surfaceCreated(SurfaceHolder holder)"," {"," glThread.surfaceCreated();"," }",""," /**"," * This method is part of the SurfaceHolder.Callback interface, and is"," * not normally called or subclassed by clients of GLSurfaceView2."," */"," public void surfaceDestroyed(SurfaceHolder holder)"," {"," // Surface will be destroyed when we return"," glThread.surfaceDestroyed();"," }",""," /**"," * This method is part of the SurfaceHolder.Callback interface, and is"," * not normally called or subclassed by clients of GLSurfaceView2."," */"," public void surfaceChanged(SurfaceHolder holder, int format, int w, int h)"," {"," glThread.onWindowResize(w, h);"," }",""," /**"," * Inform the view that the activity is paused. The owner of this view must"," * call this method when the activity is paused. Calling this method will"," * pause the rendering thread."," * Must not be called before a renderer has been set."," */"," public void onPause()"," {"," glThread.onPause();"," }",""," /**"," * Inform the view that the activity is resumed. The owner of this view must"," * call this method when the activity is resumed. Calling this method will"," * recreate the OpenGL display and resume the rendering"," * thread."," * Must not be called before a renderer has been set."," */"," public void onResume()"," {"," glThread.onResume();"," }",""," /**"," * Queue a runnable to be run on the GL rendering thread. This can be used"," * to communicate with the Renderer on the rendering thread."," * Must not be called before a renderer has been set."," *"," * @param r the runnable to be run on the GL rendering thread."," */"," public void queueEvent(Runnable r)"," {"," glThread.queueEvent(r);"," }",""," /**"," * This method is used as part of the View class and is not normally"," * called or subclassed by clients of GLSurfaceView2."," */"," @Override"," protected void onAttachedToWindow()"," {"," super.onAttachedToWindow();",""," if (s_LOG_ATTACH_DETACH)"," {"," Log.d(s_TAG, \"onAttachedToWindow reattach =\" + detached);"," }",""," if (detached && (renderer != null))"," {"," int renderMode = s_RENDERMODE_CONTINUOUSLY;",""," if (glThread != null)"," {"," renderMode = glThread.getRenderMode();"," }",""," glThread = new GLThread(thisWeakRef);",""," if (renderMode != s_RENDERMODE_CONTINUOUSLY)"," {"," glThread.setRenderMode(renderMode);"," }",""," glThread.start();"," }",""," detached = false;"," }",""," @Override"," protected void onDetachedFromWindow()"," {"," if (s_LOG_ATTACH_DETACH)"," {"," Log.d(s_TAG, \"onDetachedFromWindow\");"," }",""," if (glThread != null)"," {"," glThread.requestExitAndWait();"," }",""," detached = true;",""," super.onDetachedFromWindow();"," }",""," // ----------------------------------------------------------------------",""," /**"," * A generic renderer interface."," *"," * The renderer is responsible for making OpenGL calls to render a frame."," *
"," * GLSurfaceView2 clients typically create their own classes that implement"," * this interface, and then call {@link GLSurfaceView2#setRenderer} to"," * register the renderer with the GLSurfaceView2."," *
"," *
"," *For more information about how to use OpenGL, read the"," * OpenGL developer guide.
"," *"," * void onGLSurfaceChanged(int width, int height) {"," * gl.glViewport(0, 0, width, height);"," * // for a fixed camera, set the projection too"," * float ratio = (float) width / height;"," * gl.glMatrixMode(GL10.GL_PROJECTION);"," * gl.glLoadIdentity();"," * gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);"," * }"," *"," *"," * @param width"," * @param height"," */"," void onGLSurfaceChanged(int width, int height);",""," /**"," * Called to draw the current frame."," * "," * This method is responsible for drawing the current frame."," * "," * The implementation of this method typically looks like this:"," *
"," * void onGLDrawFrame(GL10 gl) {"," * gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);"," * //... other gl calls to render the scene ..."," * }"," *"," */"," void onGLDrawFrame();"," }",""," /**"," * An interface for customizing the eglCreateContext and eglDestroyContext calls."," * "," * This interface must be implemented by clients wishing to call"," * {@link GLSurfaceView2#setEGLContextFactory(EGLContextFactory)}"," */",""," public interface EGLContextFactory"," {"," EGLContext createContext(EGLDisplay display, EGLConfig eglConfig);",""," void destroyContext(EGLDisplay display, EGLContext context);"," }",""," private class DefaultContextFactory implements EGLContextFactory"," {"," public EGLContext createContext(EGLDisplay display, EGLConfig config)"," {"," // If minor version is specified then use EGL_CONTEXT_MAJOR_VERSION_KHR / EGL_CONTEXT_MINOR_VERSION_KHR"," // otherwise use EGL_CONTEXT_CLIENT_VERSION",""," int majorGLVersion = eglContextGLESVersion.getMajorVersion();"," int minorGLVersion = eglContextGLESVersion.getMinorVersion();",""," int majorMinorAttribList[] = new int[]{ EGLExt.EGL_CONTEXT_MAJOR_VERSION_KHR, majorGLVersion,"," EGLExt.EGL_CONTEXT_MINOR_VERSION_KHR, minorGLVersion, EGL14.EGL_NONE };",""," int majorAttribList[] = new int[]{ EGL14.EGL_CONTEXT_CLIENT_VERSION, majorGLVersion, EGL14.EGL_NONE };",""," EGLContext context = null;",""," if (minorGLVersion != 0)"," {"," context = EGL14.eglCreateContext(display, config, EGL14.EGL_NO_CONTEXT,"," majorGLVersion != 0 ? majorMinorAttribList : null, 0);"," }",""," if (context == null || context.equals(EGL14.EGL_NO_CONTEXT))"," {"," Log.d(s_TAG, \"DefaultContextFactory - createContext: Could create requested context: \""," +eglContextGLESVersion);",""," Log.d(s_TAG, \"DefaultContextFactory - createContest: \" +"," \"Attempting to create context based on major GLES version: \" +majorGLVersion);",""," context = EGL14.eglCreateContext(display, config, EGL14.EGL_NO_CONTEXT,"," majorGLVersion != 0 ? majorAttribList : null, 0);",""," minorGLVersion = 0;"," }",""," int clientValue[] = new int[1];",""," EGL14.eglQueryContext(display, context, EGLExt.EGL_CONTEXT_MAJOR_VERSION_KHR, clientValue, 0);"," if (EGL14.eglGetError() != EGL14.EGL_BAD_ATTRIBUTE)"," {"," majorGLVersion = clientValue[0];"," }",""," EGL14.eglQueryContext(display, context, EGLExt.EGL_CONTEXT_MINOR_VERSION_KHR, clientValue, 0);"," if (EGL14.eglGetError() != EGL14.EGL_BAD_ATTRIBUTE)"," {"," minorGLVersion = clientValue[0];"," }",""," GLSurfaceView2.this.actualEGLContextGLESVersion = AndroidGLESUtil.getGLVersion(majorGLVersion, minorGLVersion);",""," return context;"," }",""," public void destroyContext(EGLDisplay display, EGLContext context)"," {"," if (!EGL14.eglDestroyContext(display, context))"," {"," Log.e(\"DefaultContextFactory\", \"display:\" + display + \" context: \" + context);",""," if (s_LOG_THREADS)"," {"," Log.i(\"DefaultContextFactory\", \"tid=\" + Thread.currentThread().getId());"," }",""," EglHelper.throwEglException(\"eglDestroyContex\", EGL14.eglGetError());"," }"," }"," }",""," /**"," * An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls."," * "," * This interface must be implemented by clients wishing to call"," * {@link GLSurfaceView2#setEGLWindowSurfaceFactory(EGLWindowSurfaceFactory)}"," */"," public interface EGLWindowSurfaceFactory"," {"," /**"," * @return null if the surface cannot be constructed."," */"," EGLSurface createWindowSurface(EGLDisplay display, EGLConfig config, Object nativeWindow);",""," void destroySurface(EGLDisplay display, EGLSurface surface);"," }",""," private static class DefaultWindowSurfaceFactory implements EGLWindowSurfaceFactory"," {"," public EGLSurface createWindowSurface(EGLDisplay display, EGLConfig config, Object nativeWindow)"," {"," EGLSurface result = null;"," try"," {"," result = EGL14.eglCreateWindowSurface(display, config, nativeWindow, s_DEFAULT_SURFACE_ATTRIBS, 0);"," }"," catch (IllegalArgumentException e)"," {"," // This exception indicates that the surface flinger surface"," // is not valid. This can happen if the surface flinger surface has"," // been torn down, but the application has not yet been"," // notified via SurfaceHolder.Callback.surfaceDestroyed."," // In theory the application should be notified first,"," // but in practice sometimes it is not. See b/4588890"," Log.e(s_TAG, \"eglCreateWindowSurface\", e);"," }"," return result;"," }",""," public void destroySurface(EGLDisplay display, EGLSurface surface)"," {"," EGL14.eglDestroySurface(display, surface);"," }"," }",""," /**"," * An interface for choosing an EGLConfig configuration from a list of"," * potential configurations."," * "," * This interface must be implemented by clients wishing to call"," * {@link GLSurfaceView2#setEGLConfigChooser(EGLConfigChooser)}"," */"," public interface EGLConfigChooser"," {"," /**"," * Choose a configuration from the list. Implementors typically"," * implement this method by calling"," * {@link javax.microedition.khronos.egl.EGL10#eglChooseConfig} and iterating through the results. Please consult the"," * EGL specification available from The Khronos Group to learn how to call eglChooseConfig."," *"," * @param display the current display."," * @return the chosen configuration."," */"," EGLConfig chooseConfig(EGLDisplay display);"," }",""," private abstract class BaseConfigChooser implements EGLConfigChooser"," {"," protected int[] configSpec;",""," public BaseConfigChooser(int[] configSpec)"," {"," this.configSpec = filterConfigSpec(configSpec);"," }",""," public EGLConfig chooseConfig(EGLDisplay display)"," {"," EGLConfig[] configs = new EGLConfig[1];",""," int[] num_config = new int[1];",""," if (!EGL14.eglChooseConfig(display, configSpec, 0, configs, 0, configs.length, num_config, 0))"," {"," throw new IllegalArgumentException(\"eglChooseConfig failed\");"," }",""," int numConfigs = num_config[0];",""," if (numConfigs <= 0)"," {"," throw new IllegalArgumentException(\"No configs match configSpec\");"," }",""," if (!EGL14.eglChooseConfig(display, configSpec, 0, configs, 0, configs.length, num_config, 0))"," {"," throw new IllegalArgumentException(\"eglChooseConfig#2 failed\");"," }",""," EGLConfig config = chooseConfig(display, configs);"," if (config == null)"," {"," throw new IllegalArgumentException(\"No config chosen\");"," }",""," return config;"," }",""," abstract EGLConfig chooseConfig(EGLDisplay display, EGLConfig[] configs);",""," private int[] filterConfigSpec(int[] configSpec)"," {"," int majorGLVersion = eglContextGLESVersion.getMajorVersion();",""," if (majorGLVersion != 2 && majorGLVersion != 3)"," {"," return configSpec;"," }"," /* We know none of the subclasses define EGL_RENDERABLE_TYPE."," * And we know the configSpec is well formed."," */"," int len = configSpec.length;"," int[] newConfigSpec = new int[len + 2];"," System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1);"," newConfigSpec[len - 1] = EGL14.EGL_RENDERABLE_TYPE;"," if (majorGLVersion == 2)"," {"," newConfigSpec[len] = EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */"," }"," else"," {"," newConfigSpec[len] = EGLExt.EGL_OPENGL_ES3_BIT_KHR; /* EGL_OPENGL_ES3_BIT_KHR */"," }"," newConfigSpec[len + 1] = EGL14.EGL_NONE;"," return newConfigSpec;"," }"," }",""," /**"," * Choose a configuration with exactly the specified r,g,b,a sizes,"," * and at least the specified depth and stencil sizes."," */"," private class ComponentSizeChooser extends BaseConfigChooser"," {"," private int[] value;",""," // Subclasses can adjust these values:"," protected int redSize;"," protected int greenSize;"," protected int blueSize;"," protected int alphaSize;"," protected int depthSize;"," protected int stencilSize;",""," public ComponentSizeChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize,"," int stencilSize)"," {"," super(new int[]{"," EGL14.EGL_RED_SIZE, redSize,"," EGL14.EGL_GREEN_SIZE, greenSize,"," EGL14.EGL_BLUE_SIZE, blueSize,"," EGL14.EGL_ALPHA_SIZE, alphaSize,"," EGL14.EGL_DEPTH_SIZE, depthSize,"," EGL14.EGL_STENCIL_SIZE, stencilSize,"," EGL14.EGL_NONE});",""," value = new int[1];"," this.redSize = redSize;"," this.greenSize = greenSize;"," this.blueSize = blueSize;"," this.alphaSize = alphaSize;"," this.depthSize = depthSize;"," this.stencilSize = stencilSize;"," }",""," @Override"," public EGLConfig chooseConfig(EGLDisplay display, EGLConfig[] configs)"," {"," for (EGLConfig config : configs)"," {"," int d = findConfigAttrib(display, config, EGL14.EGL_DEPTH_SIZE, 0);"," int s = findConfigAttrib(display, config, EGL14.EGL_STENCIL_SIZE, 0);",""," if ((d >= depthSize) && (s >= stencilSize))"," {"," int r = findConfigAttrib(display, config, EGL14.EGL_RED_SIZE, 0);"," int g = findConfigAttrib(display, config, EGL14.EGL_GREEN_SIZE, 0);"," int b = findConfigAttrib(display, config, EGL14.EGL_BLUE_SIZE, 0);"," int a = findConfigAttrib(display, config, EGL14.EGL_ALPHA_SIZE, 0);",""," if ((r == redSize) && (g == greenSize) && (b == blueSize) && (a == alphaSize))"," {"," return config;"," }"," }"," }"," return null;"," }",""," private int findConfigAttrib(EGLDisplay display, EGLConfig config, int attribute, int defaultValue)"," {"," if (EGL14.eglGetConfigAttrib(display, config, attribute, value, 0))"," {"," return value[0];"," }"," return defaultValue;"," }"," }",""," /**"," * This class will choose a RGB_888 surface with or without a depth buffer."," */"," private class SimpleEGLConfigChooser extends ComponentSizeChooser"," {"," public SimpleEGLConfigChooser(boolean withDepthBuffer)"," {"," super(8, 8, 8, 0, withDepthBuffer ? 16 : 0, 0);"," }"," }",""," /**"," * An EGL helper class."," */",""," private static class EglHelper"," {"," private WeakReference