glsl-extract-reflect
Takes the type data from glsl-extract and transforms the names into a JSON structure where each leaf node is the return value of the given map
function.
This is useful to create wrappers for uniform and attribute structs/arrays.
var reflect = var uniforms = name: 'lights[0].position' type: 'vec4' name: 'projection' type: 'mat4' name: 'color' type: 'vec3' var locations =
The locations
result looks like this:
"lights": "position": "type": "vec4" "location": WebGLUniformLocation "projection": "type": "mat4" "location": WebGLUniformLocation "color": "type": "vec3" "location": WebGLUniformLocation
Credit goes to @mikolalysenko; this was pulled out of gl-shader and made a little more generic.
Usage
result = reflect(array, map)
Takes an array
of uniforms or attributes with { name, type }
values, and returns the "unflattened" object for all structs and arrays. Each leaf node is the result of calling map(data, index, array)
, where data
has the following:
name: 'radius' // the standalone uniform name path: 'lights[0].radius' // the qualified name used by WebGL type: 'float' // the original type ...
Other values (like location
) are also copied into the data
object.
See Also
- glsl-extract-sync
- gl-shader-extract (extracts during runtime)
License
MIT, see LICENSE.md for details.