Setting up the vertex buffer
The vertex buffer offers another technique of improving performance. Instead of using the gl.Vertex
function for each vertex, you can load vertices into the memory in a batch. This is considerably faster because you only use one function call instead of hundreds or thousands of calls.
Getting ready
Vertex buffers are represented by vertex buffer objects or VBO in short. VBO was introduced as an extension of OpenGL and you can check its presence in the extension list with the extension name GL_ARB_vertex_buffer_object
. Fortunately, LuaGL contains support for the GLEW library, which manages extension initialization.
The vertex buffer object must be initialized with the gl.GenBuffers
function. This function will only reserve the buffer object identifiers and returns a Lua table with the buffer object identifiers. Further buffer object specification must be done with the gl.BufferData
function.
This recipe assumes that you already have a valid buffer object generated...