-
Notifications
You must be signed in to change notification settings - Fork 1
/
CLShaderLoader.js
51 lines (47 loc) · 1.62 KB
/
CLShaderLoader.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
CL.ShaderLoader = {
loadFile: function(url, no, callback, errorCallback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onreadystatechange = function () {
if (request.readyState == 4) {
if (request.status == 200) {
callback(request.responseText, no)
} else {
errorCallback(url);
}
}
};
request.send(null);
},
loadFiles: function(urls, callback, errorCallback, GCB) {
var numUrls = urls.length;
var numComplete = 0;
var result = [];
function partialCallback(text, urlIndex) {
result[result.length] = {}
result[result.length-1].type = urls[urlIndex][1];
result[result.length-1].text = text;
result[result.length-1].url = urls[urlIndex][0];
numComplete++;
if (numComplete == numUrls) {
callback(result, GCB);
}
}
for (i = 0; i < numUrls; i++) {
CL.ShaderLoader.loadFile(urls[i][0], i, partialCallback, errorCallback);
}
},
appendShaders: function(shaders, callback) {
for(shader in shaders) {
shader = shaders[shader]
elem = document.createElement('script')
url = shader.url;
alert("shader.url")
elem.id = url.substr(url.lastIndexOf("/") + 1)
elem.innerHTML = shader.text;
elem.type = shader.type
document.head.appendChild(elem);
}
callback()
}
}