admin管理员组

文章数量:1431788

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,

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,

Share Improve this question asked Dec 18, 2012 at 17:47 Hard RainHard Rain 1,4204 gold badges15 silver badges19 bronze badges 2
  • It might help if you shared what you found in your search. – Aaron Kurtzhals Commented Dec 18, 2012 at 17:49
  • Nothing useful. This is a function, and if !!window.WebGLRenderingContext is false, then webgl is not supported. – Hard Rain Commented Dec 18, 2012 at 17:53
Add a ment  | 

3 Answers 3

Reset to default 3

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

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.

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.

本文标签: javascriptWhat is windowWebGLRenderingContextStack Overflow