Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c561ef2
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
webglew | ||
======= | ||
*WebGL* *E*xtension *W*rangler. Manages WebGL extensions so you don't have to. | ||
|
||
Usage | ||
===== | ||
First, install using npm: | ||
|
||
npm install webglew | ||
|
||
Then you can pull in a list of extensions by passing it a WebGL context: | ||
|
||
var gl = require("gl"); | ||
var ext = require("webglew")(gl); | ||
|
||
if(ext.OES_texture_float) { | ||
console.log("GL context supports floats!"); | ||
} else { | ||
console.log("No floating point textures :'("); | ||
} | ||
|
||
`require("webglew")(gl)` | ||
------------------------ | ||
To use the library, call the module with a WebGL context and it will return a JavaScript object with a list of properties. For convenience, extensions with a vendor specific prefix are aliased to the root WEBGL_* name. For example, | ||
|
||
WEBKIT_WEBGL_lose_context | ||
|
||
Becomes: | ||
|
||
WEBGL_lose_context | ||
|
||
Credits | ||
======= | ||
(c) 2013 Mikola Lysenko. BSD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
|
||
var VENDOR_PREFIX = [ | ||
"WEBKIT_", | ||
"MOZ_" | ||
]; | ||
|
||
function baseName(ext_name) { | ||
for(var i=0; i<VENDOR_PREFIX.length; ++i) { | ||
var prefix = VENDOR_PREFIX[i]; | ||
if(ext_name.indexOf(prefix) === 0) { | ||
return ext_name.slice(prefix.length); | ||
} | ||
} | ||
return ext_name; | ||
} | ||
|
||
function initWebGLEW(gl) { | ||
if(gl._webglew_struct) { | ||
return gl._webglew_struct; | ||
} | ||
var extensions = {}; | ||
var supported = gl.getSupportedExtensions(); | ||
for(var i=0; i<supported.length; ++i) { | ||
var ext = gl.getExtension(supported[i]); | ||
if(!ext) { | ||
continue; | ||
} | ||
extensions[supported[i]] = ext; | ||
extensions[baseName(supported[i])] = ext; //Add version without VENDOR | ||
} | ||
gl._webglew_struct = extensions; | ||
return extensions; | ||
} | ||
module.exports = initWebGLEW; |