emscripten-core / emscripten-core/emscripten

Using shared OpenGL context in the wroker thread...

Open
#20,418 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

Hello,

I have an issue using WebGL API in the worker thread (which is used to compile shaders only)...

My steps are:
1. I create 2 OpenGL contexts using SDL2...
_glContext = SDL_GL_CreateContext(_window);
SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
SDL_GLContext newCont = SDL_GL_CreateContext(_window);
_glSharedContext = newCont;

2. Make main context current to main thread:
SDL_GL_MakeCurrent(_window, _glContext);

3. Spawn worker job thread and make shared context current to the worker thread
// Inside the worker thread...
SDL_GL_MakeCurrent(_window, _glSharedContext);

4. Execute queue of shader jobs in worker thread...

All this perfectly worrking in windows build.
But in emscripten, unfortunately when i try to access any WebGL API in the worker it doesn't work:
Worker thread throws error, createShader is not a fucntion or so...
Looks like worker doesn't have any context? but SDL_GL_MakeCurrent returns 0, which means succeded.

So how to use WebGL in the workers?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.