简体   繁体   English

我可以在调用glDrawArrays后删除OpenGL顶点数组吗?

[英]Can I delete OpenGL vertex arrays after calling glDrawArrays?

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? glDrawArrays立即将顶点数组复制到服务器吗? Hence is it safe to delete the vertex arrays after calling glDrawArrays ? 因此在调用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? 否则,如何确定何时删除顶点数组是否安全?

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. 另外,正如dirkgently指出的,你需要使用delete[] vp来删除一个数组。

Yes, you can delete the vertex array after calling glDrawArrays. 是的,您可以在调用glDrawArrays后删除顶点数组。 But opengl won't store vertex data in it's memory. 但是opengl不会将顶点数据存储在它的内存中。 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. 所以下次如果你想绘制相同的顶点,那么你必须再次为glDrawArrays提供顶点数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM