问题
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