Skip to content Skip to sidebar Skip to footer

What Is Window.webglrenderingcontext?

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,

Solution 1:

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 instanceofWebGLRenderingContext
true

Solution 2:

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.

Solution 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.

Post a Comment for "What Is Window.webglrenderingcontext?"