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 integer | int | EGLint |
32-bit unsigned integer | unsigned int | EGLBoolean, EGLenum |
32-bit pointer | void * | EGLConfig, EGLContext, EGLDisplay, EGLSurface, EGLClientBuffer |
2. OpengGL ES命令后綴和參數數據類型
Data Type Suffix | Data Type | C-Language Type | GL Type |
b | 8-bit signed integer | signed char | GLbyte |
ub | 8-bit unsigned integer | unsigned char | GLubyte, GLboolean |
s | 16-bit signed integer | short | GLshort |
us | 16-bit unsigned integer | unsigned short | GLushort |
i | 32-bit signed integer | int | GLint |
ui | 32-bit unsigned integer | unsigned int | GLuint, GLbitfield, GLenum |
x | 16.16 fixed point | int | GLfixed |
f | 32-bit floating point | float | GLfloat, GLclampf |
GLvoid是OpenGL ES命令可接受的指針。
2.1 OpenGL ES基本錯誤碼
錯誤碼可通過GLenum glGetError(void)函數獲取。假設當前錯誤碼的值不為GL_NO_ERROR。則新產生的錯誤碼不能被保存。
Error Code | Description |
GL_NO_ERROR | No error has been generated since the last call to glGetError. |
GL_INVALID_ENUM | A GLenum argument is out of range. The command that generated the error is ignored. |
GL_INVALID_VALUE | A numeric argument is out of range. The command that generated the error is ignored. |
GL_INVALID_OPERATION | The specific command cannot be performed in the current OpenGL ES state. The command that generated the error is ignored. |
GL_OUT_OF_MEMORY | There 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(client-server)模式。應用程序(client)公布命令,則Server負責運行處理。且不是應用程序每發一個命令都被及時地發送給Server。在設備中CPU負責運行游戲的邏輯。並向GPU(硬件顯卡或是軟件模擬的顯卡)發送繪圖指令。在這樣的架構下,CPU和GPU分別充當client與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))來進行查詢。