-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcompute.js
52 lines (48 loc) · 1.35 KB
/
compute.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
52
define(function(require, exports, module){
function ComputeKernel(gl, options){
this.gl = gl;
this.shader = options.shader;
this.mesh = options.mesh;
this.uniforms = options.uniforms;
this.outputFBO = options.output;
this.blend = options.blend;
this.nobind = options.nobind;
this.nounbind = options.nounbind;
}
ComputeKernel.prototype.run = function(){
if(this.outputFBO && !this.nobind) {
this.outputFBO.bind();
}
var textureUnit = 0, value;
for(var name in this.uniforms){
if(this.uniforms.hasOwnProperty(name)){
value = this.uniforms[name];
if(value.bindTexture && !value.bound){
value.bindTexture(textureUnit++);
}
}
}
this.shader.use();
this.shader.uniforms(this.uniforms);
if(this.blend === 'add'){
this.gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
this.gl.enable(gl.BLEND);
}
else {
this.gl.disable(gl.BLEND);
}
this.mesh.draw(this.shader);
if(this.outputFBO && !this.nounbind) {
this.outputFBO.unbind();
}
for(name in this.uniforms){
if(this.uniforms.hasOwnProperty(name)){
value = this.uniforms[name];
if(value.bindTexture && value.bound){
value.unbindTexture();
}
}
}
};
exports.Kernel = ComputeKernel;
});