天天看點

Android EGL OpenGL庫說明和加載流程

OpenGL ES

什麼是OpenGL?

Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.

OpenGL是和程式設計語言、平台無關的一套interface ,主要是為了渲染 2D 和 3D圖形等。一般這套接口是用來和GPU進行互動的,使用GPU進行硬體加速。

什麼是OpenGL ES?

Android includes support for high performance 2D and 3D graphics with the Open Graphics Library (OpenGL®), specifically, the OpenGL ES API. OpenGL is a cross-platform graphics API that specifies a standard software interface for 3D graphics processing hardware. OpenGL ES is a flavor of the OpenGL specification intended for embedded devices.

OpenGL ES就是專為嵌入式裝置設計的,OpenGL ES和OpenGL中的函數接口有一些是不一樣,因為嵌入式裝置和pc等的硬體處理能力有差距的。

既然OpenGL ES隻是一組函數接口,Android平台提供了兩種類型的實作:軟體實作,硬體實作。

a.硬體實作,前面提到這組函數接口主要是為了和GPU這個硬體進行打交道的。是以各個硬體廠商會提供相關的實作,例如高通平台的adreno解決方案;

b.軟體實作,Android自身也提供了一套OpenGL ES的軟體實作,不使用GPU,完全用軟體實作畫圖的相關功能,也就是libagl

EGL

EGL - Native Platform Interface

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?EGL是OpenGL ES和底層的native window system之間的接口,承上啟下。

EGL is a complement to OpenGL ES. EGL is used for getting surfaces to render to using functions like eglCreateWindowSurface, and you can then draw to that surface with OpenGL ES. Its role is similar to GLX/WGL/CGL.

Whether or not EGL can give you a context that supports OpenGL ES 2.0 may vary by platform, but if the Android device supports ES 2.0 and EGL, you should be able to get such a context from EGL. Take a look at the EGL_RENDERABLE_TYPE attribute and the EGL_OPENGL_ES2_BIT when requesting an EGLConfig.

http://www.khronos.org/files/egl-1-4-quick-reference-card.pdf

在Android上,EGL完善了OpenGL ES。利用類似eglCreateWindowSurface的EGL函數可以建立surface 用來render ,有了這個surface就能往這個surface中利用OpenGL ES函數去畫圖。

下圖表示的是顯示相關的幾個子產品的關系,

其中FrameBufferNativeWindow已經過時。通過該圖可以看到EGL OpenGL所處的位置。

Android EGL OpenGL庫說明和加載流程

EGL OpenGL庫加載流程

簡化示意圖如下:

Android EGL OpenGL庫說明和加載流程

EGL OpenGL相關庫說明:

MTK:

so directory descrption
libEGL_mtk.so /vendor/lib/egl /vendor/lib64/egl egl的實作
libGLESv1_CM.so libGLESv2.so /vendor/lib/egl /vendor/lib64/egl opengl具體實作的wrapper
libGLES_android.so /system/lib/egl /system/lib64/egl opengl軟體實作,即agl
libGLESv1_CM_mtk.so libGLESv2_mtk.so /vendor/lib/egl /vendor/lib64/egl opengl硬體實作,即hgl

高通:

so directory descrption
egl.cfg /system/lib/egl 選擇圖形渲染方式(libagl/libhgl)
libEGL_adreno.so /vendor/lib/egl /vendor/lib64/egl egl的實作
libGLES_android.so /system/lib/egl /system/lib64/egl opengl軟體實作,即agl
libGLESv1_CM_adreno.so libGLESv2_adreno.so /vendor/lib/egl /vendor/lib64/egl opengl硬體實作,即hgl

本文參考文章: EGL和OpenGL ES之間的關系

另外強烈推薦兩篇講解agl的文章:

 http://blog.csdn.net/happy19850920/article/details/50673005

 http://blog.csdn.net/happy19850920/article/details/50773875