Skip to content

Commit

Permalink
Make use of emscripten_supports_offscreencanvas. NFC
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 committed Jan 29, 2024
1 parent 0e5b3a8 commit 06bd7db
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/library_html5_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var LibraryHtml5WebGL = {
emscripten_webgl_do_create_context__deps: [
#if OFFSCREENCANVAS_SUPPORT
'malloc',
'emscripten_supports_offscreencanvas',
#endif
#if PTHREADS && OFFSCREEN_FRAMEBUFFER
'emscripten_webgl_create_context_proxied',
Expand Down Expand Up @@ -95,7 +96,7 @@ var LibraryHtml5WebGL = {
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.
if (typeof OffscreenCanvas == 'undefined') {
if (!_emscripten_supports_offscreencanvas()) {
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.renderViaOffscreenBackBuffer, '1', 'i32') }}};
{{{ makeSetValue('attributes', C_STRUCTS.EmscriptenWebGLContextAttributes.preserveDrawingBuffer, '1', 'i32') }}};
}
Expand All @@ -115,12 +116,12 @@ var LibraryHtml5WebGL = {
if (canvas.offscreenCanvas) canvas = canvas.offscreenCanvas;
#if GL_DEBUG
if (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
if (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas) dbg(`emscripten_webgl_create_context: Creating an OffscreenCanvas-based WebGL context on target "${targetStr}"`);
else if (typeof HTMLCanvasElement != 'undefined' && canvas instanceof HTMLCanvasElement) dbg(`emscripten_webgl_create_context: Creating an HTMLCanvasElement-based WebGL context on target "${targetStr}"`);
#endif
if (contextAttributes.explicitSwapControl) {
var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (typeof OffscreenCanvas != 'undefined' && canvas instanceof OffscreenCanvas);
var supportsOffscreenCanvas = canvas.transferControlToOffscreen || (_emscripten_supports_offscreencanvas() && canvas instanceof OffscreenCanvas);
if (!supportsOffscreenCanvas) {
#if OFFSCREEN_FRAMEBUFFER
Expand Down
8 changes: 4 additions & 4 deletions test/canvas_animate_resize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ int main()
printf("Created context with handle %u\n", (unsigned int)ctx);
if (!ctx)
{
EM_ASM({
if (typeof OffscreenCanvas === 'undefined') {
if (!emscripten_supports_offscreencanvas() {
EM_ASM({
xhr = new XMLHttpRequest();
xhr.open('GET', 'http://localhost:8888/report_result?skipped:%20OffscreenCanvas%20is%20not%20supported!');
xhr.send();
setTimeout(function() { window.close() }, 2000);
}
});
});
}
return 0;
}
emscripten_webgl_make_context_current(ctx);
Expand Down

0 comments on commit 06bd7db

Please sign in to comment.