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() { })(),
|
print: (function() { })(),
|
||||||
printErr: function(text) { },
|
printErr: function(text) { },
|
||||||
canvas: (function() {
|
canvas: (function() {
|
||||||
let canvas = document.getElementById('canvas');
|
const canvas = document.getElementById('canvas');
|
||||||
// As a default initial behavior, pop up an alert when webgl context is lost. To make your
|
canvas.addEventListener("webglcontextlost", function(e) {
|
||||||
// application robust, you may want to override this behavior before shipping!
|
alert('WebGL context lost, please reload the page');
|
||||||
// See http://www.khronos.org/registry/webgl/specs/latest/1.0/#5.15.2
|
e.preventDefault();
|
||||||
canvas.addEventListener("webglcontextlost", function(e) { alert('WebGL context lost. You will need to reload the page.'); e.preventDefault(); }, false);
|
}, 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;
|
return canvas;
|
||||||
|
} else {
|
||||||
|
alert('WebGL 2 not supported by this browser');
|
||||||
|
}
|
||||||
})(),
|
})(),
|
||||||
setStatus: function(text) { },
|
setStatus: function(text) { },
|
||||||
totalDependencies: 0,
|
totalDependencies: 0,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user