58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
/**
|
|
* Initialize Vertex Attributes
|
|
* @param {any} gl the WebGL content
|
|
* @param {any} programInfo WebGL program information
|
|
* @param {any} buffers the buffers to init
|
|
*/
|
|
export function initVertexAttribs(gl: any, programInfo: any, buffers: any) {
|
|
{
|
|
const numComponents = 3;
|
|
const type = gl.FLOAT;
|
|
const normalize = false;
|
|
const stride = 0;
|
|
const offset = 0;
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.positions);
|
|
gl.vertexAttribPointer(
|
|
programInfo.attribLocations.vertexPosition,
|
|
numComponents,
|
|
type,
|
|
normalize,
|
|
stride,
|
|
offset);
|
|
gl.enableVertexAttribArray(
|
|
programInfo.attribLocations.vertexPosition);
|
|
}
|
|
{
|
|
const numComponents = 3;
|
|
const type = gl.FLOAT;
|
|
const normalize = false;
|
|
const stride = 0;
|
|
const offset = 0;
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.normals);
|
|
gl.vertexAttribPointer(
|
|
programInfo.attribLocations.vertexNormal,
|
|
numComponents,
|
|
type,
|
|
normalize,
|
|
stride,
|
|
offset);
|
|
gl.enableVertexAttribArray(
|
|
programInfo.attribLocations.vertexNormal);
|
|
}
|
|
{
|
|
const numComponents = 2;
|
|
const type = gl.FLOAT;
|
|
const normalize = false;
|
|
const stride = 0;
|
|
const offset = 0;
|
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffers.uvs);
|
|
gl.vertexAttribPointer(programInfo.attribLocations.textureCoord,
|
|
numComponents,
|
|
type,
|
|
normalize,
|
|
stride,
|
|
offset);
|
|
gl.enableVertexAttribArray(programInfo.attribLocations.textureCoord);
|
|
}
|
|
}
|