Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Blakeasd

macrumors 6502a
Original poster
Dec 29, 2009
643
0
Hello,

In the default Xcode 4.x OpenGL ES iOS template, why doesn't Apple use indices when drawing the two cubes? How does OpenGL know what order to draw the coordinates. Also, Apple uses normal values in with the vertex data -- how does OpenGL know what is a normal coordinate vs a vertex??

Thanks!
 
Hello,

In the default Xcode 4.x OpenGL ES iOS template, why doesn't Apple use indices when drawing the two cubes? How does OpenGL know what order to draw the coordinates. Also, Apple uses normal values in with the vertex data -- how does OpenGL know what is a normal coordinate vs a vertex??

Thanks!

They don't use indices because they always draw both cubes. Arrays of indices let you hop around in your index data, "connecting the dots" in different ways. That isn't needed in this case.

The drawing is done with glDrawArrays, which draws all the triangle data that was set up.

The vertex data in normals are interleaved because that makes rendering much faster. That gives the GPU locality of reference when it loads the data to draw a given triangle. If you had separate arrays of vertexes and normals the GPU would have to load the vertexes for a triangle from on area of memory, and the normal from another, which means it would have to load from main video memory to cache memory much more frequently.

It knows where the vertex data is vs where the normal data is because the program tells it in the setupGL method.

Specifically the paired calls to glEnableVertexAttribArray and glVertexAttribPointer tell it first where the data for the vertexes is located at each entry in the array, and then where the normals are located. Note the "BUFFER_OFFSET" macros at the end of each call to glVertexAttribPointer. Those specify offset into each entry in the vertex array where the vertex data and normal data are located.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.