-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
51 lines (38 loc) · 1.3 KB
/
helpers.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
const vertexShaderSource = `
attribute vec4 a_Position;
uniform vec4 u_Translation;
uniform mat4 u_scaleMatrix;
void main() {
gl_Position = a_Position * u_scaleMatrix;
gl_PointSize = 50.0;
}
`;
const fragmentShaderSource = `
precision mediump float;
uniform vec4 u_FragColor;
void main() {
gl_FragColor = u_FragColor;
}
`;
const initVertexShader = ({ context, program }) => {
const vertexShader = context.createShader(context.VERTEX_SHADER);
context.shaderSource(vertexShader, vertexShaderSource);
context.compileShader(vertexShader);
context.attachShader(program, vertexShader);
};
const initFragmentShader = ({ context, program }) => {
const fragmentShader = context.createShader(context.FRAGMENT_SHADER);
context.shaderSource(fragmentShader, fragmentShaderSource);
context.compileShader(fragmentShader);
context.attachShader(program, fragmentShader);
};
const initShaders = context => {
const program = context.createProgram();
initVertexShader({ context, program });
initFragmentShader({ context, program });
context.linkProgram(program);
const linkStatus = context.getProgramParameter(program, context.LINK_STATUS);
console.log(linkStatus);
context.useProgram(program);
return program;
};