opengl和directx哪个配置要求低(OpenGL ES EGL 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本文由博客 - 猿说编程 猿说编程 发布!
创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!