OpenGL ES EGL eglGetError

目錄

零基礎 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 – 渲染區域,系統窗口或 frame buffer 句柄 ,可以理解爲一個後端的渲染目標窗口

EGLConfig – 對 EGLSurface 的 EGL 配置,可以理解爲繪製目標 framebuffer 的配置屬性

EGLContextOpenGL ES 圖形上下文

二. EGL 繪製流程簡介

  1. 獲取 EGL Display 對象:eglGetDisplay
  2. 初始化與 EGLDisplay 之間的連接:eglInitialize
  3. 獲取 EGLConfig 對象:eglChooseConfig / eglGetConfigs
  4. 創建 EGLContext 實例:eglCreateContext
  5. 創建 EGLSurface 實例:eglCreateWindowSurface
  6. 連接 EGLContext 和 EGLSurface:eglMakeCurrent
  7. 使用 OpenGL ES API 繪製圖形:gl_*
  8. 切換 front buffer 和 back buffer 顯示:eglSwapBuffer
  9. 斷開並釋放與 EGLSurface 關聯的 EGLContext 對象:eglRelease
  10. 刪除 EGLSurface 對象
  11. 刪除 EGLContext 對象
  12. 終止與 EGLDisplay 之間的連接

三.eglGetError 函數簡介

EGL 中大部分函數成功時都是返回 EGL_TRUE,失敗返回 EGL_FALSE。至於其他錯誤原因,需要調用 eglGetError 函數獲取:

// 描述:返回 EGL 錯誤號,如果返回 EGL_SUCCESS 說明沒有錯誤
EGLint eglGetError();

四.eglGetError 函數使用

調用 eglGetError 如果返回 EGL_SUCCESS 說明沒有錯誤,返回其他值表示有錯誤產生;例如 :eglInitialize 會初始化 EGL 內部數據,分配顯存等初始化失敗

/******************************************************************************************/
//@Author:猿說編程
//@Blog(個人博客地址): www.codersrc.com
//@File:OpenGL ES EGL eglGetError
//@Time:2022/08/04 07:30
//@Motto:不積跬步無以至千里,不積小流無以成江海,程序人生的精彩需要堅持不懈地積累!
/******************************************************************************************/

EGLint attrs[3] = { EGL_DEPTH_SIZE, 16, EGL_NONE };
EGLint num_configs;
EGLConfigs *configs_list;
// Get the display device
if ((eglDisplay = eglGetDisplay(EGL_NO_DISPLAY)) == EGL_NO_DISPLAY) {
	return eglGetError();
}
// Initialize the display
if (eglInitialize(eglDisplay, NULL, NULL) == EGL_FALSE) {
	return eglGetError();
}
// Obtain the total number of configurations that match
if (eglChooseConfig(eglDisplay, attrs, NULL, 0, &num_configs) == EGL_FALSE) {
	return eglGetError();
}
configs_list = malloc(num_configs * sizeof(EGLConfig));
if (configs_list == (EGLConfig *)0){
	return eglGetError();
}
// Obtain the first configuration with a depth buffer of 16 bits
if (!eglChooseConfig(eglDisplay, attrs, &configs_list, num_configs, &num_configs)) {
	return eglGetError();
}

五.猜你喜歡

  1. OpenGL ES 簡介
  2. OpenGL ES 版本介紹
  3. OpenGL ES 2.0 和 3.0 區別
  4. OpenGL ES 名詞解釋(一)
  5. OpenGL ES 名詞解釋(二)
  6. OpenGL ES GLSL 着色器使用過程
  7. OpenGL ES EGL 簡介
  8. OpenGL ES EGL 名詞解釋
  9. OpenGL ES EGL eglGetDisplay
  10. OpenGL ES EGL eglInitialize
  11. OpenGL ES EGL eglGetConfigs
  12. OpenGL ES EGL eglChooseConfig
  13. OpenGL ES EGL eglGetError

本文由博客 - 猿說編程 猿說編程 發佈!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章