• 因为自己写的一个渲染库有降级的处理在低配和无webgl的环境下是会使用canvas的渲染器。后来发现在云桌面的一些环境下是能开webgl的但是会很卡…后面就打算多一个检测硬件加速来降级判断
        try {
            const webgl = !!window.WebGLRenderingContext
            if (webgl) {
                const canvas = document.createElement('canvas');
                const option = {
                    failIfMajorPerformanceCaveat: !('undefined' != typeof window && window.FORCE_WEBGL)
                }
                const gl = (
                    canvas.getContext('webgl', option) ||
                    canvas.getContext('experimental-webgl', option)
                )
                if (gl) {
                    const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
                    if (debugInfo) {
                        const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
                        console.log(!/SwiftShader/gi.test(renderer) ?
                            "浏览器环境支持并开启webgl硬件加速" :
                            "浏览器并未开启硬件加速"
                        );
                    }
                } else {
                    console.log('浏览器在低配环境下开启不了webgl')
                }
            } else {
                console.log('浏览器没有webgl环境')
            }
        } catch (e) {
            console.log(e)
        }

更多推荐