forked from scriptfoundry/WebGL2-Videos-Materials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path14.matrixattributes.js
67 lines (51 loc) · 1.66 KB
/
14.matrixattributes.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// tslint:disable: no-console
const vertexShaderSrc = `#version 300 es
#pragma vscode_glsllint_stage: vert
layout(location=0) in vec4 aPosition;
layout(location=1) in float aPointSize;
layout(location=2) in vec4 aColor;
layout(location=3) in mat4 aModelMatrix;
out vec4 vColor;
void main()
{
vColor = aColor;
gl_PointSize = aPointSize;
gl_Position = aModelMatrix * aPosition;
}`;
const fragmentShaderSrc = `#version 300 es
#pragma vscode_glsllint_stage: frag
precision mediump float;
in vec4 vColor;
out vec4 fragColor;
void main()
{
fragColor = vColor;
}`;
const gl = document.querySelector('canvas').getContext('webgl2');
const program = gl.createProgram();
const vertexShader = gl.createShader(gl.VERTEX_SHADER);
gl.shaderSource(vertexShader, vertexShaderSrc);
gl.compileShader(vertexShader);
gl.attachShader(program, vertexShader);
const fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
gl.shaderSource(fragmentShader, fragmentShaderSrc);
gl.compileShader(fragmentShader);
gl.attachShader(program, fragmentShader);
gl.linkProgram(program);
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
console.log(gl.getShaderInfoLog(vertexShader));
console.log(gl.getShaderInfoLog(fragmentShader));
}
gl.useProgram(program);
// Get all attribute names
const attributeNames = [];
for (let i = 0; i < gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); i++)
attributeNames.push(gl.getActiveAttrib(program, i).name);
// Print out their attribute location values
attributeNames
.reduce((c, attribName) => [
...c,
`${ gl.getAttribLocation(program, attribName) }: ${attribName}`,
], [])
.sort()
.forEach(v => console.log(v));