Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EGL Bind API is Per Thread #1820

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 2 comments
Closed

EGL Bind API is Per Thread #1820

SDLBugzilla opened this issue Feb 10, 2021 · 2 comments
Assignees
Milestone

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 2.1
Reported for operating system, platform: All, All

Comments on the original bug report:

On 2015-04-09 12:06:45 +0000, wrote:

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."

On 2015-04-10 12:37:07 +0000, wrote:

Created attachment 2116
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.

On 2015-04-11 02:34:50 +0000, wrote:

Created attachment 2117
EGL Threaded API Patch

Updated to bind the correct api for OpenGL.

On 2017-08-13 00:46:35 +0000, Sam Lantinga wrote:

Ryan, this seems reasonable offhand. Is this something we want to add?

@icculus icculus added this to the 2.0.18 milestone Aug 12, 2021
@icculus icculus self-assigned this Aug 12, 2021
@icculus
Copy link
Collaborator

icculus commented Sep 22, 2021

I think we're going to try this without tracking the currently-bound API. If you call MakeCurrent, and SDL decides the context needs to be set for the thread, it'll bind the API too. This is likely not an expensive call, and calling MakeCurrent is a rare event anyhow.

@icculus
Copy link
Collaborator

icculus commented Sep 23, 2021

My patch was way simpler than the one attached here, but this should get the job done just as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants