Opengl ES创建流程

在android 1.0rc2 sdk中,提供了以下包支持Opengl ES 编程:

一、openglES包

android.opengl
Class:
GLDebugHelper:用于调试OpenGL ES程序的帮助类
GLU:提供GL 公共工具功能的类
GLUtils:连接OpenGL ES和Android API的工具类,其中提供了纹理图片的操作。
Matrix:矩阵运算工具类
Exception:
GLException:OpenGL异常类
javax.microedition.khronos.egl
Interface:
EGL:GL的配置接口
EGL10:GL1.0的配置接口
EGL11:GL1.1的配置接口
Classes:
EGLConfig:GL配置的类
EGLContext:GL运行环境的类
EGLDisplay:GL显示窗口的类
EGLSurface:可渲染GL的视图类
javax.microedition.khronos.opengles
Interfaces:
GL:Opengles的接口
GL10:Opengles1.0的接口
GL10Ext:Opengles1.0的扩展接口
GL11:Opengles1.1的接口
GL11Ext:Opengles1.1的扩展接口
GLExtentsionPack:Opengles的扩展接口
EGLDisplay:GL显示窗口的类
EGLSurface:可渲染GL的视图类

二、通常创建流程:

a)创建一个EGL实例

EGL10 mEgl = (EGL10) EGLContext.getEGL();

b)创建一个EGLDisplay实例

EGLDisplay mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

c)初始化EGLDisplay

mEgl.eglInitialize(mEglDisplay, version);

d)选择Config

mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, num_config);

EGLConfig mEglConfig = configs[0];

e)创建opengl运行环境

EGLContext mEglContext = mEgl.eglCreateContext(       mEglDisplay,

mEglConfig,

EGL10.EGL_NO_CONTEXT,

null);

 

f) 创建新surface

mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay,

mEglConfig, holder, null);

 

g) 将opengles环境设置为当前

mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,

mEglContext);

 

h) 获取当前opengles画布

GL gl = mEglContext.getGL();

 

i) 显示绘制结果到屏幕上

mEgl.eglSwapBuffers(mEglDisplay, mEglSurface);

 

三、示例Cube分析

这里简要分析下 google提供的示例代码APIDemos中的Cube的运行结构,具体代码就不详细列出了。

静态类关系图:

对象协作图:

首先,由GLSurfaceViewActivity的实例在onCreate函数中,创建一个GLSurfaceView实例用于显示绘制OpenglES;

其次,创建一个CubeRenderer的实例,用于渲染Cube对象;

然后,使用GLSurfaceView的setRenderer方法,创建一个GLThread实例。CLThread实例创建一个EglHelper实例初始化opengle环境,并且在run函数中循环运行CubeRender的drawFrame方法;

最后,使用setContentView方法,将GLSurfaceView的实例添加到显示窗口。

特别需要注意多线程同步问题,由于绘制是由绘制线程处理的,所以当主进程在调用surfaceCreated,surfaceDestroyed,onPause,onResume,onWindowFocusChanged,

onWindowResize,requestExitAndWait,queueEvent,getEvent时,

都会访问绘制线程,所以这些方法需要使用同步关键字synchronized锁定绘制线程,主线程必需要等待绘制线程执行完相应的方法后,在继续执行。

你可能感兴趣的:(多线程,exception,android,扩展,工具,Matrix)