nigels-com / glew

The OpenGL Extension Wrangler Library
Other
2.58k stars 608 forks source link

Unclear how to use glew with EGL / Missing early no-EGLDisplay init #372

Open vvuk opened 1 year ago

vvuk commented 1 year ago

I'm not sure I see what the right path is to using GLEW with EGL. Can't call glewInit() at the start, because it wants to call glewContextInit but there's no GL context yet. eglewInit(dpy) can't be used, because you don't yet have a EGLDisplay. And eglGetDisplay can't be used to get one, because the __eglewGetDisplay pointer has not been initialized yet.

Seems like there's something like an eglewEarlyInit (or even eglewInit(EGL_NO_DISPLAY)) missing that initializes the function pointers for the functions that can be called even before EGL initialization, such as eglGetDisplay -- as well as extensions that can be used before init, such as EGL_EXT_device_enumeration and EGL_EXT_platform_base (in order to call eglQueryDevicesEXT + eglGetPlatformDisplayEXT).

A workaround that seems to be ok is to just manually init the specific functions you need:

    __eglewQueryDevicesEXT = (PFNEGLQUERYDEVICESEXTPROC) eglGetProcAddress("eglQueryDevicesEXT");
    __eglewGetPlatformDisplayEXT = (PFNEGLGETPLATFORMDISPLAYEXTPROC) eglGetProcAddress("eglGetPlatformDisplayEXT");

(or the same for __eglewGetDisplay), and then calling eglewInit(dpy) with the dpy that you're able to obtain. But it's a bit messy/magic to have to know that.

(Even more annoyingly, but not GLEW's fault... for some reason EGL_EXT_device_enumeration, device_query, etc. are missing from the EGL extensions string with nvidia's drivers on Linux, but eglGetProcAddress finds their entry points fine.)

nigels-com commented 1 year ago

I'm not hands-on with EGL personally. What you're saying here sounds right, looking at the implementations of glewInit and eglewInit. Room for improvement indeed.

vvuk commented 1 year ago

I'll see if I can take a swing at this as part of my current project; I think even just getting a path for eglGetDisplay would be a big help

gedalia commented 4 months ago

I just noticed the same thing, did this ever improve?