(
gl: WebGL2RenderingContext, vertexShaderSource: string,
fragmentShaderSource: string, vertices: Float32Array,
texCoords: Float32Array)
| 365 | } |
| 366 | |
| 367 | function createProgramObjects( |
| 368 | gl: WebGL2RenderingContext, vertexShaderSource: string, |
| 369 | fragmentShaderSource: string, vertices: Float32Array, |
| 370 | texCoords: Float32Array): ProgramObjects { |
| 371 | const vertShader = gl.createShader(gl.VERTEX_SHADER); |
| 372 | gl.shaderSource(vertShader, vertexShaderSource); |
| 373 | gl.compileShader(vertShader); |
| 374 | |
| 375 | const fragShader = gl.createShader(gl.FRAGMENT_SHADER); |
| 376 | gl.shaderSource(fragShader, fragmentShaderSource); |
| 377 | gl.compileShader(fragShader); |
| 378 | |
| 379 | const program = gl.createProgram(); |
| 380 | gl.attachShader(program, vertShader); |
| 381 | gl.attachShader(program, fragShader); |
| 382 | gl.linkProgram(program); |
| 383 | gl.validateProgram(program); |
| 384 | |
| 385 | // Use a vertex array objects to record geometry info |
| 386 | const vao = gl.createVertexArray(); |
| 387 | gl.bindVertexArray(vao); |
| 388 | |
| 389 | // Set up geometry |
| 390 | webgl_util.callAndCheck(gl, () => { |
| 391 | const positionAttrib = gl.getAttribLocation(program, 'position'); |
| 392 | const vertsCoordsBuffer = gl.createBuffer(); |
| 393 | gl.bindBuffer(gl.ARRAY_BUFFER, vertsCoordsBuffer); |
| 394 | gl.enableVertexAttribArray(positionAttrib); |
| 395 | gl.bufferData(gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW); |
| 396 | gl.vertexAttribPointer(positionAttrib, 2, gl.FLOAT, false, 0, 0); |
| 397 | gl.bindBuffer(gl.ARRAY_BUFFER, null); |
| 398 | }); |
| 399 | |
| 400 | webgl_util.callAndCheck(gl, () => { |
| 401 | const texCoordsAttrib = gl.getAttribLocation(program, 'texCoords'); |
| 402 | const texCoordsBuffer = gl.createBuffer(); |
| 403 | gl.bindBuffer(gl.ARRAY_BUFFER, texCoordsBuffer); |
| 404 | gl.bufferData(gl.ARRAY_BUFFER, texCoords, gl.STATIC_DRAW); |
| 405 | gl.enableVertexAttribArray(texCoordsAttrib); |
| 406 | gl.vertexAttribPointer(texCoordsAttrib, 2, gl.FLOAT, false, 0, 0); |
| 407 | gl.bindBuffer(gl.ARRAY_BUFFER, null); |
| 408 | }); |
| 409 | |
| 410 | const uniformLocations = new Map<string, WebGLUniformLocation>(); |
| 411 | webgl_util.callAndCheck(gl, () => { |
| 412 | const inputTextureLoc = gl.getUniformLocation(program, 'inputTexture'); |
| 413 | uniformLocations.set('inputTexture', inputTextureLoc); |
| 414 | }); |
| 415 | |
| 416 | // Unbind |
| 417 | gl.bindVertexArray(null); |
| 418 | return { |
| 419 | program, |
| 420 | vao, |
| 421 | vertices, |
| 422 | uniformLocations, |
| 423 | }; |
| 424 | } |
no test coverage detected
searching dependent graphs…