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 2937 - EGL Bind API is Per Thread
Summary: EGL Bind API is Per Thread
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.1
Hardware: All All
: P2 major
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-09 12:06 UTC by x414e54
Modified: 2017-08-13 00:46 UTC (History)
0 users

See Also:


Attachments
EGL Threaded API Patch (6.85 KB, patch)
2015-04-10 12:37 UTC, x414e54
Details | Diff
EGL Threaded API Patch (6.85 KB, patch)
2015-04-11 02:34 UTC, x414e54
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description x414e54 2015-04-09 12:06:45 UTC
As per the EGL spec eglBindApi needs to be called for each thread.

Currently eglBindApi is only called at window/context creation. This means if SDL_GL_CreateContext is called on a different thread to SDL_GL_MakeCurrent it is possible that there would be no bound egl api.

I was trying to track down an error where my OpenGL application will produce an EGL_BAD_SURFACE in SDL_GL_SwapWindow even though the context is current and this lead me to this error.

To fix this I would suggest calls to SDL_GL_MakeCurrent check if eglBindApi has been called on that thread and is also set to the same api of that context. If not it will call eglBindApi. This would require storing an egl_api value with the SDL_GLContext. I will create a patch if I get time.


A quote from the EGL spec:

"eglBindAPI defines the current rendering API for EGL in the thread it is called from."
Comment 1 x414e54 2015-04-10 12:37:07 UTC
Created attachment 2116 [details]
EGL Threaded API Patch

I have created a quick patch to bind the API per thread.

It compiles but I have not tested it fully yet.

Currently it uses eglQueryAPI but if you would like it not to call down to egl even though this is probably not an expensive call then it would need to use TLS.
Comment 2 x414e54 2015-04-11 02:34:50 UTC
Created attachment 2117 [details]
EGL Threaded API Patch

Updated to bind the correct api for OpenGL.
Comment 3 Sam Lantinga 2017-08-13 00:46:35 UTC
Ryan, this seems reasonable offhand. Is this something we want to add?