Reputation: 9207
I'm just beginning to learn OpenGL on Android and I just noticed that some of gl calls, such as glTexCoordPointer(...) or glVertexPointer(...), accept data only in Buffer objects, others, such as glDrawTexvOES(), glTexParameteriv(), accept a float[] too.
I'm curious why is that so? :)
Upvotes: 2
Views: 104
Reputation: 56438
The basic difference is that the input to glTexCoordPointer and glVertexPointer functions are not used right away, they are only used once a glDraw method is called, e.g. glDrawArrays, glDrawElements.
Since the arrays are not used right away, you need to keep the pointer to the array sent to these functions around long enough for the draw routines to access it. The data has to be on the native heap, otherwise the garbage collector could move the underlying native pointer even if it the data is not deleted. In order to get a pointer on the native heap, you need to wrap the data inside the Buffer objects.
The glTexParameteriv-like functions use the values in the array you pass in right away, so there are no worries about pointers moving out from under the called function, and no need to have them on the native heap.
If you use glTexCoordPointer and friends from native code, you have to keep the pointer you send it around until after you call the glDraw function too. From native code you have an advantage that the pointer does not need to be wrapped in an object, but you have the disadvantage that you have to manage any heap allocation manually.
Upvotes: 2