28

I'm writing an implementation for OpenVG and OpenGL|ES in Go, both of which depend on the Khronos EGL API, supposedly to ease portability I guess.

I'm writing an implementation of OpenVG on top of OpenGL ES for fun and educational reasons - I haven't done a lot of rendering work and I'd like to learn more about the open APIs and practice implementing well defined standards (easier to see if I got the right results).

As I understand it, EGL provides a standard API for retrieving a drawing context (or what ever it's rightly called,) instead of using one of the multiple OS provided APIs (GLX, WGL etc)

enter image description here

I have a hard time believing Khronos would go through such effort and leave the standard OpenGL out of the loop but the thing is, I haven't found how or if OpenGL (the real deal) interfaces with EGL or if it's only OpenGL ES. If OpenGL ES can use the drawing context from EGL, would standard OpenGL also work?

I'm really new to all of this which is why I'm excited but the real project I'm doing is a Go widget toolkit that utilizes OpenVG for its drawing operations and uses hardware acceleration wherever possible.

If OpenVG, OpenGL and OpenGL ES depend on EGL, I think my question can be answered with "yes" or "no". Just keep in mind that I dove into this subject head-first last night.

Does OpenGL use or depend on EGL?


Off topic, but there is no EGL tag. Should there be?

Marco A.
  • 43,032
  • 26
  • 132
  • 246
hannson
  • 4,465
  • 8
  • 38
  • 46

3 Answers3

16

You can bind EGL_OPENGL_API as the current API for your thread, via the eglBindAPI(EGLenum api); a subsequent eglCreateContext will create an OpenGL rendering context.

From the EGL spec, p42:

Some of the functions described in this section make use of the current rendering API, which is set on a per-thread basis by calling

EGLBoolean eglBindAPI(EGLenum api);

api must specify one of the supported client APIs , either EGL_OPENGL_API, EGL_OPENGL_ES_API, or EGL_OPENVG_API

The caveat is that the EGL implementation is well within its rights not support EGL_OPENGL_API and instead generate an EGL_BAD_PARAMETER error if you try to bind it.

It's also hard to link to libGL without picking up the AGL/WGL/GLX cruft; the ABI on these platforms require that libGL provides those entry points. Depending on what platform you're playing with this may or may not be a problem.

RAOF
  • 1,126
  • 9
  • 14
12

Does OpenGL use or depend on EGL?

No. You can run OpenGL without EGL.

But is possible to have EGL implementation capable to create desktop OpenGL context. That's because EGL's eglBindAPI(int api) allows EGL_OPENGL_API, EGL_OPENGL_ES_API, or EGL_OPENVG_API.

But if you ask:

Does OpenGL-ES use or depend on EGL?

The answer is yes, but there are exceptions.

Currently (2015), you have several implementations of OpenGL-ES that rely on EGL to create graphics context: Google ANGLE, PowerVR, ARM MALI, Adreno, AMD, Mesa, etc.

But on recent releases of NVIDIA and Intel drivers you can also request OpenGL-ES contexts directly, where extensions WGL_EXT_create_context_es_profile and WGL_EXT_create_context_es2_profile are available (Windows). Same thing on Unix platforms where GLX_EXT_create_context_es_profile and GLX_EXT_create_context_es2_profile extensions are available.

The intent of EGL is to ease developers' lives by creating a portable and standard way to initialize and get context of supported graphics API, without worrying about platform specific issues, as WGL, GLX, etc. That is a problem of EGL implementers, not final programmer.

Marco A.
  • 43,032
  • 26
  • 132
  • 246
Alex Byrth
  • 1,328
  • 18
  • 23
  • I installed NVIDIA's latest driver (version 364) on my Ubuntu 14.04, and I found there are libGL.so, libGLESv2.so, libEGL.so. Does that mean I can use EGL to create window context on my desktop and use it with OpenGL 4.5 on my Ubuntu desktop? – Robert Wang May 09 '16 at 09:12
  • 1
    Bind to libEGL.so and call EGL functions to query support to OpenGL. see http://stackoverflow.com/questions/23139886/how-to-create-opengl-context-via-drm-linux . Steps: (1) get display with eglGetDisplay(...) ; (2) eglInitialize(display,...); (3) eglChooseConfig(...) with attrib_list containing pairs { ... EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT EGL_CONFORMANT, EGL_OPENGL_BIT, ... }, (4) eglCreateContext(...) – Alex Byrth May 09 '16 at 15:08
  • BUT from EGL card, it says EGL supports only OpenGL 1.x and 2.x. I didn't try it yet. – Alex Byrth May 09 '16 at 15:13
  • Thanks for the info. One more question. I just don't understand why we need to used mesa driver (which was mentioned in that post)? What is lacking in the NV drivers? – Robert Wang May 10 '16 at 05:57
  • 1
    Revised comment ! If you already have a libEGL.so, you don't need to worry with mesa. Just bind to your EGL and be happy. – Alex Byrth May 10 '16 at 17:42
  • Thanks. I will give it a try when I get some time. – Robert Wang May 11 '16 at 09:30
6

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.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Thats a shame. Will have to work around that, but thanks for the reply. – hannson Aug 10 '11 at 21:01
  • AMD have included the EGL library in their OpenGL ES 2.0 SDK http://developer.amd.com/tools/graphics-development/amd-opengl-es-sdk/ It works on Windows with AMD (Radeon, ATI ) cards – Tim Child Jan 19 '13 at 03:16
  • Is this answer "no relationsship" still true today(2013). The wikipedia page on EGL [here] (http://en.wikipedia.org/wiki/EGL_%28OpenGL%29) for instance suggest some connection. Maybe you/somebody can update the question if necessary – humanityANDpeace Aug 30 '13 at 14:56
  • 2
    @humanityANDpeace: It's not clear to me from a cursory look at Mesa's website that you can use Mesa3D and EGL to create a *desktop* OpenGL context. Also, Wayland is not terribly widespread. So I don't see a need to change anything that's been said here at present. If Mir becomes widely adopted by Linux, then maybe. Or if NVIDIA is able to get lots of desktop OpenGL running, perhaps. But the at present, the statement "EGL *generally* does not run on desktops" remains true. – Nicol Bolas Aug 30 '13 at 22:54
  • 1
    I am impressded by your reply, thank you! Anyway I think my comment was meant to stimmulate rethinking about the relationship of EGL and OpenGL (which is the original question). I was and still am under the impression that there has been some development and today (aprox. 3 years) later there are lined out lots of cases where EGL is used on desktops for instance. Still being thankful I cannot understand why you bring up Mesa, Wayland and -most confusing- Ubuntu-MIR. – humanityANDpeace Sep 02 '13 at 06:21
  • 1
    @humanityANDpeace: "*I cannot understand why you bring up Mesa, Wayland and -most confusing- Ubuntu-MIR.*" Because those are pretty much the only providers of EGL for desktop OpenGL. Unless you know of some others I (and Wikipedia) am not aware of. – Nicol Bolas Sep 02 '13 at 06:32
  • 17
    @NicolBolas EGL on X11 has supported creation of desktop OpenGL contexts at least since 2011 (and maybe before) in Mesa. – Chadversary Apr 23 '14 at 02:15
  • 19
    The Wayland display server protocol uses EGL and this answer is now totally outdated. – Janus Troelsen Aug 08 '17 at 10:13
  • 1
    i'm using EGL/GLES3 on linux desktop through the nvidia driver right now lol – mchiasson Jun 12 '18 at 20:06
  • 5
    This answer is hopelessly outdated, could it please be updated or removed? – rdb May 20 '20 at 18:15
  • "EGL generally does not run on desktops" - Are you confusing OpenGL ES with EGL here? EGL is a framework that can be used for OpenGL ES but also for normal OpenGL. EGL is a platform neutral replacement to GLX on UNIX (X11), WGL (Windows), and CGL (macOS). EGL can run on any system that provides an implementation for it as it is independent of the system and the used (native) desktop system. It's the only supported framework of Wayland, BTW. – Mecki Nov 02 '21 at 00:59
  • @Mecki: What it *can* run on is not the point. The point was about whether actual implementations are *generally* available on desktops. They're not available at all on MacOS. Wayland may require it, but it is at best optional on other Linux platforms. And EGL is pretty much non-existent on Windows. It *could* run on all of these platforms, but it *doesn't*. – Nicol Bolas Nov 02 '21 at 01:02
  • 1
    @Mecki: It should also be noted that this was written in 2011. – Nicol Bolas Nov 02 '21 at 01:02