Robert Robert - 3 months ago 48
Swift Question

What does glGenVertexArraysOES() do and where is the documentation?

I'm starting with the Swift OpenGL ES "Game" project template in XCode 7 and having a very frustrating time. There seems to be lots of information about using OpenGL ES with Objective C, and some information about using regular OpenGL with Swift, but very little about using OpenGL ES with Swift on iOS.

In the template's GameViewController.swift, in the setupGL() function, there's a call to

glGenVertexArraysOES(1, &vertexArray)
. The documentation is totally unhelpful. Googling finds lots of people using glGenVertexArraysOES(), but nothing documenting what it is or how to use it.

What does this function do, and where is it documented?

Answer

glGenVertexArraysOESgenerates vertex arrays. Vertex arrays can be used to describe how your geometry data (vertices, indices) is stored in a vertex buffer object (which attribute index corresponds to which attribute like position, texture coordinate etc.). There is documentation on opengl.org (the function does the same as the *OES version):

glGenVertexArrays — generate vertex array object names

glGenVertexArrays returns n vertex array object names in arrays. There is no guarantee that the names form a contiguous set of integers; however, it is guaranteed that none of the returned names was in use immediately before the call to glGenVertexArrays.

Vertex array object names returned by a call to glGenVertexArrays are not returned by subsequent calls, unless they are first deleted with glDeleteVertexArrays.

The names returned in arrays are marked as used, for the purposes of glGenVertexArrays only, but they acquire state and type only when they are first bound