What Is Egl and How to Use It

Please explain to me what exactly is EGL in Android?

The OpenGL, or OpenGL ES - is everything about rendering within some environment. It doesn't know or care about what exactly that environment is. As long as it provides required list of compliant functions that can be called to achieve desired result - that's OpenGL for you.

Now how do you create that environment? Since it's not OpenGL's responsibility, it has to be done by someone else, and it has to be done in a way that is compliant with rules of the system that hosts the rendering application.

That's where the EGL place is - it defines an API that gets translated to underlying windowing system calls by some library. Like GLX and WGL is responsible for creation of OpenGL context on Linux and Windows, EGL is responsible for creation of OpenGL ES context in embedded systems. Android is not the only platform that's using EGL, pretty much all the Linux-capable single-SoC ARM computers will expose EGL API, so apps would be able to create a valid rendering context.

If you never used EGL api - then it means you never wrote the native applications for Android, or some other java class (like GLSurfaceView) is wrapping up things for you. Look at the basic GLES examples, you'll find lots of references to EGL stuff. At the minimum you'd be asked to provide the EGLConfigChooser, or at least give some parameters to implicitly created EGLConfigChoser.

EGL guide for beginners

To begin learning EGL, I recommend the following resources.

  • The OpenGL ES 3.0 Programming Guide from Addison-Wesley provides a good tutorial on using EGL with OpenGL ES, complete with example code on Github. The book's text provides an introduction to the parts of EGL that are independent of operating system. To cover the operating system specific parts, the book's example code provides a complete program that works on each major operating system. (Addison-Wesley is the publisher of many well-known OpenGL books, such as The Red Book and the OpenGL SuperBible).

    Dan Ginsburg, Budirijanto Purnomo, Dave Shreiner, Aaftab Munshi. OpenGL ES 3.0 Programming Guide, 2e, Chapter 3: An Introduction to EGL. Addison-Wesley, 2014. ISBN-13: 978-0-321-93388-1, ISBN-13: 978-0-13-344016-4.

  • As you're learning, keep by your side the official EGL 1.4 Quick Reference Card.

  • (Linux only) The example code in the EGL_EXT_platform_x11 extension specification demonstrates how to create an X11 window and produce an EGLSurface from that window. (The example programs from the OpenGL ES 3.0 Programming Guide also demonstrates how to do this, but you may find the more focused treatment in the EGL_EXT_platform_x11 specification easier to follow).

  • (Linux only) Likewise, the EGL_MESA_platform_gbm extension specification demonstrates how to do the same, but for GBM, a headless EGL backend supported by opensource Linux drivers.(The OpenGL ES 3.0 Programming Guide does not touch GBM).

Depending on your goals, you may also find useful the following low-level resources, all found in the Khronos EGL Registry.

  • EGL 1.4 Specification
  • EGL man pages
  • EGL Extension Registry
  • EGL XML API Registry

EGL_KHR_IMAGE - what is it and when should I use it

So a year later, I have become more of an expert in Android graphics and actually wrote a white paper about EGL Images. If my company lets me publish the paper externally, I'll post it here. For the time being, here is a short answer.

An EGL Image is simply a texture whose content can be updated without having to re-upload to VRAM (meaning no call to glTexImage2D). One of the only drawbacks, besides increased code complexity, is that the application developer has to handle synchronization themselves. In apps that I've written, I had to implement my own "internal" swapchain of EGL Images and manage all the locking primitives myself. Thus, a call to eglSwapBuffers swaps front and back framebuffers as usual, but in a seperate thread there are 2 EGL Images swapping front-to-back as new content becomes available.

What is the relationship between EGL and OpenGL?

There is no relationship between OpenGL and EGL. EGL generally does not run on desktops, and there is no ability to create a desktop OpenGL context through EGL.

OpenGL contexts are instead created and managed by platform-specific APIs. On Windows, the WGL API is used. On X11-based platforms, GLX is used. And so forth.

There was some noise last year from Khronos about creating a version of EGL that could work on the desktop and make OpenGL contexts, but thus far, nothing came of it.

Confusion between OPEN GL ES and EGL library

EGL is the interface between OpenGL ES and the underlying native display platform. It is used to create & manage rendering surfaces & graphics contexts.

What are EGL pixmaps good for?

EGL pixmaps are meant to mirror any pixmap-like concept supported by the underlying windowing system. The terminology comes from X11. The EGL spec says:

EGL defines several types of drawing surfaces collectively referred to as
EGLSurfaces. These include windows, used for onscreen rendering; pbuffers,
used for offscreen rendering; and pixmaps, used for offscreen rendering into buffers
that may be accessed through native APIs. EGL windows and pixmaps are tied to
native window system windows and pixmaps.

The main differences between pixmaps and windows are:

  • An EGL implementation doesn't need to support pixmaps (the native windowing system might not have an equivalent concept)
  • Pixmaps are typically single-buffered, whereas a window might be double- or triple-buffered.
  • Pixmaps are offscreen surfaces (although offscreen windows might be possible as well)

If the underlying windowing system doesn't support pixmaps, there's no real use for EGL pixmaps (and they probably won't be exposed by the EGL implementation). They're only provided so you can render to X11 pixmaps (or something similar) in case you need to do that for some reason.

One example might be: you want to render a 3D object using the GPU and then use it as an X11 cursor. In that case you might create a pixmap, create an EGL pixmap drawable, draw something, and then use XCreateCursorFromPixmap to turn your pixmap into a cursor (this is an example of the kind of "native API" the EGL spec is referring to). Examples more useful than this probably exist.

OpenGL-ES 2.0 and egl* functions (iOS)

EGL is a separate spec from OpenGL ES, it can manage contexts for OpenGL ES 1.0/1.1 and OpenGL ES 2.0 (and algo OpenVG), so it's not really gone.

The latest spec is here.



Related Topics



Leave a reply



Submit