aboutsummaryrefslogtreecommitdiffhomepage
path: root/canvasWorker.js
diff options
context:
space:
mode:
Diffstat (limited to 'canvasWorker.js')
-rw-r--r--canvasWorker.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/canvasWorker.js b/canvasWorker.js
index 04a2e1b..51878f6 100644
--- a/canvasWorker.js
+++ b/canvasWorker.js
@@ -88,11 +88,26 @@ self.onmessage = (msg) => {
useWebGL = msg.data.useWebGL;
if (useWebGL) {
console.log("using WebGL");
- gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
- if (!gl) return self.onmessage({ canvas, useWebGL: false });
+ // i hate this
+ try {
+ gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
+ if (!gl)
+ gl = canvas.getContext("experimental-webgl", {
+ preserveDrawingBuffer: true,
+ });
+ } catch (e) {
+ } finally {
+ if (!gl) {
+ console.error("WebGL not supported, using canvas instead.");
+ useWebGL = false;
+ gl = canvas.getContext("2d");
+ return;
+ }
+ }
gl.viewport(0, 0, canvas.width, canvas.height);
draw = initGL();
} else {
+ useWebGL = false;
console.log("using canvas");
gl = canvas.getContext("2d");
}