-
Notifications
You must be signed in to change notification settings - Fork 159
Expand file tree
/
Copy pathdestinationnode.js
More file actions
62 lines (50 loc) · 2.02 KB
/
destinationnode.js
File metadata and controls
62 lines (50 loc) · 2.02 KB
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
53
54
55
56
57
58
59
60
61
62
//Matthew Shotton, R&D User Experience,© BBC 2015
import ProcessingNode from "../ProcessingNodes/processingnode";
import fragmentShader from "./destinationnode.frag";
import vertexShader from "./destinationnode.vert";
const TYPE = "DestinationNode";
class DestinationNode extends ProcessingNode {
/**
* Initialise an instance of a DestinationNode.
*
* There should only be a single instance of a DestinationNode per VideoContext instance. An VideoContext's destination can be accessed like so: videoContext.desitnation.
*
* You should not instantiate this directly.
*/
constructor(gl, renderGraph) {
let definition = {
fragmentShader,
vertexShader,
properties: {},
inputs: ["u_image"]
};
super(gl, renderGraph, definition, definition.inputs, false);
this._displayName = TYPE;
}
_render() {
let gl = this._gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.clearColor(0, 0, 0, 0.0); // green;
gl.clear(gl.COLOR_BUFFER_BIT);
// Set the initial blend function to 'proiritize' the SRC so that the background
// clearColor doesn't bleed / blend into output
gl.enable(gl.BLEND);
gl.blendFunc(gl.ONE, gl.ZERO);
this.inputs.forEach(node => {
super._render();
//map the input textures input the node
var texture = node._texture;
for (let mapping of this._shaderInputsTextureUnitMapping) {
gl.activeTexture(mapping.textureUnit);
gl.uniform1i(mapping.location, mapping.textureUnitIndex);
gl.bindTexture(gl.TEXTURE_2D, texture);
}
gl.drawArrays(gl.TRIANGLES, 0, 6);
// Update the blend function to allow for 'default' blend of transparency
// of the next inputs of the node
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
});
}
}
export { TYPE as DESTINATIONTYPE };
export default DestinationNode;