freakish freakish - 2 months ago 14
C++ Question

OpenGL: Do I still need an array of vertices after buffering to VBO?

Let's say that I have an array of vertices and a VBO pointer:

std::vector<Vertex> vertices;
GLuint vbo;
glBindBuffer(GL_ARRAY_BUFFER, vbo);

Now I buffer the data:


If I understand this correctly I still need to keep vertices array due to
. However if I change it to
then all of the data will be copied to GPU's memory so I can free memory used by
. Is that correct? If that's the case why do we need
? Is that useful because of the GPU's memory limit? Plus how does
really work?


All of this is explained in the glBufferData() man pages.

You don't need to keep an extra copy in your program's memory. The whole purpose of glBufferData() is to copy data from your program to an OpenGL buffer, once the copy is complete, you can do whatever you want with your program memory.

If data is not NULL, the data store is initialized with data from this pointer.

Do not use GL_STATIC_COPY, that is incorrect. The documentation reads:


The data store contents are modified by reading data from the GL, and used as the source for GL drawing and image specification commands.

So GL_STATIC_COPY is only for internal copies between different OpenGL buffers, not for copies from your application to OpenGL. Use DRAW.