Last active
April 14, 2017 15:15
-
-
Save mendes5/de0a98dd82cb8d8720a6f7ee603e8636 to your computer and use it in GitHub Desktop.
Retrieve all uniforms, attributes and its types from an shader string and returns it in a javascript object
This file contains hidden or 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
| const getShaderData = (str) => { | |
| let shaderData = { uniform: {}, attribute: {} } | |
| str.match(/attribute.*;|uniform.*;/g).map(item => { | |
| let [type1, type2, name] = item.split(' ') | |
| name = name.slice(0,name.length-1) | |
| shaderData[type1][name] = {} | |
| shaderData[type1][name].location = name | |
| shaderData[type1][name].type = type2 | |
| }) | |
| shaderData.isFragmentShader = /gl_FragColor/.test(str) | |
| shaderData.isVertexShader = /gl_Position/.test(str) | |
| return shaderData | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment