- 一. EGL 前言
- 二. EGL 繪制流程簡介
- 三.eglCreateWindowSurface 函式簡介
- 1.eglCreateWindowSurface 函式
- 2.EGLSurface 分類
- 四.eglCreateWindowSurface 函式使用
- 五.猜你喜歡
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES 基礎
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES 特效
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES 轉場
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES 函式
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES GPUImage 使用
零基礎 OpenGL ES 學習路線推薦 : OpenGL ES 學習目錄 >> OpenGL ES GLSL 編程
一. EGL 前言
EGLNativeDisplayType – 系統顯示型別,標識你所開發設備的物理螢屏,DX/OPenGL ES/Metal/Vulkan….
EGLNativeWindowType – 系統視窗,渲染顯示的視窗句柄
EGLDisplay – 關聯 EGLNativeDisplayType 系統物理螢屏的通用資料型別,是平臺上 WGL / GLX / AGL 的等價物
EGLSurface – 渲染區域,相當于 OpenGL ES 繪圖的畫布 (一塊記憶體空間),用戶想繪制的資訊首先都要先繪制到 EGLSurface 上,然后通過 EGLDisplay 顯示
EGLConfig – 對 EGLSurface 的 EGL 配置,可以理解為繪制目標 framebuffer 的配置屬性
EGLContext – OpenGL ES 圖形背景關系
二. EGL 繪制流程簡介
- 獲取 EGL Display 物件:eglGetDisplay
- 初始化與 EGLDisplay 之間的連接:eglInitialize
- 獲取 EGLConfig 物件:eglChooseConfig / eglGetConfigs
- 創建 EGLContext 實體:eglCreateContext
- 創建 EGLSurface 實體:eglCreateWindowSurface / eglCreatePbufferSurface
- 連接 EGLContext 和 EGLSurface:eglMakeCurrent
- 使用 OpenGL ES API 繪制圖形:gl_*
- 切換 front buffer 和 back buffer 顯示:eglSwapBuffer
- 斷開并釋放與 EGLSurface 關聯的 EGLContext 物件:eglRelease
- 洗掉 EGLSurface 物件
- 洗掉 EGLContext 物件
- 終止與 EGLDisplay 之間的連接

三.eglCreateWindowSurface 函式簡介
EGLSurface 也稱為 渲染區域,相當于 OpenGL ES 繪圖的畫布 (一塊記憶體空間),用戶想繪制的資訊首先都要先繪制到 EGLSurface 上,然后通過 EGLDisplay 顯示;
1.eglCreateWindowSurface 函式
創建 EGLSurface 需要 EGLConfig,函式宣告如下:
/*描述:創建 OpenGL ES EGLSurface
*引數:
* display:指定顯示的連接
* config:配置 EGLConfig
* native_window:原生視窗
* attribList:指定操作的屬性串列
*
*回傳值:成功時回傳新創建的 EGLSurface,失敗時回傳EGL_NO_SURFACE.
*/
EGLSurface eglCreateWindowSurface(
EGLDisplay display,
EGLConfig config,
NativeWindowType native_window,
EGLint const * attrib_list);
如果創建 EGLSurface 失敗,可以通過 eglGetError 獲取錯誤型別,可能產生錯誤號:
EGL_BAD_DISPLAY: 連接不是一個EGL display連接
EGL_NOT_INITIALIZED: EGL沒有初始化
EGL_BAD_CONFIG: EGL frame buffer配置無效
EGL_BAD_NATIVE_WINDOW: native window不是與display相同平臺的有效Native Window
EGL_BAD_ATTRIBUTE: attrib_list包含無效引數,或者引數未被識別,或者引數越界
EGL_BAD_ALLOC:已經有一個與native window關聯的Surface,或者無法為新的EGL視窗分配資源,
EGL_BAD_MATCH:本機視窗的像素格式與配置所需的顏色緩沖區的格式、型別和大小不一致
2.EGLSurface 分類
在文章 《OpenGL ES EGL 名詞解釋》有詳細介紹, EGLSurface 一共分為三類:
1.Surface – 可顯示的 Surface,實際上就是一個 FrameBuffer,用于系結視窗后預覽顯示,通過 eglCreateWindowSurface 創建;
2.PixmapSurface – 不是可顯示的 Surface,保存在系統記憶體中的位圖;
3.PBufferSurface – 不是可顯示的 Surface,保存在顯存中的幀,用于離屏渲染,不需要系結視窗,通過 eglCreatePbufferSurface 創建
四.eglCreateWindowSurface 函式使用
/******************************************************************************************/
//@Author:猿說編程
//@Blog(個人博客地址): www.codersrc.com
//@File:OpenGL ES EGL eglCreateWindowSurface
//@Time:2022/08/04 07:30
//@Motto:不積跬步無以至千里,不積小流無以成江海,程式人生的精彩需要堅持不懈地積累!
/******************************************************************************************/
EGLBoolean initializeWindow(EGLNativeWindow nativeWindow)
{
const EGLint configAttribs[] = {EGL_RENDER_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_DEPTH_SIZE, 24,
EGL_NONE};
const EGLint contextAttribs[] = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL_NONE};
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY)
if (display == EGL_NO_DISPLAY)
{
return EGL_FALSE;
}
EGLint major, minor;
if (!eglInitialize(display, &major, &minor))
{
return EGL_FALSE;
}
EGLConfig config;
EGLint numConfigs;
if (!eglChooseConfig(display, configAttribs, &config, 1, &numConfigs))
{
return EGL_FALSE;
}
EGLSurface window = eglCreateWindowSurface(display, config, nativeWindow, NULL);
if (window == EGL_NO_SURFACE)
{
return EGL_FALSE;
}
EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs);
if (context == EGL_NO_CONTEXT)
{
return EGL_FALSE;
}
if (!eglMakeCurrent(display, window, window, context))
{
return EGL_FALSE;
}
return EGL_TRUE;
}
五.猜你喜歡
- OpenGL ES 簡介
- OpenGL ES 版本介紹
- OpenGL ES 2.0 和 3.0 區別
- OpenGL ES 名詞解釋(一)
- OpenGL ES 名詞解釋(二)
- OpenGL ES GLSL 著色器使用程序
- OpenGL ES EGL 簡介
- OpenGL ES EGL 名詞解釋
- OpenGL ES EGL eglGetDisplay
- OpenGL ES EGL eglInitialize
- OpenGL ES EGL eglGetConfigs
- OpenGL ES EGL eglChooseConfig
- OpenGL ES EGL eglGetError
- OpenGL ES EGL eglCreateContext
- OpenGL ES EGL eglCreateWindowSurface
本文由博客 - 猿說編程 猿說編程 發布!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/523151.html
標籤:其他
