随笔 - 65  文章 - 0  评论 - 21  阅读 - 32万

【Android OpenGL ES】阅读hello-gl2代码(三)配置EGL

关于EGL的介绍:

EGL is an interface between Khronos rendering APIs such as OpenGL ES or OpenVG and the underlying native platform window system. It handles graphics context management, surface/buffer binding, and rendering synchronization and enables high-performance, accelerated, mixed-mode 2D and 3D rendering using other Khronos APIs. EGL also provides interop capability between Khronos to enable efficient transfer of data between APIs – for example between a video subsystem running OpenMAX AL and a GPU running OpenGL ES.

EGL can be implemented on multiple operating systems (such as Android and Linux) and native window systems (such as X and Microsoft Windows). Implementations may also choose to allow rendering into specific types of EGL surfaces via other supported native rendering APIs, such as Xlib or GDI. EGL provides:

  • Mechanisms for creating rendering surfaces (windows, pbuffers, pixmaps) onto which client APIs can draw and share
  • Methods to create and manage graphics contexts for client APIs
  • Ways to synchronize drawing by client APIs as well as native platform rendering APIs.

官网:http://www.khronos.org/egl

 

ConfigChooser

定义配置信息的属性列表:

复制代码
private static int EGL_OPENGL_ES2_BIT = 4;
private static int[] s_configAttribs2 =
{
    EGL10.EGL_RED_SIZE, 4,
    EGL10.EGL_GREEN_SIZE, 4,
    EGL10.EGL_BLUE_SIZE, 4,
    EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
    EGL10.EGL_NONE
};
复制代码

配置EGL_RED_SIZE、EGL_GREEN_SIZE、EGL_BLUE_SIZE和EGL_RENDERABLE_TYPE。

EGL的属性列表:

 

复制代码
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {

    /* Get the number of minimally matching EGL configurations
     */
    int[] num_config = new int[1];
    egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);

    int numConfigs = num_config[0];

    if (numConfigs <= 0) {
        throw new IllegalArgumentException("No configs match configSpec");
    }

    /* Allocate then read the array of minimally matching EGL configs
     */
    EGLConfig[] configs = new EGLConfig[numConfigs];
    egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);

    if (DEBUG) {
         printConfigs(egl, display, configs);
    }
    /* Now return the "best" one
     */
    return chooseConfig(egl, display, configs);
}
复制代码

GLSurfaceView.EGLConfigChooser:http://developer.android.com/reference/android/opengl/GLSurfaceView.EGLConfigChooser.html

首先,获得调用egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config);,获得配置信息的数量;

然后,调用egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config);,获得配置信息EGLConfig数组;

最后,调用私有方法chooseConfig(egl, display, configs);,取得最合适的配置信息EGLConfig。

EGL配置管理如下图:

 

ContextFactory

在EGL2JNIView.java文件中,私有内部类ConfigChooser定义如下:

复制代码
private static class ContextFactory implements GLSurfaceView.EGLContextFactory {
    private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) {
        Log.w(TAG, "creating OpenGL ES 2.0 context");
        checkEglError("Before eglCreateContext", egl);
        int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
        EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
        checkEglError("After eglCreateContext", egl);
        return context;
    }

    public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) {
        egl.eglDestroyContext(display, context);
    }
}
复制代码

GLSurfaceView.EGLContextFactory:http://developer.android.com/reference/android/opengl/GLSurfaceView.EGLContextFactory.html

int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);

创建OpenGL ES 2.0版本的EGLContext。

 

 

posted on   Anthony Li  阅读(4079)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
< 2012年11月 >
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 1
2 3 4 5 6 7 8

博客园博客已停止更新,博客地址:dyinigbleed.com

点击右上角即可分享
微信分享提示