博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Android OpenGL ES】阅读hello-gl2代码(三)配置EGL
阅读量:6084 次
发布时间:2019-06-20

本文共 3577 字,大约阅读时间需要 11 分钟。

关于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.

官网:

 

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:

首先,获得调用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:

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。

 

 

转载于:https://www.cnblogs.com/dyingbleed/archive/2012/11/05/2755529.html

你可能感兴趣的文章
java基础学习(目录)
查看>>
Effective Objective-C 2.0 随笔
查看>>
50KM徒步体验
查看>>
子元素固定宽度 父元素宽度被撑开
查看>>
【在线直播】机器学习中的建模问题
查看>>
SequoiaDB巨杉数据库携手民生银行分布式数据管理平台
查看>>
每日两道前端面试题20190221
查看>>
IOS评论框不贴底(ios12新bug)
查看>>
分数的表示以及计算(c++)
查看>>
【技术性】Software engineering知识
查看>>
Python爬虫笔记3-解析库Xpath的使用
查看>>
敏捷 - #3 原则:经常提供工作软件 ( #3 Agile - Principle)
查看>>
222. Count Complete Tree Nodes
查看>>
Nervos CKB 共识协议 NC-Max:突破 Nakamoto Consensus 吞吐量的极限
查看>>
一行js代码识别Selenium+Webdriver及其应对方案
查看>>
ubuntu 设置root用户密码并实现root用户登录
查看>>
UITableView性能优化 - 中级篇
查看>>
前端常用网站及论坛集锦
查看>>
Element组件引发的Vue中mixins使用,写出高复用组件
查看>>
JavaScript闯关笔记
查看>>