2

window.WebGLRenderingContext和 和有什么不一样canvas.getContext('experimental-webgl')

我已经搜索了很多,但我找不到答案。

提前致谢,

4

3 回答 3

3

他们说什么:-)

instanceof还有一件事,你可以使用它

> c = document.createElement("canvas");
<canvas>​
> gl = c.getContext("experimental-webgl")
WebGLRenderingContext
> gl instanceof WebGLRenderingContext
true
于 2012-12-19T08:17:17.453 回答
1

canvas.getContext将返回该特定画布的绘图上下文(请参阅规范 §2:上下文创建)。它很可能继承自全局和静态window.WebGLRenderingContext对象,该对象公开了WebGLRenderingContext接口(规范 §5.14)。浏览器不需要向 DOM 脚本 API 公开这些本机接口,但它们通常会这样做。

于 2012-12-18T17:53:54.970 回答
1

WebGLRenderingContext 是本机实现(或被允许),并不意味着由最终用户直接调用以完成工作。

至少,不像现在那样。

真的,您可以使用它来查看是否支持 WebGL:

if (!!window.WebGLRenderingContext) { 
    /* webGL is 100% guaranteed to be supported in this browser,
       if browser follows standards */
}

或者

if (!window.WebGLRenderingContext) { /* software fallback */ }

但是不能直接使用。

于 2012-12-18T17:54:05.457 回答