javascript - 检查客户端浏览器是否支持并启用 WebGL2
问题描述
我想检查用户浏览器是否启用并支持 WebGL 2。
WebGL 1 有很多帖子,但我没有发现任何与 WebGL 版本 2 相关的帖子。
解决方案
您应该检查的方式只是查看尝试获取webgl2
上下文是成功还是失败
const gl = document.createElement('canvas').getContext('webgl2');
if (!gl) {
console.log('your browser/OS/drivers do not support WebGL2');
} else {
console.log('webgl2 works!');
}
您还可以检查是否window.WebGL2RenderingContext
存在以尝试猜测它是不支持 WebGL2 的浏览器还是用户的 OS/GPU/驱动程序。
const gl = document.createElement('canvas').getContext('webgl2');
if (!gl) {
if (typeof WebGL2RenderingContext !== 'undefined') {
console.log('your browser appears to support WebGL2 but it might be disabled. Try updating your OS and/or video card drivers');
} else {
console.log('your browser has no WebGL2 support at all');
}
} else {
console.log('webgl2 works!');
}
推荐阅读
- angularjs - 隔离范围和嵌套指令
- r - 无法在 R 中安装漩涡包
- python - 为什么我的二元分类模型不学习,甚至过度拟合?
- amazon-cognito - 在 Cognito 中获取特定用户的 UserNotFoundException
- javascript - 如何访问从 API 调用返回的该对象内部的值
- machine-learning - Pytorch 与改进的衍生物
- c++ - 可组合的单子 lambda/std::function 与 std::optional
- airflow - MLFlow 的气流运算符
- html - html img 在内容框上有一个额外的空间
- javascript - setAttribute 不设置值