We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 3415

Summary: SDL_VIDEODRIVER=wayland makes SDL_GL_GetProcAddress return NULL on many modern opengl functions
Product: SDL Reporter: eliashogstvedt
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: amaranth72, icculus
Version: HG 2.1   
Hardware: x86_64   
OS: Linux   

Description eliashogstvedt 2016-08-26 10:08:21 UTC
This only happens when using the environment variable and it does not happen when using the default video driver (xorg). For example direct state access functions like SDL_GL_GetProcAddress("glCreateVertexArrays"); do not exist.
Comment 1 eliashogstvedt 2016-08-26 10:38:29 UTC
Having had a look at the function I saw that it uses SDL_SetError on failure SDL_GetError returns :

Failed loading _glCreateVertexArrays: /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1: undefined symbol: __glCreateVertexArrays

I don't know much about how symbols are loaded in opengl or sdl but there is no such symbol in libGL.so however I did found "00000000002f3400 D epoxy_glCreateVertexArrays" in /usr/lib/x86_64-linux-gnu/libepoxy.so. Might be a clue?
Comment 2 Alex Szpakowski 2016-08-28 13:49:35 UTC
Does your OpenGL implementation provide either OpenGL 4.5 or the GL_ARB_direct_state_access extension, when you use wayland? That function requires at least one of those at runtime.
Comment 3 eliashogstvedt 2016-08-31 11:02:14 UTC
(In reply to Alex Szpakowski from comment #2)
> Does your OpenGL implementation provide either OpenGL 4.5 or the
> GL_ARB_direct_state_access extension, when you use wayland? That function
> requires at least one of those at runtime.

It provides 4.4 (using intel hd graphcis 5500/i915 with mesa 12.1.0-devel)

I think this is a misunderstanding on my end on how SDL_GL_GetProcAddress works. With X SDL_GL_ExtensionSupported("GL_ARB_direct_state_access") does not return true but SDL_GL_GetProcAddress returns the DSA function pointers and they work as expected. This had me confused so I had worked around it in my renderer but I wasn't sure if this was related to this issue so I didn't mention it. I also thought DSA was core from 4.2-3 and up.

With wayland (SDL_VIDEODRIVER=wayland) the DSA extension is also false but the function pointers are NULL.

So I don't know if this is a bug or expected behavior anymore. Now my issue is: How do I get access to the DSA functions under OpenGL 4.4 using wayland?
Comment 4 Alex Szpakowski 2016-08-31 20:57:43 UTC
Mesa 12.1 isn't officially released yet. Maybe it's a driver bug?
Comment 5 Ryan C. Gordon 2016-09-07 03:07:50 UTC
> So I don't know if this is a bug or expected behavior anymore.

Mesa on X11 will always return a non-NULL pointer, even if the extension isn't supported, because you can legally ask for a pointer before you have a context and they know what's actually available to you. These pointers are trampolines that will bounce to the real implementation once you have a current context.

https://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL/

_Always_ check the extension, not whether you get a NULL pointer!

I don't know if Wayland cleaned this mess up, but it _would_ use a different mechanism for finding GL entry points.

--ryan.
Comment 6 eliashogstvedt 2016-09-07 10:32:47 UTC
Thanks for the feedback. 

This has been a mistake on my end where I had cached the result of what SDL_GL_ExtensionSupported returned and called the function too early making me believe direct_state_access was not available.

But for some reason now I can also use the DSA functions under wayland but I'm not sure how that started working. Maybe it's because I'm using the oibaf ppa to get the latest mesa drivers?

I also wasn't able to compile SDL with wayland whereas a week ago I was able to. I had had a look at the configure file and installed the packages it was looking for. This might have been the latest cursor addition to wayland though.