From 0f7678fc5b897f1c69631108a394e448b727db95 Mon Sep 17 00:00:00 2001 From: Codezigineer <53050996+Codezigineer@users.noreply.github.com> Date: Mon, 21 Nov 2022 09:52:00 -0800 Subject: [PATCH] Add OffscreenCanvas --- js/tinygl.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/js/tinygl.js b/js/tinygl.js index c4aab50..8e118da 100644 --- a/js/tinygl.js +++ b/js/tinygl.js @@ -2513,3 +2513,24 @@ if ((typeof HTMLCanvasElement) != 'undefined') { } catch (e) { } } + +/* Also add for offscreenCanvas */ +if ((typeof OffscreenCanvas) != 'undefined') { + try { + var default_get_context_func = OffscreenCanvas.prototype.getContext; + OffscreenCanvas.prototype.getContext = function() { + if (arguments[0] == 'experimental-tinygl') { + try { + // initialize TinyGL runtime if not yet + if (!TinyGLRenderingContext) + initializeTinyGLRuntime(arguments[1]); + return new TinyGLRenderingContext(this, arguments[1]); + } catch (e) { + return null; + } + } + return default_get_context_func.apply(this, arguments); + }; + } catch (e) { + } +};