Using the Buffer as Input on Android

The vertexAttribPointer tells OpenGL how to load data from the array buffer into the attribute.

263     protected void bindBuffer(int vertexBuffer, int program, String attribute, int size, int type, int stride, int offset)
264     {
265         int            attributeLocation;
266 
267         attributeLocation = GLES20.glGetAttribLocation(program, attribute);
268 
269         // Binding an object makes it the target of subsequent manipulations.
270         GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, vertexBuffer);
271 
272         GLES20.glVertexAttribPointer(attributeLocation, size, type, false, stride, offset);
273 
274         GLES20.glEnableVertexAttribArray(attributeLocation);
275     }

Notes

We have come a long way by echoing the WebGL code in our OpenGL ES implimentation, but now we need to take a detour and talk about things that are different.

First, lookup the index of the attribute by name with glGetAttribLocation.

Enable the attribute for input by passing that index to glEnableVertexAttribArray.

We are working with multiple buffers so we bind the desired buffer.

glVertexAttribPointer describes exactly how to map the currently bound buffer to the attibute.