问题
In the stock OpenGL ES app you get (when you create a new "OpenGL game" in XCode), in the setupGL
function, there is:
glEnable(GL_DEPTH_TEST);
//glGenVertexArraysOES( 1, &_vertexArray ) ; // va's are not being used!
//glBindVertexArrayOES( _vertexArray ) ; // we comment these out
// to no ill effect -- are these calls extraneous?
glGenBuffers( 1, &_vertexBuffer ) ;
glBindBuffer( GL_ARRAY_BUFFER, _vertexBuffer ) ;
glBufferData( GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW ) ;
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
//glBindVertexArrayOES(0);
However, it doesn't seem that vertex arrays are being used, (far as I know, vertex arrays stay in client memory while vertex buffers are parked on OpenGL server memory).
If you comment out the glBindVertexArrayOES
commands, the code seems to work exactly the same.
Are the glBindVertexArrayOES
calls extraneous in this xCode sample?
回答1:
You're confusing vertex arrays with Vertex Array Objects (the terminology is confusing).
This statement: "(far as I know, vertex arrays stay in client memory while vertex buffers are parked on OpenGL server memory)" applies to client side vertex arrays. These are used instead of "Vertex Buffer Objects" when you want to keep your vertex buffers local, and thus supply a raw memory pointer to glDrawElements/gl*Pointer.
Vertex Array Objects on the other hand are an OpenGL construct that contains all of the pointers necessary to draw an object. Any OpenGL function with "VertexArray" in the name applies to "Vertex Array Objects", and not client side vertex arrays.
You can read more about VAO here:
http://www.opengl.org/wiki/Vertex_Specification#Vertex_Array_Object
来源:https://stackoverflow.com/questions/12428473/in-the-stock-opengl-es-app-on-ios-5-1-are-they-really-using-the-vertex-arrays-t