aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMarvin Borner2024-04-08 16:20:39 +0200
committerMarvin Borner2024-04-08 16:29:08 +0200
commit6e763fb73bd3292fbbd1f9bfdccc09af5f730938 (patch)
treee6c55259c1a89c83a1feea31b81a60ad29f4245f
parent992c4a984a696984765c6eb04eb889a0a94d7d8a (diff)
Improve canvas fallback
-rw-r--r--canvasWorker.js19
-rw-r--r--index.html8
2 files changed, 22 insertions, 5 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");
}
diff --git a/index.html b/index.html
index 6dba53a..5523cf2 100644
--- a/index.html
+++ b/index.html
@@ -139,10 +139,12 @@ qsplit = \(0 \\\\\((((0 ((4 \((((0 \\1) \\1) \\1) \\1)) \((((0 \\0) \\0) \\0) \\
<script src="main.js"></script>
<script charset="utf-8">
let useWebGL = true;
- const isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
- if (isMobile) {
+ const isWeird = /iPhone|iPad|iPod|Android|AppleWebKit/i.test(
+ navigator.userAgent,
+ );
+ if (isWeird) {
useWebGL = false;
- MAXRES = 10;
+ MAXRES = 3;
}
const canvas = window.canvas;