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(用戶端-伺服器)模式。應用程式(用戶端)發布命令,則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))來進行查詢。