aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-06-17 13:03:28 -0700
committerAlon Zakai <alonzakai@gmail.com>2014-06-17 13:08:53 -0700
commitdf9d3c2381883d38efd870a1d62730a6b16e1a8b (patch)
tree30c9f229ba25165be9fcbaf5cdf6370a2fadfb05 /src
parent65b9caa8199b1245cf2e089a5878713569cceeb8 (diff)
parse attributes
Diffstat (limited to 'src')
-rw-r--r--src/webGLWorker.js26
1 files changed, 17 insertions, 9 deletions
diff --git a/src/webGLWorker.js b/src/webGLWorker.js
index 559e13bd..cbf5ec74 100644
--- a/src/webGLWorker.js
+++ b/src/webGLWorker.js
@@ -567,13 +567,11 @@ function WebGLWorker() {
this.linkProgram = function(program) {
commandBuffer.push('linkProgram', 1, program.id);
// parse shader sources
- program.uniforms = {};
- program.uniformVec = [];
- program.shaders.forEach(function(shader) {
- var newUniforms = shader.source.match(/uniform\s+\w+\s+[\w,\s\[\]]+;/g);
- if (!newUniforms) return;
- newUniforms.forEach(function(uniform) {
- var m = /uniform\s+\w+\s+([\w,\s\[\]]+);/.exec(uniform);
+ function parseElementType(shader, type, obj, vec) {
+ var newItems = shader.source.match(new RegExp(type + '\\s+\\w+\\s+[\\w,\\s\[\\]]+;', 'g'));
+ if (!newItems) return;
+ newItems.forEach(function(item) {
+ var m = new RegExp(type + '\\s+\\w+\\s+([\\w,\\s\[\\]]+);').exec(item);
assert(m);
m[1].split(',').map(function(name) { return name.replace(/\s/g, '') }).filter(function(name) { return !!name }).forEach(function(name) {
var size = 1;
@@ -584,11 +582,21 @@ function WebGLWorker() {
name = name.substr(0, open);
}
if (!program.uniforms[name]) {
- program.uniforms[name] = { what: 'uniform', name: name, size: size };
- program.uniformVec.push(name);
+ obj[name] = { what: type, name: name, size: size };
+ if (vec) vec.push(name);
}
});
});
+ }
+
+ program.uniforms = {};
+ program.uniformVec = [];
+
+ program.existingAttributes = {};
+
+ program.shaders.forEach(function(shader) {
+ parseElementType(shader, 'uniform', program.uniforms, program.uniformVec);
+ parseElementType(shader, 'attribute', program.existingAttributes, null);
});
};
this.getProgramParameter = function(program, name) {