web: Improved canvas webgl creation logic
This commit is contained in:
parent
c7c4ecad6d
commit
3b799388c2
22
dist/web/source/wasm-config.js
vendored
22
dist/web/source/wasm-config.js
vendored
@ -111,13 +111,25 @@ var Module = {
|
||||
print: (function() { })(),
|
||||
printErr: function(text) { },
|
||||
canvas: (function() {
|
||||
let canvas = document.getElementById('canvas');
|
||||
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
||||
// application robust, you may want to override this behavior before shipping!
|
||||
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
||||
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
||||
const canvas = document.getElementById('canvas');
|
||||
canvas.addEventListener("webglcontextlost", function(e) {
|
||||
alert('WebGL context lost, please reload the page');
|
||||
e.preventDefault();
|
||||
}, false);
|
||||
|
||||
if (typeof WebGL2RenderingContext !== 'undefined') {
|
||||
let gl = canvas.getContext('webgl2', { stencil: true });
|
||||
if (!gl) {
|
||||
console.error('WebGL 2 not available, falling back to WebGL');
|
||||
gl = canvas.getContext('webgl', { stencil: true });
|
||||
}
|
||||
if (!gl) {
|
||||
alert('WebGL not available with stencil buffer');
|
||||
}
|
||||
return canvas;
|
||||
} else {
|
||||
alert('WebGL 2 not supported by this browser');
|
||||
}
|
||||
})(),
|
||||
setStatus: function(text) { },
|
||||
totalDependencies: 0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user