@@ -47,9 +47,20 @@ var LibraryHtml5WebGL = {
4747
4848 _emscripten_webgl_power_preferences : "['default', 'low-power', 'high-performance']" ,
4949
50- // In offscreen framebuffer mode, we implement these functions in C so that they enable
51- // the proxying of GL commands. Otherwise, they are implemented here in JS.
52- #if ! ( USE_PTHREADS && OFFSCREEN_FRAMEBUFFER )
50+ #if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER
51+ // In offscreen framebuffer mode, we implement a proxied version of the
52+ // emscripten_webgl_create_context() function in JS.
53+ emscripten_webgl_create_context_proxied__proxy : 'sync' ,
54+ emscripten_webgl_create_context_proxied__deps : [ 'emscripten_webgl_do_create_context' ] ,
55+ emscripten_webgl_create_context_proxied : function ( target , attributes ) {
56+ return _emscripten_webgl_do_create_context ( target , attributes ) ;
57+ } ,
58+
59+ // The other proxied GL commands are defined in C (guarded by the
60+ // __EMSCRIPTEN_OFFSCREEN_FRAMEBUFFER__ definition).
61+ #else
62+ // When not in offscreen framebuffer mode, these functions are implemented
63+ // in JS and forwarded without any proxying.
5364 emscripten_webgl_create_context__sig : 'iii' ,
5465 emscripten_webgl_create_context : 'emscripten_webgl_do_create_context' ,
5566
@@ -60,16 +71,16 @@ var LibraryHtml5WebGL = {
6071 emscripten_webgl_commit_frame : 'emscripten_webgl_do_commit_frame' ,
6172#endif
6273
63- // This code is called from the main proxying logic, which has a big switch
64- // for all the messages, one of which is this GL-using one . This won't be
74+ // This code is called from emscripten_webgl_create_context() and proxied
75+ // to the main thread when in offscreen framebuffer mode . This won't be
6576 // called if GL is not linked in, but also make sure to not add a dep on
6677 // GL unnecessarily from here, as that would cause a linker error.
6778 emscripten_webgl_do_create_context__deps : [
6879#if LibraryManager . has ( 'library_webgl.js' )
6980 '$GL' ,
7081#endif
71- #if ( USE_PTHREADS && OFFSCREEN_FRAMEBUFFER )
72- 'emscripten_sync_run_in_main_thread_2 ' ,
82+ #if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER
83+ 'emscripten_webgl_create_context_proxied ' ,
7384#endif
7485 '$JSEvents' , '_emscripten_webgl_power_preferences' , '$findEventTarget' , '$findCanvasEventTarget' ] ,
7586 // This function performs proxying manually, depending on the style of context that is to be created.
@@ -104,7 +115,7 @@ var LibraryHtml5WebGL = {
104115 var targetStr = UTF8ToString ( target ) ;
105116#endif
106117
107- #if ( USE_PTHREADS && OFFSCREEN_FRAMEBUFFER )
118+ #if USE_PTHREADS && OFFSCREEN_FRAMEBUFFER
108119 // Create a WebGL context that is proxied to main thread if canvas was not found on worker, or if explicitly requested to do so.
109120 if ( ENVIRONMENT_IS_PTHREAD ) {
110121 if ( contextAttributes . proxyContextToMainThread === { { { cDefine ( 'EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS' ) } } } ||
@@ -122,7 +133,7 @@ var LibraryHtml5WebGL = {
122133 { { { makeSetValue ( 'attributes' , C_STRUCTS . EmscriptenWebGLContextAttributes . renderViaOffscreenBackBuffer , '1' , 'i32' ) } } } ;
123134 { { { makeSetValue ( 'attributes' , C_STRUCTS . EmscriptenWebGLContextAttributes . preserveDrawingBuffer , '1' , 'i32' ) } } } ;
124135 }
125- return _emscripten_sync_run_in_main_thread_2 ( { { { cDefine ( 'EM_PROXIED_CREATE_CONTEXT' ) } } } , target , attributes ) ;
136+ return _emscripten_webgl_create_context_proxied ( target , attributes ) ;
126137 }
127138 }
128139#endif
@@ -617,7 +628,7 @@ function handleWebGLProxying(funcs) {
617628 } else if ( targetingOffscreenFramebuffer ) {
618629 // When targeting only OFFSCREEN_FRAMEBUFFER, unconditionally proxy all GL calls to
619630 // main thread.
620- funcs [ i + '__proxy' ] = 'sync' ;
631+ funcs [ i + '__proxy' ] = 'sync' ;
621632 } else {
622633 // Building without OFFSCREENCANVAS_SUPPORT or OFFSCREEN_FRAMEBUFFER; or building
623634 // with OFFSCREENCANVAS_SUPPORT and no OFFSCREEN_FRAMEBUFFER: the application
0 commit comments