Skip to content

Commit

Permalink
initialize
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolalysenko committed Feb 23, 2013
0 parents commit c561ef2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
@@ -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
35 changes: 35 additions & 0 deletions webglew.js
@@ -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;

0 comments on commit c561ef2

Please sign in to comment.