glBufferData分配的内存何时释放? [英] When is the memory allocated by glBufferData freed?

查看:281
本文介绍了glBufferData分配的内存何时释放?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我为统一缓冲区分配内存,如下所示:

Let's say I allocate memory for a uniform buffer, like so:

GLuint length(0x1000);
GLuint myBuffer;
glGenBuffers(1, &myBuffer);
glBindBuffer(GL_UNIFORM_BUFFER, myBuffer);
glBufferData(GL_UNIFORM_BUFFER, length, NULL, GL_STATIC_DRAW);

使用完缓冲区后,我想确保该内存可再次用于其他缓冲区.调用glDeleteBuffers(1,&myBuffer)是否足以实现这一目标?因为我的直觉告诉我应该为此呼叫glBufferData (例如OpenGL 4中的glInvalidateBufferData​),但在glBufferData的文档中完全没有提及任何类型的内容(

When I am done using the buffer, I would like to make sure that the memory is available again for other buffers. Is it sufficient to call glDeleteBuffers(1,&myBuffer) to achieve that? Because my gut feeling tells me there should be a call symmetrical to glBufferData for that (like glInvalidateBufferData​ in OpenGL 4), but nothing of the kind is mentioned in the documentation for glBufferData at all (http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml)

推荐答案

不是嗡嗡声,但是诸如顶点数组对象之类的容器对象使该讨论变得更加复杂.

Not to be a buzz kill, but container objects such as Vertex Array Objects significantly complicate this discussion.

通常,当您删除缓冲区对象时,会发生两个关键事件,从而可以回收内存:

Normally, when you delete a buffer object two key things happen that allow the memory to be reclaimed:

  1. 其名称(GLuint ID)被释放以立即重用
  2. 该对象已从 当前活动 上下文中解除绑定
  1. Its name (GLuint ID) is freed up for reuse immediately
  2. The object is unbound from the currently active context

有一个需要注意的隐藏警告:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆