-
Notifications
You must be signed in to change notification settings - Fork 10
/
program.js
41 lines (34 loc) · 946 Bytes
/
program.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
import { initShader } from '../../libs/shader.js'
const vertexShader = `
attribute vec4 pos;
attribute vec2 texCoord;
uniform mat4 modelViewMat;
uniform mat4 projectionMat;
varying highp vec2 vTexCoord;
void main() {
gl_Position = projectionMat * modelViewMat * pos;
vTexCoord = texCoord;
}
`
const fragmentShader = `
uniform sampler2D sampler;
varying highp vec2 vTexCoord;
void main() {
gl_FragColor = texture2D(sampler, vTexCoord);
}
`
export const initProgramInfo = gl => {
const program = initShader(gl, vertexShader, fragmentShader)
return {
program,
attribLocations: {
pos: gl.getAttribLocation(program, 'pos'),
texCoord: gl.getAttribLocation(program, 'texCoord')
},
uniformLocations: {
sampler: gl.getUniformLocation(program, 'sampler'),
projectionMat: gl.getUniformLocation(program, 'projectionMat'),
modelViewMat: gl.getUniformLocation(program, 'modelViewMat')
}
}
}