gl-extension

gets a WebGL extension, normalized to work the same in WebGL 2 contexts

gl-extension

Grabs an extension from the specified WebGL context.

If the context is using WebGL 2.0, core functions and contexts are wrapped with dummy interfaces, so your code does not need to change.

Example

var getExtension = require('gl-extension')

// get an extension
var ext = getExtension(gl, 'OES_vertex_array_object')
if (ext) {
  // this will work even when gl is a WebGL 2.0 context
  var array = ext.createVertexArrayOES()
  console.log(ext.VERTEX_ARRAY_BINDING_OES)  
}

Install

npm install gl-extension --save

Usage

ext = getExtension(gl, name)

If gl is a WebGL 1.0 instance, or if the extension is not part of core in WebGL 2.0, this is the same as calling gl.getExtension(name).

If gl is a WebGL 2.0 instance and name is an extension that has been promoted to core, a new wrapper object will be returned mimicing the API and constants of the WebGL 1 extension.

See the WebGL Extension Registry for extension details.

require('gl-extension').patch(gl)

Patches the gl.getExtension function correctly so that legacy code bases (e.g. ThreeJS) can use WebGL2 without problems.

See Also

License

MIT, see LICENSE.md for details.

HomePage

https://github.com/Jam3/gl-extension

Repository

https://github.com/Jam3/gl-extension


相关推荐