Skip to content

Commit

Permalink
Remove duplicate prozying for emscripten_webgl_create_context
Browse files Browse the repository at this point in the history
The logic here for proxying this call seems to exist in both the JS
code and in the native code.   It seems to have been that way since it
was added in emscripten-core#6254.
  • Loading branch information
sbc100 committed Jan 29, 2024
1 parent ce5114b commit b2fb65e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
25 changes: 17 additions & 8 deletions src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,28 @@ var LibraryHtml5WebGL = {
#endif

#if PTHREADS && OFFSCREEN_FRAMEBUFFER
// Create a WebGL context that is proxied to main thread if canvas was not found on worker, or if explicitly requested to do so.
// Create a WebGL context that is proxied to main thread if canvas was not
// found on worker, or if explicitly requested to do so.
if (ENVIRONMENT_IS_PTHREAD) {
if (contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS }}} ||
(!canvas && contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK }}})) {
// When WebGL context is being proxied via the main thread, we must render using an offscreen FBO render target to avoid WebGL's
// "implicit swap when callback exits" behavior. TODO: If OffscreenCanvas is supported, explicitSwapControl=true and still proxying,
// then this can be avoided, since OffscreenCanvas enables explicit swap control.
// When WebGL context is being proxied via the main thread, we must
// render using an offscreen FBO render target to avoid WebGL's
// "implicit swap when callback exits" behavior. TODO: If
// OffscreenCanvas is supported, explicitSwapControl=true and still
// proxying, then this can be avoided, since OffscreenCanvas enables
// explicit swap control.
#if GL_DEBUG
if (contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS }}}) dbg('EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS enabled, proxying WebGL rendering from pthread to main thread.');
if (!canvas && contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK }}}) dbg(`Specified canvas target "${targetStr}" is not an OffscreenCanvas in the current pthread, but EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK is set. Proxying WebGL rendering from pthread to main thread.`);
dbg('Performance warning: forcing renderViaOffscreenBackBuffer=true and preserveDrawingBuffer=true since proxying WebGL rendering.');
if (contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS }}}) {
dbg('EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS enabled, proxying WebGL rendering from pthread to main thread.');
}
if (!canvas && contextAttributes.proxyContextToMainThread === {{{ cDefs.EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK }}}) {
dbg(`Specified canvas target "${targetStr}" is not an OffscreenCanvas in the current pthread, but EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK is set. Proxying WebGL rendering from pthread to main thread.`);
dbg('Performance warning: forcing renderViaOffscreenBackBuffer=true and preserveDrawingBuffer=true since proxying WebGL rendering.');
}
#endif
// We will be proxying - if OffscreenCanvas is supported, we can proxy a bit more efficiently by avoiding having to create an Offscreen FBO.
// We will be proxying - if OffscreenCanvas is supported, we can proxy a
// bit more efficiently by avoiding having to create an Offscreen FBO.
if (typeof OffscreenCanvas == 'undefined') {
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, '1', 'i32') }}};
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, '1', 'i32') }}};
Expand Down
9 changes: 1 addition & 8 deletions system/lib/gl/webgl1.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,7 @@ EMSCRIPTEN_WEBGL_CONTEXT_HANDLE emscripten_webgl_create_context(const char *targ
}
pthread_once(&tlsInit, InitWebGLTls);

if (attributes->proxyContextToMainThread == EMSCRIPTEN_WEBGL_CONTEXT_PROXY_ALWAYS ||
(attributes->proxyContextToMainThread == EMSCRIPTEN_WEBGL_CONTEXT_PROXY_FALLBACK && !emscripten_supports_offscreencanvas())) {
EmscriptenWebGLContextAttributes attrs = *attributes;
attrs.renderViaOffscreenBackBuffer = EM_TRUE;
return (EMSCRIPTEN_WEBGL_CONTEXT_HANDLE)emscripten_sync_run_in_main_runtime_thread_ptr(EM_FUNC_SIG_PPP, &emscripten_webgl_do_create_context, target, &attrs);
} else {
return emscripten_webgl_do_create_context(target, attributes);
}
return emscripten_webgl_do_create_context(target, attributes);
}

EMSCRIPTEN_RESULT emscripten_webgl_make_context_current(EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context) {
Expand Down

0 comments on commit b2fb65e

Please sign in to comment.