简体   繁体   English

如何正确识别IE11 WebGL兼容性(clearStencil,着色器)

[英]How to identify IE11 WebGL compatibility (clearStencil,shaders) correctly

In IE11 Version 11.0.9600.16428 and below some WebGL Methods are not working correctly (as mentioned here: https://github.com/mrdoob/three.js/issues/3600 ) 在IE11版本11.0.9600.16428及以下版本中,某些WebGL方法无法正常工作(如此处所述: https//github.com/mrdoob/three.js/issues/3600

One Example is the method clearStencil . 一个例子是方法clearStencil The Problem is that the method exists, but it's not working correctly. 问题是该方法存在,但它无法正常工作。 I would like to detect that and give the user some feedback. 我想检测一下并给用户一些反馈。 I tried the Detector.js from Three.js but it only checks if the browser and graphic card support WebGL and not if they support all relevant features. 我尝试过Three.js的Detector.js,但它只检查浏览器和显卡是否支持WebGL,而不是支持所有相关功能。

I tried to do a WebGL check like this: 我尝试像这样做一个WebGL检查:

var supportsWebGL=function(){
    if(Detector.webgl){
        var _canvas = document.createElement( 'canvas' );
        var _gl = _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' );
        try{
            _gl.clearStencil( 0 );
        }catch(e){
            return false;
        }
        return true;
    }else{
        return false;
    }
}

In IE11 (11.0.9600.16428) the method supportsWebGL returns true, but gives me an Error like this: 在IE11(11.0.9600.16428)中,该方法supportsWebGL WebGL返回true,但是给出了如下错误:

WEBGL11095: INVALID-OPERATION: clearStencil: Method not currently supported. WEBGL11095:无效操作:clearStencil:当前不支持的方法。

Now I want my Method supportsWebGL to detect that incompability and return false. 现在我希望我的方法supportsWebGL WebGL检测到不兼容并返回false。 Does anyone knows how to do that? 有谁知道怎么做?

I found a way to do this by using _gl.getError() 我找到了一种方法来使用_gl.getError()

var supportsWebGL=function(){
    if(Detector.webgl){
        var _canvas = document.createElement( 'canvas' );
        var _gl = _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' );
        var errors=undefined;        
        try{
            _gl.clearStencil( 0 );
            errors=_gl.getError();
        }catch(e){
            return false;
        }
        return errors==0;
    }else{
        return false;
    }
}

Only if errors are equal to zero the method will return true . 只有当errors等于零时,方法才会返回true If you have other methods you want to check for, just add them to the try/catch block. 如果您要检查其他方法,只需将它们添加到try/catch块即可。

If you need a solution that works without Three.js, check this out: 如果您需要一个没有Three.js的解决方案,请查看以下内容:

var supportsWebGL=function(){
    if(!window.WebGLRenderingContext)return false;
    try{
        var _canvas = document.createElement( 'canvas' );
        var _gl = _canvas.getContext( 'webgl' ) || _canvas.getContext( 'experimental-webgl' );
        _gl.clearStencil( 0 );
        var errors=_gl.getError();
        return errors==0;
    }catch(e){
        return false;
    }
}

The best way I can think of for now, is to check the Browser and its version. 我现在想到的最好的方法是检查浏览器及其版本。

Take this code snippet to get the browser name and its version (only major): 获取此代码段以获取浏览器名称及其版本(仅限主要版本):

var browserInformation = (function() {
var temporal = undefined;
var userAgent = navigator.userAgent;
var matches = userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if (/trident/i.test(matches[1])) {
    temporal = /\brv[ :]+(\d+)/g.exec(userAgent) || [];
    return 'Internet Explorer ' + (temporal[1] || '');
}
if (matches[1] === 'Chrome') {
    temporal = userAgent.match(/\bOPR\/(\d+)/);
    if (temporal != null)
        return 'Opera ' + temporal[1];
}
matches = matches[2] ? [matches[1], matches[2]] : [navigator.appName, navigator.appVersion, '-?'];
if ((temporal = userAgent.match(/version\/(\d+)/i)) != null)
    matches.splice(1, 1, temporal[1]);
return matches.join(' ');})();

This snippet will return a string in the format [Browsername Version] , ie Internet Explorer 11 . 此代码段将返回[Browsername Version]格式的字符串,即Internet Explorer 11

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM