3

I am generating the vertex arrays on the fly on each render and I want to delete the arrays afterwards. Does glDrawArrays immediately copy the vertex arrays to the server? Hence is it safe to delete the vertex arrays after calling glDrawArrays?

float * vp = GetVertices(); // Regenerated on each render
glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), vp);
glDrawArrays(GL_TRIANGLES, 0, nVertices);
delete[] vp; // Can I do this?

Otherwise, how can I determine when it is safe to delete the vertex arrays?

Ozgur Ozcitak
  • 10,409
  • 8
  • 46
  • 56
  • 1
    An array deletion requires the syntax: `delete [] vp;` where `vp` is a pointer to the first element of an array. – dirkgently Feb 06 '10 at 11:09
  • 2
    On an unrelated note - using vertex arrays requires shunting the data up to the graphics card memory each time. For a more efficient approach take a look at Vertex Buffer Objects http://www.songho.ca/opengl/gl_vbo.html – zebrabox Feb 06 '10 at 12:40

2 Answers2

8

Yes, it is copied immediately, so once you've done the call you can do whatever you like with the array.

Also, as dirkgently pointed out, you need to use delete[] vp to delete an array.

Peter Alexander
  • 53,344
  • 14
  • 119
  • 168
2

Yes, you can delete the vertex array after calling glDrawArrays. But opengl won't store vertex data in it's memory. It will just use the vertex array and draws on the frame buffer. So next time if you want draw the same vertex, then you have to provide the vertex array again to glDrawArrays.

Garrett Hyde
  • 5,409
  • 8
  • 49
  • 55
manojyerra
  • 21
  • 1