Game Development Reference
In-Depth Information
if (m_MeshHasNormals)
{
// Set up Vertex Texture Data stream to shader
m_VertexBuffer.position(m_MeshVerticesDataNormalOffset);
GLES20.glVertexAttribPointer(NormalHandle, 3, GLES20.GL_FLOAT, false,
m_MeshVerticesDataStrideBytes, m_VertexBuffer);
GLES20.glEnableVertexAttribArray(NormalHandle);
}
}
The DrawMesh() function in Listing 4-35 first calls the SetUpMeshArrays() function to prepare the
vertex attributes for sending to the shader.
Listing 4-35. Main Drawing Function DrawMesh
void DrawMesh(int PosHandle, int TexHandle, int NormalHandle)
{
SetUpMeshArrays(PosHandle, TexHandle, NormalHandle);
GLES20.glDrawElements(GLES20.GL_TRIANGLES, m_DrawListBuffer.capacity(),
GLES20.GL_UNSIGNED_SHORT, m_DrawListBuffer);
// Disable vertex array
GLES20.glDisableVertexAttribArray(PosHandle);
CheckGLError("glDisableVertexAttribArray ERROR - PosHandle");
if (m_MeshHasUV)
{
GLES20.glDisableVertexAttribArray(TexHandle);
CheckGLError("glDisableVertexAttribArray ERROR - TexHandle");
}
if (m_MeshHasNormals)
{
GLES20.glDisableVertexAttribArray(NormalHandle);
CheckGLError("glDisableVertexAttribArray ERROR - NormalHandle");
}
}
Next, the glDrawElements() function is called with the following parameters:
Primitive drawing type, which is GL_TRIANGLES
1.
2.
The number of vertex indices to be processed
The type of the vertex index, which is GL_UNSIGNED_SHORT
3.
4. The buffer that contains the vertex indices to process, which is
m_DrawListBuffer
Finally, each vertex attribute that was activated is now disabled with the glDisableVertexAttribArray()
function. The CheckGLError() function is also called to check to see if any OpenGL errors have
occurred.
 
Search WWH ::




Custom Search