How to use and what are the arguments for this api. And any additional notes.

satya - Tue Aug 14 2012 13:03:58 GMT-0400 (Eastern Daylight Time)

Link to ES 2.0 site for the API

Link to ES 2.0 site for the API

satya - Tue Aug 14 2012 13:04:54 GMT-0400 (Eastern Daylight Time)

quickly


void glVertexAttribPointer(   GLuint index,
    GLint size,
    GLenum type,
    GLboolean normalized,
    GLsizei stride,
    const GLvoid * pointer);

satya - Tue Aug 14 2012 13:07:12 GMT-0400 (Eastern Daylight Time)

index argument is a misnomer

This is not the same as indexing into set of vertices to reuse vertices. This points to the binding location to the corresponding variable in the vertex shader program.

satya - Tue Aug 14 2012 13:07:55 GMT-0400 (Eastern Daylight Time)

Here is an example of the call


private void transferTexturePoints(int texturePositionHandle)
    {
        GLES20.glVertexAttribPointer(texturePositionHandle, 2, GLES20.GL_FLOAT, false,
                0, mFVertexBuffer);
        checkGlError("glVertexAttribPointer texture array");
        //mFVertexBuffer.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
        GLES20.glEnableVertexAttribArray(texturePositionHandle);
        checkGlError("glEnableVertexAttribArray textures");
    }

satya - Tue Aug 14 2012 13:11:07 GMT-0400 (Eastern Daylight Time)

Annotated call example


GLES20.glVertexAttribPointer(
  texturePositionHandle, //address of the var in the shader
  2, //how many floats are you transfering: 1,2,3, or 4
  GLES20.GL_FLOAT, //each transfered element type
  false, //not normalized
  0, //stride, or offset
  mFVertexBuffer); //client buffer to transfer from

satya - Tue Aug 14 2012 13:12:19 GMT-0400 (Eastern Daylight Time)

What is stride?

stride tells you how the vertex data is spaced in the buffer. For example you can say that between two vertex position coordinates there are 10 bytes that don't count. This allows you to pack additional data into the same buffer should that be needed.

satya - Tue Aug 14 2012 13:14:05 GMT-0400 (Eastern Daylight Time)

Show me how you declared the texturePositionHandler?


uniform mat4 uMVPMatrix;
attribute vec4 aPosition;


//Bind this to the texturePositionHandle
attribute vec2 aTextureCoordinate;

out vec2 v_TextureCoordinate;
void main() 
{
   gl_Position = uMVPMatrix * aPosition;
   v_TextureCoordinate = aTextureCoordinate;
}

satya - Tue Aug 14 2012 13:15:44 GMT-0400 (Eastern Daylight Time)

This shows that you use the same call glVertexAttribPointer

to transfer any number of arbitrary vertex related attributes. Some of the vertex attributes are a) color b) position c) normals (in which direction is the surface facing)

satya - Tue Aug 14 2012 13:22:19 GMT-0400 (Eastern Daylight Time)

Size argument would have been 3 if I were transferring vertex data

Size argument would have been 3 if I were transferring vertex data

satya - Sat Sep 08 2012 11:34:23 GMT-0400 (Eastern Daylight Time)

glEnableVertexAttribArray(attrib-variable-inthe-shader)

glEnableVertexAttribArray(attrib-variable-inthe-shader)

This particular "attribute" variable in the shader program is enabled to use the specified attribute when glDrawArrays or glDrawElements is called.

By default these are disabled.

satya - Sat Sep 08 2012 11:35:14 GMT-0400 (Eastern Daylight Time)

So the sequence may look like this


private void transferVertexPoints(int vertexPositionHandle)
    {
        GLES20.glVertexAttribPointer(
              vertexPositionHandle, //bound address in the vertex shader 
              3, //how may floats for this attribute: x, y, z
              GLES20.GL_FLOAT, //what is type of each attribute? 
              false, // not normalized
                0, //stride
                mFVertexBuffer); //local client pointer to data
        //Check to see if this caused any errors
        checkGlError("glVertexAttribPointer maPosition");
        
        GLES20.glEnableVertexAttribArray(vertexPositionHandle);
        checkGlError("glEnableVertexAttribArray maPositionHandle");
    }

satya - Sat Sep 08 2012 12:02:33 GMT-0400 (Eastern Daylight Time)

So show me glDrawArray


GLES20.glDrawArrays(GLES20.GL_TRIANGLES, //what primitives to use
              0, //at what point to start
              vertexCount); //Starting there how many points to use