南飓风 发表于 2022-10-30 09:59:06

OpenGL ES EGL eglCreateWindowSurface


[*]一. 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 之间的连接
https://img2022.cnblogs.com/other/641604/202210/641604-20221030093848104-1230669221.png
三.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
本文由博客 - 猿说编程 猿说编程 发布!

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页: [1]
查看完整版本: OpenGL ES EGL eglCreateWindowSurface