Three.js 检测 webgl 支持并回退到常规画布 [英] Three.js detect webgl support and fallback to regular canvas
问题描述
任何使用过 Three.js 的人都可以告诉我是否可以检测 webgl 支持,如果不存在,则退回到标准的 Canvas 渲染?
Can anyone who has used three.js tell me if its possible to detect webgl support, and, if not present, fallback to a standard Canvas render?
推荐答案
是的,这是可能的.您可以使用 CanvasRenderer
而不是 WebGLRenderer
.
Yes, it's possible. You can use CanvasRenderer
instead of WebGLRenderer
.
关于 WebGL 检测:
About WebGL detection:
1) 阅读这篇 WebGL 维基文章:http://www.khronos.org/webgl/wiki/常见问题解答
1) Read this WebGL wiki article: http://www.khronos.org/webgl/wiki/FAQ
if (!window.WebGLRenderingContext) {
// the browser doesn't even know what WebGL is
window.location = "http://get.webgl.org";
} else {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("webgl");
if (!context) {
// browser supports WebGL but initialization failed.
window.location = "http://get.webgl.org/troubleshooting";
}
}
2) Three.js 已经有一个 WebGL 检测器:https://github.com/mrdoob/three.js/blob/master/示例/js/Detector.js
2) Three.js already has a WebGL detector: https://github.com/mrdoob/three.js/blob/master/examples/js/Detector.js
renderer = Detector.webgl? new THREE.WebGLRenderer(): new THREE.CanvasRenderer();
3) 还要检查 Modernizr 检测器:https://github.com/Modernizr/Modernizr/blob/master/feature-detects/webgl.js
3) Check also the Modernizr detector: https://github.com/Modernizr/Modernizr/blob/master/feature-detects/webgl.js
这篇关于Three.js 检测 webgl 支持并回退到常规画布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!