request.>
result[key] = request.response;
loaded += 1;
if(count == loaded) ondone(result);
}
request.send();
}
for(var key in files){
var path = files[key];
count += 1;
doLoad(key, path);
}
}
And you can use it like:
loadFiles({
foo: 'foo.shader',
bar: 'bar.shader',
test: 'test.shader',
another: 'whatever.shader'
}, function(files){
ctx.shaderSource(shader, files.foo);
});
The other is a bit cleaner in my opinion, which is:
- Some script to pack all your shaders in a JSON, for instance in python
import os, json
result = {}
for path, dirs, names in os.walk('.'):
for name in names:
result[os.path.join(path, name)] = open(os.path.join(path, name)).read()
open('shaders.json', 'w').write(json.encode(result))
And then in JS do:
var request = new XMLHttpRequest();
request.open('GET', 'sometext.txt', true);
request.>
var shaders = JSON.parse(request.response);
gl.shaderSource(shader, shaders['whatever.shader']);
}
request.send();
(Not to mention the requirement of a local http server, which most definitely negatively impacts the pick-up-and-hack capabilities of WebGL)
Afaik, XHRs work locally either if you toggle them on (in chrome) or if you request only from below your html files path (firefox).