egl10
private EGL10 mEgl;
private EGLDisplay mEglDisplay = EGL10.EGL_NO_DISPLAY;
private EGLContext mEglContext = EGL10.EGL_NO_CONTEXT;
private EGLSurface mEglSurface = EGL10.EGL_NO_SURFACE;
//初始化
mEgl = (EGL10) EGLContext.getEGL();
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
mEgl.eglInitialize(mEglDisplay, null);
int[] configSpec = {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_SURFACE_TYPE,
EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE };
int[] num_config = new int[1];
EGLConfig[] configs = new EGLConfig[1];
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, configs[0],
mGLSurfaceViewWeakRef.get().mHolder, null);
int[] attrs = {0x3098, 2, EGL10.EGL_NONE};//0x3098 = EGL_CONTEXT_CLIENT_VERSION
mEglContext = this.mEgl.eglCreateContext(mEglDisplay, configs[0],
EGL10.EGL_NO_CONTEXT, attrs);
mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
//opengl渲染
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
//销毁
if (mEglSurface != EGL10.EGL_NO_SURFACE) {
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
mEglSurface = EGL10.EGL_NO_SURFACE;
}
if (mEglContext != EGL10.EGL_NO_CONTEXT) {
mEgl.eglDestroyContext(mEglDisplay, mEglContext);
mEglContext = EGL10.EGL_NO_CONTEXT;
}
if (mEglDisplay != EGL10.EGL_NO_DISPLAY) {
mEgl.eglTerminate(mEglDisplay);
mEglDisplay = EGL10.EGL_NO_DISPLAY;
}
egl 14
private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
private EGLContext eglCtx = EGL14.EGL_NO_CONTEXT;
private EGLDisplay eglDis = EGL14.EGL_NO_DISPLAY;
初始化
eglDis = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
EGL14.eglInitialize(eglDis, version, 0, version, 1);
int confAttr[] = {
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_GREEN_SIZE, 8,
EGL14.EGL_BLUE_SIZE, 8,
EGL14.EGL_SURFACE_TYPE,
EGL14.EGL_WINDOW_BIT,
EGL14.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
EGL14.eglChooseConfig(eglDis, confAttr, 0, configs, 0, 1, numConfigs, 0);
int ctxAttr[] = {
EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,// 0x3098
EGL14.EGL_NONE
};
eglCtx = EGL14.eglCreateContext(eglDis, configs[0], EGL14.EGL_NO_CONTEXT, ctxAttr, 0);
int[] surfaceAttr = {
EGL14.EGL_NONE
};
eglSurface = EGL14.eglCreateWindowSurface(eglDis, configs[0], surface, surfaceAttr, 0);
EGL14.eglMakeCurrent(eglDis, eglSurface, eglSurface, eglCtx);
//渲染
EGL14.eglSwapBuffers(eglDis, eglSurface);
//销毁
if (eglSurface != EGL14.EGL_NO_SURFACE) {
EGL14.eglMakeCurrent(eglDis, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroySurface(eglDis, eglSurface);
eglSurface = EGL14.EGL_NO_SURFACE;
}
if (eglCtx != EGL14.EGL_NO_CONTEXT) {
EGL14.eglDestroyContext(eglDis, eglCtx);
eglCtx = EGL14.EGL_NO_CONTEXT;
}
if (eglDis != EGL14.EGL_NO_DISPLAY) {
EGL14.eglTerminate(eglDis);
eglDis = EGL14.EGL_NO_DISPLAY;
}
Raphael
EGL 视窗设计是基于人们熟悉的用于 Microsoft Windows ( WGL )和 UNIX ( GLX )上的 OpenGL 的 Native 接口,
与后者比较接近。OpenGL ES 图形管线的状态被存储于 EGL 管理的一个 Context 中。
Frame Buffers 和其他绘制 Surfaces 通过 EGL API 创建、管理和销毁。EGL 同时也控制和提供了对设备显示和可能的设备渲染配置的访问。
EGLRenderSurface window;
EGLint attribList[] =
{
EGL_RENDER_BUFFER, EGL_BACK_BUFFER,
EGL_NONE
);
window = eglCreateWindowSurface(dpy, config, window, attribList);
if(window == EGL_NO_SURFACE)
{
switch(eglGetError())
{
case EGL_BAD_MATCH:
// Check window and EGLConfig attributes to determine
// compatibility, or verify that the EGLConfig
// supports rendering to a window,
break;
case EGL_BAD_CONFIG:
// Verify that provided EGLConfig is valid
break;
case EGL_BAD_NATIVE_WINDOW:
// Verify that provided EGLNativeWindow is valid
break;
case EGL_BAD_ALLOC:
// Not enough resources available. Handle and recover
break;
}
}
egl10 egl14
https://developer.android.google.cn/reference/android/opengl/EGL14?hl=zh-cn
//初始化
private EGL10 mEgl;
private EGLDisplay mEglDisplay = EGL10.EGL_NO_DISPLAY;
private EGLContext mEglContext = EGL10.EGL_NO_CONTEXT;
private EGLSurface mEglSurface = EGL10.EGL_NO_SURFACE;
mEgl = (EGL10) EGLContext.getEGL();
mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
mEgl.eglInitialize(mEglDisplay, null);
int[] configSpec = {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_SURFACE_TYPE,
EGL10.EGL_WINDOW_BIT,
EGL10.EGL_NONE };
int[] num_config = new int[1];
EGLConfig[] configs = new EGLConfig[1];
mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);
mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, configs[0],mGLSurfaceViewWeakRef.get().mHolder, null);
int[] attrs = {0x3098, 2, EGL10.EGL_NONE};//0x3098 = EGL_CONTEXT_CLIENT_VERSION
mEglContext = this.mEgl.eglCreateContext(mEglDisplay, configs[0], EGL10.EGL_NO_CONTEXT, attrs);
mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext);
//渲染
mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);
//销毁
if (mEglSurface != EGL10.EGL_NO_SURFACE) {
mEgl.eglMakeCurrent(mEglDisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
mEglSurface = EGL10.EGL_NO_SURFACE;
}
if (mEglContext != EGL10.EGL_NO_CONTEXT) {
mEgl.eglDestroyContext(mEglDisplay, mEglContext);
mEglContext = EGL10.EGL_NO_CONTEXT;
}
if (mEglDisplay != EGL10.EGL_NO_DISPLAY) {
mEgl.eglTerminate(mEglDisplay);
mEglDisplay = EGL10.EGL_NO_DISPLAY;
}
egl14
private EGLSurface eglSurface = EGL14.EGL_NO_SURFACE;
private EGLContext eglCtx = EGL14.EGL_NO_CONTEXT;
private EGLDisplay eglDis = EGL14.EGL_NO_DISPLAY;
初始化
eglDis = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
int[] version = new int[2];
EGL14.eglInitialize(eglDis, version, 0, version, 1);
int confAttr[] = {
EGL14.EGL_RED_SIZE, 8,
EGL14.EGL_GREEN_SIZE, 8,
EGL14.EGL_BLUE_SIZE, 8,
EGL14.EGL_SURFACE_TYPE,
EGL14.EGL_WINDOW_BIT,
EGL14.EGL_NONE
};
EGLConfig[] configs = new EGLConfig[1];
int[] numConfigs = new int[1];
EGL14.eglChooseConfig(eglDis, confAttr, 0, configs, 0, 1, numConfigs, 0);
int ctxAttr[] = { EGL14.EGL_CONTEXT_CLIENT_VERSION,
2,// 0x3098
EGL14.EGL_NONE
};
eglCtx = EGL14.eglCreateContext(eglDis, configs[0], EGL14.EGL_NO_CONTEXT, ctxAttr, 0);
int[] surfaceAttr = { EGL14.EGL_NONE };
eglSurface = EGL14.eglCreateWindowSurface(eglDis, configs[0], surface, surfaceAttr, 0);
EGL14.eglMakeCurrent(eglDis, eglSurface, eglSurface, eglCtx);
渲染
EGL14.eglSwapBuffers(eglDis, eglSurface);
销毁
if (eglSurface != EGL14.EGL_NO_SURFACE) {
EGL14.eglMakeCurrent(eglDis, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT);
EGL14.eglDestroySurface(eglDis, eglSurface);
eglSurface = EGL14.EGL_NO_SURFACE;
}
if (eglCtx != EGL14.EGL_NO_CONTEXT) {
EGL14.eglDestroyContext(eglDis, eglCtx);
eglCtx = EGL14.EGL_NO_CONTEXT;
}
if (eglDis != EGL14.EGL_NO_DISPLAY) {
EGL14.eglTerminate(eglDis);
eglDis = EGL14.EGL_NO_DISPLAY;
}