glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * numVertices
* 3, NULL, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(GLfloat) *
numVertices * 3, VertexArray);
How is 1 different from 2?
It is said that 2 shows better rendering performance than 1. why is so?
#1 allocates the buffer “and” provides contents for it (since the data pointer is not NULL).
#2 allocates the buffer in the first statement (but doesn’t provide contents as the pointer is NULL), and then provides the contents for it in the separate, second statement.
The advantage to the second approach for a buffer where you need to update it again and again is that you only call the glBufferData call to allocate the buffer once, then to update the buffer use glSubBufferData. This allows you to not consume the overhead of needlessly reallocating the buffer every time you need to upload new contents for it. You just provide the new contents for the “existing” buffer. If you repeatedly call glBufferData, you are repeatedly reallocating the buffer, which is a waste.
Also, there are other ways besides these two to upload data to a buffer object, such as glMapBuffer and glMapBufferRange. And these may net you even higher upload performance.