What is window.WebGLRenderingContext?

混江龙づ霸主 提交于 2019-12-11 03:17:02

问题


What is the difference between window.WebGLRenderingContext and canvas.getContext('experimental-webgl')?

I've searched a lot, but I can't find the answer.

Thanks in advance,


回答1:


canvas.getContext will return a drawing context for that particular canvas (see spec §2: Context Creation). It will likely inherit from the global and static window.WebGLRenderingContext object, which exposes the WebGLRenderingContext interface (spec §5.14). A browser does not need to expose those native interfaces to the DOM scripting API, but they usually do.




回答2:


What they said :-)

One more thing, you can use it with instanceof as in

> c = document.createElement("canvas");
<canvas>​
> gl = c.getContext("experimental-webgl")
WebGLRenderingContext
> gl instanceof WebGLRenderingContext
true



回答3:


WebGLRenderingContext is a native implementation (or is allowed to be), and isn't meant to be called by the end-user, directly, in order to do work.

At least, not as it currently-exists.

Really, you can use it to see if WebGL is supported:

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

or

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

But it can not be used directly.



来源:https://stackoverflow.com/questions/13938600/what-is-window-webglrenderingcontext

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!