mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Add check for WebGL support.
The intention is to fall back to the legacy map if WebGL is not supported on a client.
This commit is contained in:
@@ -597,12 +597,50 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
checkWebGLSupport() {
|
||||||
|
const canvas = document.createElement('canvas');
|
||||||
|
const gl = canvas.getContext('webgl2') || canvas.getContext('webgl');
|
||||||
|
if (!gl) {
|
||||||
|
//this.error = 'WebGL is not supported in this browser or device.';
|
||||||
|
//this.loading = false;
|
||||||
|
console.error('WebGL not supported');
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const isWebGL2 = gl instanceof WebGL2RenderingContext;
|
||||||
|
console.log('WebGL Support:', isWebGL2 ? 'WebGL2' : 'WebGL1');
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
toBase64 (binary) {
|
||||||
|
return btoa(String.fromCharCode(...new Uint8Array(binary)));
|
||||||
|
},
|
||||||
|
|
||||||
|
fromBase64 (text) {
|
||||||
|
const decoded = atob(text);
|
||||||
|
const arr = new Uint8Array(decoded.length);
|
||||||
|
for (let i=0; i<decoded.length; i++) {
|
||||||
|
arr[i] = decoded.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return arr.buffer;
|
||||||
|
},
|
||||||
|
|
||||||
...mapActions(["api"])
|
...mapActions(["api"])
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async mounted () {
|
async mounted () {
|
||||||
|
|
||||||
|
if (!this.checkWebGLSupport()) {
|
||||||
|
for (const countdown = 5; countdown > 0; countdown--) {
|
||||||
|
if (countdown) {
|
||||||
|
this.error = `This browser does not support WebGL. Switching to legacy map view in ${countdown} seconds.`;
|
||||||
|
await new Promise( (resolve) => setTimeout(() => resolve, 1000) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.error = null;
|
||||||
|
console.log("TODO: Should switch to legacy map view");
|
||||||
|
}
|
||||||
|
|
||||||
const COLOR_SCALE = [
|
const COLOR_SCALE = [
|
||||||
// negative
|
// negative
|
||||||
[65, 182, 196],
|
[65, 182, 196],
|
||||||
|
|||||||
Reference in New Issue
Block a user