EGL学习笔记

1、EGL的功能描述:

a (mostly) platform-independent API for managing drawing surfaces。


2、EGL提供的机制: 

communicating with the native windowing system of your system;

querying the available types and configurations of drawing surfaces;

creating drawing surfaces;

synchronizing rendering between OpenGL ES 2.0 and other graphics rendering APIs(like OpenVG, or the native drawing commands of your window system);

managing rendering resources such as texture maps;


3、EGL与Windowing System的通信

EGL provides a “glue” layer between OpenGL ES 2.0 (and other Khronos graphics
APIs) and the native windowing system running on your computer, like the
X Window System common on GNU/Linux systems, Microsoft Windows, or
Mac OS X’s Quartz. 

EGL为OpenGL ES 2.0与native windowing system之间的通信提供了一个glue(glue:胶,粘合)层。


Before EGL can determine what types of drawing surfaces,
or any other characteristics of the underlying system for that matter, it needs
to open a communications channel with the windowing system.

EGL在决定drawing surfaces的类型,或者获取相关的底层系统的特性之前,需要先与windowing system建立通信通道。


Because every windowing system has different semantics, EGL provides a
basic opaque type—the EGLDisplay—that encapsulates all of the system
dependencies for interfacing with the native windowing system. The first
operation that any application using EGL will need to do is create and initialize
a connection with the local EGL display. 

EGL提供了一个类型:EGLDisplay,它封装了所有与native windowing system交互时需要的系统属性,应用程序使用EGL时要做的第一个操作就是创建并初始化与local EGL display的连接。


  1. <span style=“font-family:’Times New Roman’;font-size:18px;”>EGLint majorVersion;  
  2. EGLint minorVersion;  
  3. EGLDisplay display;  
  4. display = eglGetDisplay(EGL_DEFAULT_DISPLAY);  
  5. if(display == EGL_NO_DISPLAY)  
  6. {  
  7. // Unable to open connection to local windowing system  
  8. }  
  9. if(!eglInitialize(display, &majorVersion, &minorVersion))  
  10. {  
  11. // Unable to initialize EGL. Handle and recover  
  12. }</span>  
EGLint majorVersion; 
EGLint minorVersion;
EGLDisplay display;
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
if(display == EGL_NO_DISPLAY)
{
// Unable to open connection to local windowing system
}
if(!eglInitialize(display, &majorVersion, &minorVersion))
{
// Unable to initialize EGL. Handle and recover
}
调用eglGetDisplay函数,打开与EGL display server之间的连接:

  1. <span style=“font-family:’Times New Roman’;font-size:18px;”>EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id);</span>  
EGLDisplay eglGetDisplay(EGLNativeDisplayType display_id);

EGLNativeDisplayType is defined to match the native window system’s display
type. On Microsoft Windows, for example, an EGLNativeDisplayType
would be defined to be an HDC—a handle to the Microsoft Windows device
context. However, to make it easy to move your code to different operating
systems and platforms, the token EGL_DEFAULT_DISPLAY is accepted and will
return a connection to the default native display, as we did

EGLNativeDisplayType屏蔽了不同平台类型之间的差异。为了保持代码在不同操作系统平台上的可移植性,使用EGL_DEFAULT_DISPLAY,系统会返回与默认native display之间的连接。


4、初始化EGL

成功的打开连接后,就需要初始化EGL,调用eglInitialize函数完成:

  1. <span style=“font-family:’Times New Roman’;font-size:18px;”>EGLBoolean eglInitialize(EGLDisplay display, EGLint *majorVersion,  
  2. EGLint *minorVersion);</span>  
EGLBoolean eglInitialize(EGLDisplay display, EGLint *majorVersion, 
EGLint *minorVersion);
eglInitialize函数初始化EGL的内部数据结构,返回EGL实现的主版本号和次版本号。如果EGL初始化失败,就会返回EGL_FALSE。


5、Determining the Available Surface Configurations

Once we’ve initialized EGL, we’re able to determine what types and configurations
of rendering surfaces are available to us. There are two ways to go
about this:
Query every surface configuration and find the best choice ourselves.
Specify a set of requirements and let EGL make a recommendation for the
best match.

EGL初始化完成后,获取我们可以使用的rendering surfaces的类型和配置。


6、Querying EGLConfig Attributes

An EGLConfig contains all of the information about a surface made available
by EGL. This includes information about the number of available colors,
additional buffers associated with the configuration (like depth and
stencil buffers, which we discuss later), the type of surfaces, and numerous
other characteristics.


7、Letting EGL Choose the Config


8、Creating an On-Screen Rendering Area: The EGL Window

Once we have a suitable EGLConfig that meets our requirements for rendering,
we’re set to create our window. To create a window, call

EGLSurface eglCreateWindowSurface(EGLDisplay display, EGLConfig config, EGLNatvieWindowType window, const EGLint *attribList);

创建窗口。


9、Creating an Off-Screen Rendering Area: EGL Pbuffers

10、Creating a Rendering Context

A rendering context is a data structure internal to OpenGL ES 2.0 that contains
all of the state required for operation. For example, it contains references
to the vertex and fragment shaders and the array of vertex data. 

Before OpenGL ES 2.0 can draw it
needs to have a context available for its use.

创建Rendering Context,Rendering Context是一个OpenGL ES 2.0内部的数据结构,包含了操作需要的全部状态。

创建Rendering Context的方法:

EGLContext eglCreateContext(EGLDisplay display, EGLConfig config,
EGLContext shareContext,
const EGLint* attribList);

When eglCreateContext succeeds, it returns a handle to the newly created
context. If a context is not able to be created, then eglCreateContext
returns EGL_NO_CONTEXT, and the reason for the failure is set, and can be
obtained by calling eglGetError.


11、Making an EGLContext Current

As an application might have created multiple EGLContexts for various purposes,
we need a way to associate a particular EGLContext with our rendering
surface—a process commonly called “make current.”

应用程序可能会创建多个EGL Context,我们需要为rendering surface指定其中的一个。

猜你喜欢

转载自blog.csdn.net/baidu_37503452/article/details/80798653