您的位置:首页 > 编程语言

OpenGL ES2.0 基本编程

2013-01-28 10:12 246 查看
1. EGL

OpenGL ES命令需要一个rendering context和一个drawing surface。

Rendering Context: 保存当前的OpenGL ES状态。

Drawing Surface: 是原语(primitive)画图的Surface。它指定了渲染的buffer类型,如:color buffer,depth buffer和stencil buffer;同时它也指定了每个需要的buffer的位深度(bit depth)。

EGL是OpenGL ES API与Native Window System之间的接口。在OpenGL ES执行render之间,需要EGL做以下工作:

• 查询设备上可得到的显示设备,并初始化它们。

• 创建一个Rendering Surface(渲染表面)。EGL可以创建屏幕上的表面(on-srceen surface)或离off-screen surface,屏幕上的表面连接到本地窗口系统;而离屏表面不显示,但可以用于渲染表面(rendering
surface)的像素缓冲区。

• 创建一个rendering context(渲染环境)。在真正开始画图之前,需要把渲染环境连接到渲染表面。

1.1 EGL 数据类型

Data Type
C-Language Type
EGL Type
32-bit integerintEGLint
32-bit unsigned integerunsigned intEGLBoolean, EGLenum
32-bit pointervoid *EGLConfig, EGLContext,

EGLDisplay, EGLSurface,

EGLClientBuffer
2. OpengGL ES命令后缀和参数数据类型

Data Type SuffixData TypeC-Language TypeGL Type
b8-bit signed integersigned charGLbyte
ub8-bit unsigned integerunsigned charGLubyte,

GLboolean
s16-bit signed integershortGLshort
us16-bit unsigned integerunsigned shortGLushort
i32-bit signed integerintGLint
ui32-bit unsigned integerunsigned intGLuint,

GLbitfield,

GLenum
x16.16 fixed pointintGLfixed
f32-bit floating pointfloatGLfloat,

GLclampf
GLvoid是OpenGL ES命令可接受的批针。

2.1 OpenGL ES基本错误码

错误码可通过GLenum glGetError(void)函数获取,如果当前错误码的值不为GL_NO_ERROR,则新产生的错误码不能被保存。

Error CodeDescription
GL_NO_ERRORNo error has been generated since the last call to glGetError.
GL_INVALID_ENUMA GLenum argument is out of range. The command that generated the error is ignored.
GL_INVALID_VALUEA numeric argument is out of range. The command that generated the error is ignored.
GL_INVALID_OPERATIONThe specific command cannot be performed in the current OpenGL ES state. The command that generated the error is ignored.
GL_OUT_OF_MEMORYThere is insufficient memory to execute this command. The state of the OpenGL ES pipeline is considered to be undefined if this error is encountered
except for the current error code.
3. Flush和Finish

OpenGL ES2.0 API继承了OpenGL的C-S(客户端-服务器)模式。应用程序(客户端)发布命令,则Server负责执行处理。且不是应用程序每发一个命令都被及时地发送给Server。glFlush命令把当前OpenGL ES环境中的命令进行刷新,然后发送给Server。glFlush只是把命令发送给Server,但并不等待执行完成。如果需要等到Server执行完成时才返回,则需要调用glFinish,但它严重影响性能。

eglSwapBuffers中调用了glFlush。

4. 基本的状态管理

管道的每个阶段都有自己的一些状态,且每个状态有对应的值,这些状态值可以通过以下两个函数进行修改:

void glEnable(GLenum cap)

void glDisable(GLenum cap)

在初始状态时,除GL_DITHER(初始值为GL_TRUE)之外,其它每个状态的初始值都为GL_FALSE。这些状态值被保存在EGLcontext中。其状态值可通过glIsEnabled(GLboolean glIsEnabled(GLenum cap))来进行查询。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: