下面列出了怎么用javax.microedition.khronos.egl.EGLContext的API类实例代码及写法,或者点击链接到github查看源代码。
public void start() {
mEgl = (EGL10) EGLContext.getEGL();
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed");
}
int[] version = new int[2];
if (!mEgl.eglInitialize(mEglDisplay, version)) {
throw new RuntimeException("eglInitialize failed");
}
mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
mEglContext = null;
throwEglException("createContext");
}
mEglSurface = null;
}
private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException {
/* Get an EGL instance. */
final EGL10 egl = (EGL10) EGLContext.getEGL();
/* Get to the default display. */
final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
/* We can now initialize EGL for that display. */
final int[] version = new int[2];
egl.eglInitialize(eglDisplay, version);
final ConfigChooser configChooser = new ConfigChooser(new ConfigChooserOptions());
try {
configChooser.chooseConfig(egl, eglDisplay);
} catch (final IllegalArgumentException e) {
throw new DeviceNotSupportedException(DeviceNotSupportedCause.EGLCONFIG_NOT_FOUND, e);
}
}
private BlurContext prepare(Bitmap bitmap) {
EGLContext context = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext();
if (context.equals(EGL10.EGL_NO_CONTEXT)) {
throw new IllegalStateException("This thread has no EGLContext.");
}
if (mNeedRelink || mProgram == null) {
deletePrograms();
mProgram = ProgramFactory.create(vertexShaderCode, ShaderUtil.getFragmentShaderCode(mMode));
mNeedRelink = false;
}
if (mProgram.id() == 0) {
throw new IllegalStateException("Failed to create program.");
}
int w = bitmap.getWidth();
int h = bitmap.getHeight();
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
GLES20.glViewport(0, 0, w, h);
return new BlurContext(bitmap);
}
@Override
public EGLContext createContext(EGL10 egl, EGLDisplay display,
EGLConfig eglConfig) {
EGLContext context = egl.eglCreateContext(display, eglConfig,
EGL10.EGL_NO_CONTEXT, new int[]{
EGL_CONTEXT_CLIENT_VERSION,
3,
EGL10.EGL_NONE
});
if (context != null && context != EGL10.EGL_NO_CONTEXT &&
context.getGL() != null) {
renderer.setVersion(3);
return context;
}
return egl.eglCreateContext(display, eglConfig,
EGL10.EGL_NO_CONTEXT, new int[]{
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL10.EGL_NONE
});
}
/**
* Clears the frames from the current surface. This should only be called when
* the implementing video view has finished playback or otherwise released
* the surface
*/
@Override
public void clearSurface() {
try {
EGL10 gl10 = (EGL10) EGLContext.getEGL();
EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
gl10.eglInitialize(display, null);
EGLConfig[] configs = new EGLConfig[1];
gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], this, new int[]{EGL10.EGL_NONE});
gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
gl10.eglSwapBuffers(display, eglSurface);
gl10.eglDestroySurface(display, eglSurface);
gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
gl10.eglDestroyContext(display, context);
gl10.eglTerminate(display);
} catch (Exception e) {
Log.e(TAG, "Error clearing surface", e);
}
}
private static void addExtensionsForConfig(EGL10 egl10, EGLDisplay egldisplay, EGLConfig eglconfig, int ai[],
int ai1[], Set<String> set) {
EGLContext eglcontext = egl10.eglCreateContext(egldisplay, eglconfig, EGL10.EGL_NO_CONTEXT, ai1);
if (eglcontext != EGL10.EGL_NO_CONTEXT) {
javax.microedition.khronos.egl.EGLSurface eglsurface =
egl10.eglCreatePbufferSurface(egldisplay, eglconfig, ai);
if (eglsurface == EGL10.EGL_NO_SURFACE) {
egl10.eglDestroyContext(egldisplay, eglcontext);
} else {
egl10.eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
String s = GLES10.glGetString(7939);
if (s != null && !s.isEmpty()) {
String as[] = s.split(" ");
int i = as.length;
for (int j = 0; j < i; j++) {
set.add(as[j]);
}
}
egl10.eglMakeCurrent(egldisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
egl10.eglDestroySurface(egldisplay, eglsurface);
egl10.eglDestroyContext(egldisplay, eglcontext);
}
}
}
public void start() {
mEgl = (EGL10) EGLContext.getEGL();
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
throw new RuntimeException("eglGetDisplay failed");
}
int[] version = new int[2];
if (!mEgl.eglInitialize(mEglDisplay, version)) {
throw new RuntimeException("eglInitialize failed");
}
mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);
mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
mEglContext = null;
throwEglException("createContext");
}
mEglSurface = null;
}
public void initEGL() {
mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD, null);
mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] curGLVersion = new int[2];
mEGL.eglInitialize(mGLDisplay, curGLVersion);
Log.i("GL", "GL version = " + curGLVersion[0] + "."
+ curGLVersion[1]);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
num_config);
mGLConfig = configs[0];
mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
.getHolder(), null);
mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
EGL10.EGL_NO_CONTEXT, null);
mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD
| GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
@Override
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e("DefaultContextFactory", "display:" + display
+ " context: " + context);
if (LOG_THREADS) {
Log.i("DefaultContextFactory", "tid="
+ Thread.currentThread().getId());
}
throw new RuntimeException("eglDestroyContext failed: " + ""); // +
// EGLLogWrapper.getErrorString(egl.eglGetError()));
}
}
/**
* Clears the surface texture by attaching a GL context and clearing it.
* Code taken from <a href="http://stackoverflow.com/a/31582209">Hugo Gresse's answer on stackoverflow.com</a>.
*/
private void clearSurface() {
if (mSurface == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
return;
}
EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
egl.eglInitialize(display, null);
int[] attribList = {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE, 0, // placeholder for recordable [@-3]
EGL10.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
EGLConfig config = configs[0];
EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
12440, 2, EGL10.EGL_NONE
});
EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, mSurface, new int[]{
EGL10.EGL_NONE
});
egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
GLES20.glClearColor(0, 0, 0, 1);
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
egl.eglSwapBuffers(display, eglSurface);
egl.eglDestroySurface(display, eglSurface);
egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
egl.eglDestroyContext(display, context);
egl.eglTerminate(display);
}
public void initEGL() {
mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD, null);
mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] curGLVersion = new int[2];
mEGL.eglInitialize(mGLDisplay, curGLVersion);
Log.i("GL", "GL version = " + curGLVersion[0] + "."
+ curGLVersion[1]);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
num_config);
mGLConfig = configs[0];
mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
.getHolder(), null);
mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
EGL10.EGL_NO_CONTEXT, null);
mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD
| GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e(TAG, "display:" + display + " context: " + context);
throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
}
}
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
if (LOG_THREADS) {
Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
}
EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
}
}
public static int getMaxTextureSize() {
// Safe minimum default size
final int IMAGE_MAX_BITMAP_DIMENSION = 2048;
// Get EGL Display
EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
// Initialise
int[] version = new int[2];
egl.eglInitialize(display, version);
// Query total number of configurations
int[] totalConfigurations = new int[1];
egl.eglGetConfigs(display, null, 0, totalConfigurations);
// Query actual list configurations
EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);
int[] textureSize = new int[1];
int maximumTextureSize = 0;
// Iterate through all the configurations to located the maximum texture size
for (int i = 0; i < totalConfigurations[0]; i++) {
// Only need to check for width since opengl textures are always squared
egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);
// Keep track of the maximum texture size
if (maximumTextureSize < textureSize[0])
maximumTextureSize = textureSize[0];
}
// Release
egl.eglTerminate(display);
// Return largest texture size found, or default
return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public void destroyContext(android.opengl.EGLDisplay display, android.opengl.EGLContext context) {
if (!EGL14.eglDestroyContext(display, context)) {
FileLogger.e(TAG, "DefaultContextFactory " + "display:" + display + " context: " + context);
EglHelper.throwEglException("eglDestroyContext", EGL14.eglGetError());
}
}
@Override
public void destroyContext(EGL10 arg0, EGLDisplay arg1, EGLContext arg2) {
Log.w("gl", "Invalidating texture context");
if(drawcontext != null) drawcontext.invalidateContext();
AndroidTextDrawer.invalidateTextures();
IContextDestroyedListener listener = contextDestroyedListener;
if (listener != null) {
listener.glContextDestroyed();
}
arg0.eglDestroyContext(arg1, arg2);
}
public void initEGL() {
mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD, null);
mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] curGLVersion = new int[2];
mEGL.eglInitialize(mGLDisplay, curGLVersion);
Log.i("GL", "GL version = " + curGLVersion[0] + "."
+ curGLVersion[1]);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
num_config);
mGLConfig = configs[0];
mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
.getHolder(), null);
mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
EGL10.EGL_NO_CONTEXT, null);
mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD
| GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
public void initEGL() {
mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD, null);
mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] curGLVersion = new int[2];
mEGL.eglInitialize(mGLDisplay, curGLVersion);
Log.i("GL", "GL version = " + curGLVersion[0] + "."
+ curGLVersion[1]);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
num_config);
mGLConfig = configs[0];
mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
.getHolder(), null);
mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
EGL10.EGL_NO_CONTEXT, null);
mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD
| GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
if (LOG_THREADS) {
Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
}
EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
}
}
public PixelBuffer(final int width, final int height, final boolean isStereo) {
mWidth = isStereo ? width * 2 : width;
mHeight = height;
mIb = IntBuffer.allocate(mWidth * mHeight);
mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);
mEGL = (EGL10) EGLContext.getEGL();
mEGLDisplay = mEGL.eglGetDisplay(EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
mEGL.eglInitialize(mEGLDisplay, version);
mEGLConfigs = chooseConfigs();
mEGLConfig = mEGLConfigs[0];
mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL_NO_CONTEXT, new int[] {
0x3098, // EGL_CONTEXT_CLIENT_VERSION
2, // OpenGL ES 2.0
EGL10.EGL_NONE });
mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, new int[] {
EGL_WIDTH, mWidth,
EGL_HEIGHT, mHeight,
EGL_NONE
});
mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
mGL = (GL10) mEGLContext.getGL();
mThreadOwner = Thread.currentThread().getName();
}
/**
* 現在のスレッドの既存のレンダリングコンテキストがあればそれを共有して
* 新しいレンダリングコンテキストを生成する
* 既存のレンダリングコンテキストが存在していなければ独立したレンダリングコンテキストを
* 生成する
* @param maxClientVersion
* @param withDepthBuffer
* @param stencilBits
* @param isRecordable
* @return
*/
/*package*/ static EGLBase createFromCurrentImpl(final int maxClientVersion,
final boolean withDepthBuffer, final int stencilBits, final boolean isRecordable) {
Context context = null;
final EGL10 egl10 = (EGL10)EGLContext.getEGL();
final EGLContext currentContext = egl10.eglGetCurrentContext();
final EGLSurface currentSurface = egl10.eglGetCurrentSurface(EGL10.EGL_DRAW);
if ((currentContext != null) && (currentSurface != null)) {
context = wrap(currentContext);
}
return new EGLBase10(maxClientVersion, context, withDepthBuffer, stencilBits, isRecordable);
}
public static int getMaxTextureSize() {
// Safe minimum default size
final int IMAGE_MAX_BITMAP_DIMENSION = 2048;
// Get EGL Display
EGL10 egl = (EGL10) EGLContext.getEGL();
EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
// Initialise
int[] version = new int[2];
egl.eglInitialize(display, version);
// Query total number of configurations
int[] totalConfigurations = new int[1];
egl.eglGetConfigs(display, null, 0, totalConfigurations);
// Query actual list configurations
EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);
int[] textureSize = new int[1];
int maximumTextureSize = 0;
// Iterate through all the configurations to located the maximum texture size
for (int i = 0; i < totalConfigurations[0]; i++) {
// Only need to check for width since opengl textures are always squared
egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);
// Keep track of the maximum texture size
if (maximumTextureSize < textureSize[0])
maximumTextureSize = textureSize[0];
}
// Release
egl.eglTerminate(display);
// Return largest texture size found, or default
return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
EGL10.EGL_NONE };
return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
mEGLContextClientVersion != 0 ? attrib_list : null);
}
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
EGL10.EGL_NONE };
return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
mEGLContextClientVersion != 0 ? attrib_list : null);
}
public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw,
EGLSurface read, EGLContext context) {
begin("eglMakeCurrent");
arg("display", display);
arg("draw", draw);
arg("read", read);
arg("context", context);
end();
boolean result = mEgl10.eglMakeCurrent(display, draw, read, context);
returns(result);
checkError();
return result;
}
public void initEGL() {
mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD, null);
mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
int[] curGLVersion = new int[2];
mEGL.eglInitialize(mGLDisplay, curGLVersion);
Log.i("GL", "GL version = " + curGLVersion[0] + "."
+ curGLVersion[1]);
EGLConfig[] configs = new EGLConfig[1];
int[] num_config = new int[1];
mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
num_config);
mGLConfig = configs[0];
mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
.getHolder(), null);
mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
EGL10.EGL_NO_CONTEXT, null);
mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
GLDebugHelper.CONFIG_CHECK_GL_ERROR
| GLDebugHelper.CONFIG_CHECK_THREAD
| GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
private static void addEglExtensions(Set<String> glExtensions) {
EGL10 egl10 = (EGL10) EGLContext.getEGL();
if (egl10 != null) {
EGLDisplay display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
egl10.eglInitialize(display, new int[2]);
int cf[] = new int[1];
if (egl10.eglGetConfigs(display, null, 0, cf)) {
EGLConfig[] configs = new EGLConfig[cf[0]];
if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
int[] a1 =
new int[]{EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT,
EGL10.EGL_NONE};
int[] a2 = new int[]{12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE};
int[] a3 = new int[1];
for (int i = 0; i < cf[0]; i++) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3);
if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, a3);
if ((1 & a3[0]) != 0) {
egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, a3);
if ((1 & a3[0]) != 0) {
addExtensionsForConfig(egl10, display, configs[i], a1, null, glExtensions);
}
if ((4 & a3[0]) != 0) {
addExtensionsForConfig(egl10, display, configs[i], a1, a2, glExtensions);
}
}
}
}
}
}
egl10.eglTerminate(display);
}
}
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
if (LOG_THREADS) {
Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
}
EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
}
}
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
if (!egl.eglDestroyContext(display, context)) {
Log.e(TAG, "display:" + display + " context: " + context);
throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
}
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@Override
public android.opengl.EGLContext createContextAPI17(android.opengl.EGLDisplay display, android.opengl.EGLConfig eglConfig, android.opengl.EGLContext sharedContext) {
int[] attrib_list = {
EGL14.EGL_CONTEXT_CLIENT_VERSION, contextClientVersion,
EGL14.EGL_NONE};
return EGL14.eglCreateContext(display, eglConfig, sharedContext, attrib_list, 0);
}