Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
getAttribLocation
Collapse the table of content
Expand the table of content

getAttribLocation method

Returns an index to the location in a program of a named attribute variable.

IE11

 

Syntax

var index = WebGLRenderingContext.getAttribLocation(program, name);

Parameters

program [in]

Type: WebGLProgram

The program object.

name [in]

Type: String

The name of the attribute variable.

Return value

Type: Number

The location of the attribute variable name if found. Returns a -1 if not.

Remarks

If name is a matrix variable, index points to the first column of the matrix.

Examples

This example gets the location of an attribute passed into a shader using the getAttribLocation method. For more info on this example, see Get started with WebGL.



  // Look up where the vertex data needs to go.
this.texCoordLocation2 = gl.getAttribLocation(this.lineprogram, "a_texCoord");

  // Provide texture coordinates for the rectangle.
this.texCoordBuffer2 = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, this.texCoordBuffer2);
      
// Create a buffer and set it use the array set up above.
// Set it to be modified once, use many.
// createRedGrid sets up the vector array itself.        
gl.bufferData(gl.ARRAY_BUFFER, createRedGrid(), gl.STATIC_DRAW); // Fill buffer data

// Turns on the vertex attributes in the GPU program. 
gl.enableVertexAttribArray(this.texCoordLocation2);

// Set up the data format for the vertex array - set to points (x/y). 
// Use floats.
gl.vertexAttribPointer(this.texCoordLocation2, 2, gl.FLOAT, false, 0, 0);
}


See also

WebGLRenderingContext

 

 

Show:
© 2015 Microsoft